Skip to content

Commit

Permalink
Use assertChipStackLockedByCurrentThread when accessing statics in sr…
Browse files Browse the repository at this point in the history
…c/system/SystemStats.cpp (#25485)

* Use assertChipStackLockedByCurrentThread when accessing statics in src/system/SystemStats.cpp

* Update src/platform/Darwin/BleConnectionDelegateImpl.mm such that it does not creates a PacketBufferHandle from the ble work queue but from the chip work queue
  • Loading branch information
vivien-apple authored and pull[bot] committed Aug 30, 2023
1 parent b48b747 commit 1313176
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/lib/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ chip_test_suite("tests") {
public_deps = [
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/platform",
"${nlunit_test_root}:nlunit-test",
]
}
Expand Down
29 changes: 12 additions & 17 deletions src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,19 @@ - (void)peripheral:(CBPeripheral *)peripheral
chip::Ble::ChipBleUUID charId;
[BleConnection fillServiceWithCharacteristicUuids:characteristic svcId:&svcId charId:&charId];

// build a inet buffer from the rxEv and send to blelayer.
__block chip::System::PacketBufferHandle msgBuf
= chip::System::PacketBufferHandle::NewWithData(characteristic.value.bytes, characteristic.value.length);

if (!msgBuf.IsNull()) {
dispatch_async(_chipWorkQueue, ^{
if (!_mBleLayer->HandleIndicationReceived((__bridge void *) peripheral, &svcId, &charId, std::move(msgBuf))) {
// since this error comes from device manager core
// we assume it would do the right thing, like closing the connection
ChipLogError(Ble, "Failed at handling incoming BLE data");
}
});
} else {
ChipLogError(Ble, "Failed at allocating buffer for incoming BLE data");
dispatch_async(_chipWorkQueue, ^{
dispatch_async(_chipWorkQueue, ^{
// build a inet buffer from the rxEv and send to blelayer.
auto msgBuf = chip::System::PacketBufferHandle::NewWithData(characteristic.value.bytes, characteristic.value.length);

if (msgBuf.IsNull()) {
ChipLogError(Ble, "Failed at allocating buffer for incoming BLE data");
_mBleLayer->HandleConnectionError((__bridge void *) peripheral, CHIP_ERROR_NO_MEMORY);
});
}
} else if (!_mBleLayer->HandleIndicationReceived((__bridge void *) peripheral, &svcId, &charId, std::move(msgBuf))) {
// since this error comes from device manager core
// we assume it would do the right thing, like closing the connection
ChipLogError(Ble, "Failed at handling incoming BLE data");
}
});
} else {
ChipLogError(
Ble, "BLE:Error receiving indication of Characteristics on the device: [%s]", [error.localizedDescription UTF8String]);
Expand Down
1 change: 1 addition & 0 deletions src/setup_payload/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ chip_test_suite("tests") {

public_deps = [
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/platform",
"${chip_root}/src/setup_payload",
"${nlunit_test_root}:nlunit-test",
]
Expand Down
9 changes: 9 additions & 0 deletions src/system/SystemStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <system/SystemStats.h>

#include <lib/support/SafeInt.h>
#include <platform/LockTracker.h>

#include <string.h>

Expand Down Expand Up @@ -59,21 +60,29 @@ count_t sHighWatermarks[kNumEntries];

const Label * GetStrings()
{
assertChipStackLockedByCurrentThread();

return sStatsStrings;
}

count_t * GetResourcesInUse()
{
assertChipStackLockedByCurrentThread();

return sResourcesInUse;
}

count_t * GetHighWatermarks()
{
assertChipStackLockedByCurrentThread();

return sHighWatermarks;
}

void UpdateSnapshot(Snapshot & aSnapshot)
{
assertChipStackLockedByCurrentThread();

memcpy(&aSnapshot.mResourcesInUse, &sResourcesInUse, sizeof(aSnapshot.mResourcesInUse));
memcpy(&aSnapshot.mHighWatermarks, &sHighWatermarks, sizeof(aSnapshot.mHighWatermarks));

Expand Down

0 comments on commit 1313176

Please sign in to comment.