Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Darwin] MTRDevice _delegateExists cannot be called without holding lock #37662

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading