-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
…is started (#26338) * chip-repl hits the Code is unsafe/racy assert when BLE commissioning is started * Add lock/unlock to CancelTimer * Fix a few other issue * Restyle * Small fix * Last few fixes
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,8 +78,16 @@ ChipDeviceScanner::~ChipDeviceScanner() | |
{ | ||
StopScan(); | ||
|
||
// In case the timeout timer is still active | ||
chip::DeviceLayer::SystemLayer().CancelTimer(TimerExpiredCallback, this); | ||
// mTimerExpired should only be set to true in the TimerExpiredCallback, which means we are in that callback | ||
// right now so there is no need to cancel the timer. Doing so would result in deadlock trying to aquire the | ||
// chip stack lock which we already currently have. | ||
if (!mTimerExpired) | ||
{ | ||
// In case the timeout timer is still active | ||
DeviceLayer::PlatformMgr().LockChipStack(); | ||
chip::DeviceLayer::SystemLayer().CancelTimer(TimerExpiredCallback, this); | ||
DeviceLayer::PlatformMgr().UnlockChipStack(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
g_object_unref(mManager); | ||
g_object_unref(mCancellable); | ||
|
@@ -136,21 +144,25 @@ CHIP_ERROR ChipDeviceScanner::StartScan(System::Clock::Timeout timeout) | |
return CHIP_ERROR_INTERNAL; | ||
} | ||
|
||
DeviceLayer::PlatformMgr().LockChipStack(); | ||
CHIP_ERROR err = chip::DeviceLayer::SystemLayer().StartTimer(timeout, TimerExpiredCallback, static_cast<void *>(this)); | ||
DeviceLayer::PlatformMgr().UnlockChipStack(); | ||
This comment has been minimized.
Sorry, something went wrong.
tianfeng-yang
Contributor
|
||
|
||
if (err != CHIP_NO_ERROR) | ||
{ | ||
ChipLogError(Ble, "Failed to schedule scan timeout."); | ||
StopScan(); | ||
return err; | ||
} | ||
mTimerExpired = false; | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void ChipDeviceScanner::TimerExpiredCallback(chip::System::Layer * layer, void * appState) | ||
{ | ||
ChipDeviceScanner * chipDeviceScanner = static_cast<ChipDeviceScanner *>(appState); | ||
chipDeviceScanner->MarkTimerExpired(); | ||
chipDeviceScanner->mDelegate->OnScanError(CHIP_ERROR_TIMEOUT); | ||
chipDeviceScanner->StopScan(); | ||
} | ||
|
@@ -180,6 +192,11 @@ CHIP_ERROR ChipDeviceScanner::StopScan() | |
return CHIP_ERROR_INTERNAL; | ||
} | ||
|
||
ChipDeviceScannerDelegate * delegate = this->mDelegate; | ||
// callback is explicitly allowed to delete the scanner (hence no more | ||
// references to 'self' here) | ||
delegate->OnScanComplete(); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
|
@@ -192,12 +209,7 @@ CHIP_ERROR ChipDeviceScanner::MainLoopStopScan(ChipDeviceScanner * self) | |
ChipLogError(Ble, "Failed to stop discovery %s", error->message); | ||
g_error_free(error); | ||
} | ||
ChipDeviceScannerDelegate * delegate = self->mDelegate; | ||
self->mIsScanning = false; | ||
|
||
// callback is explicitly allowed to delete the scanner (hence no more | ||
// references to 'self' here) | ||
delegate->OnScanComplete(); | ||
self->mIsScanning = false; | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
1 comment
on commit da37e59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tehampson This patch made my application deadlock, I have added comments in the code
A deadlock can occur here.