Skip to content

Commit

Permalink
Darwin: Snapshot nodeIDToDeviceMap correctly (#35476)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling-apple authored and pull[bot] committed Sep 17, 2024
1 parent 23a607b commit 1581874
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 5 additions & 11 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,10 @@ - (void)suspend
@synchronized(self) {
_suspended = YES;

NSMutableArray * devicesToSuspend = [NSMutableArray array];
NSArray * devicesToSuspend;
{
std::lock_guard lock(*self.deviceMapLock);
NSEnumerator * devices = [self.nodeIDToDeviceMap objectEnumerator];
for (MTRDevice * device in devices) {
[devicesToSuspend addObject:device];
}
devicesToSuspend = [self.nodeIDToDeviceMap objectEnumerator].allObjects;
}

for (MTRDevice * device in devicesToSuspend) {
Expand All @@ -392,13 +389,10 @@ - (void)resume
@synchronized(self) {
_suspended = NO;

NSMutableArray * devicesToResume = [NSMutableArray array];
NSArray * devicesToResume;
{
std::lock_guard lock(*self.deviceMapLock);
NSEnumerator * devices = [self.nodeIDToDeviceMap objectEnumerator];
for (MTRDevice * device in devices) {
[devicesToResume addObject:device];
}
devicesToResume = [self.nodeIDToDeviceMap objectEnumerator].allObjects;
}

for (MTRDevice * device in devicesToResume) {
Expand Down Expand Up @@ -490,7 +484,7 @@ - (void)cleanupAfterStartup
// devices before we start invalidating.
MTR_LOG("%s: %@", __PRETTY_FUNCTION__, self);
os_unfair_lock_lock(self.deviceMapLock);
NSEnumerator * devices = [_nodeIDToDeviceMap objectEnumerator];
auto * devices = [self.nodeIDToDeviceMap objectEnumerator].allObjects;
[_nodeIDToDeviceMap removeAllObjects];
os_unfair_lock_unlock(self.deviceMapLock);

Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ - (void)cleanupAfterStartup
// devices before we start invalidating.
MTR_LOG("%s: %@", __PRETTY_FUNCTION__, self);
os_unfair_lock_lock(self.deviceMapLock);
NSEnumerator * devices = [self.nodeIDToDeviceMap objectEnumerator];
auto * devices = [self.nodeIDToDeviceMap objectEnumerator].allObjects;
[self.nodeIDToDeviceMap removeAllObjects];
os_unfair_lock_unlock(self.deviceMapLock);

Expand Down

0 comments on commit 1581874

Please sign in to comment.