Skip to content

Commit

Permalink
Fix linux BLE deadload (#26418)
Browse files Browse the repository at this point in the history
Make is so ChipDeviceScanner::StartScan is only called while in the Matter Context
  • Loading branch information
tehampson authored and pull[bot] committed Jun 24, 2023
1 parent aa720c5 commit a32f22b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/controller/python/chip/ble/LinuxImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ extern "C" void * pychip_ble_start_scanning(PyObject * context, void * adapter,
return nullptr;
}

if (scanner->StartScan(chip::System::Clock::Milliseconds32(timeoutMs)) != CHIP_NO_ERROR)
CHIP_ERROR err = CHIP_NO_ERROR;
chip::DeviceLayer::PlatformMgr().LockChipStack();
err = scanner->StartScan(chip::System::Clock::Milliseconds32(timeoutMs));
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
if (err != CHIP_NO_ERROR)
{
return nullptr;
}
Expand Down
3 changes: 1 addition & 2 deletions src/platform/Linux/bluez/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ std::unique_ptr<ChipDeviceScanner> ChipDeviceScanner::Create(BluezAdapter1 * ada

CHIP_ERROR ChipDeviceScanner::StartScan(System::Clock::Timeout timeout)
{
assertChipStackLockedByCurrentThread();
ReturnErrorCodeIf(mIsScanning, CHIP_ERROR_INCORRECT_STATE);

mIsScanning = true; // optimistic, to allow all callbacks to check this
Expand All @@ -157,9 +158,7 @@ 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();

if (err != CHIP_NO_ERROR)
{
Expand Down
3 changes: 3 additions & 0 deletions src/platform/Linux/bluez/ChipDeviceScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class ChipDeviceScanner
~ChipDeviceScanner();

/// Initiate a scan for devices, with the given timeout
///
/// This method must be called while in the Matter context (from the Matter event
/// loop, or while holding the Matter stack lock).
CHIP_ERROR StartScan(System::Clock::Timeout timeout);

/// Stop any currently running scan
Expand Down

0 comments on commit a32f22b

Please sign in to comment.