Skip to content

Commit

Permalink
[Darwin] MTRDevice _delegateExists cannot be called without holding l…
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple authored and silabs-olivierb committed Feb 19, 2025
1 parent ece725b commit 603d666
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ - (void)invalidate
[self _cancelAllAttributeValueWaiters];
}

- (BOOL)delegateExists
{
std::lock_guard lock(_lock);
return [self _delegateExists];
}

- (BOOL)_delegateExists
{
os_unfair_lock_assert_owner(&self->_lock);
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ - (void)_updateRegistrationInfo

for (NSNumber * nodeID in [self.nodeIDToDeviceMap keyEnumerator]) {
MTRDevice * device = [self _deviceForNodeID:nodeID createIfNeeded:NO];
if ([device _delegateExists]) {
if ([device delegateExists]) {
NSMutableDictionary * nodeDictionary = [NSMutableDictionary dictionary];
MTR_REQUIRED_ATTRIBUTE(MTRDeviceControllerRegistrationNodeIDKey, nodeID, nodeDictionary)

Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ MTR_DIRECT_MEMBERS
// Returns YES if any non-null delegates were found
- (BOOL)_iterateDelegatesWithBlock:(void(NS_NOESCAPE ^ _Nullable)(MTRDeviceDelegateInfo * delegateInfo))block;

// For subclasses to call while holding lock
- (BOOL)_delegateExists;

// For device controller or other objects to call
- (BOOL)delegateExists;

// Must be called by subclasses or MTRDevice implementation only.
- (void)_delegateAdded:(id<MTRDeviceDelegate>)delegate;
- (void)_delegateRemoved:(id<MTRDeviceDelegate>)delegate;
Expand Down

0 comments on commit 603d666

Please sign in to comment.