Skip to content

Commit

Permalink
Remove "run on work queue" bits from non-concrete controllers. (#36320)
Browse files Browse the repository at this point in the history
* Remove "run on work queue" bits from non-concrete controllers.

There is no "work queue" in the sense of the Matter queue involved unless we
have a concrete controller.

* syncRunOnWorkQueueWithReturnValue was unused on MTRDeviceController, so can
  just be removed.

* syncRunOnWorkQueueWithBoolReturnValue was unused on MTRDeviceController, so can
  just be removed.

* After that syncRunOnWorkQueue becomes unused and can be removed.

* At this point chipWorkQueue is not used on the base class and can be moved
  into the subclasses as needed.

* Apply suggestion from code review.
  • Loading branch information
bzbarsky-apple authored Oct 31, 2024
1 parent aff2e17 commit edd9202
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 40 deletions.
34 changes: 0 additions & 34 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -542,40 +542,6 @@ - (void)asyncDispatchToMatterQueue:(dispatch_block_t)block errorHandler:(nullabl
errorHandler([MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE]);
}

- (void)syncRunOnWorkQueue:(SyncWorkQueueBlock)block error:(NSError * __autoreleasing *)error
{
VerifyOrDie(!chip::DeviceLayer::PlatformMgrImpl().IsWorkQueueCurrentQueue());
VerifyOrReturn([self checkIsRunning:error]);

dispatch_sync(_chipWorkQueue, ^{
VerifyOrReturn([self checkIsRunning:error]);
block();
});
}

- (id)syncRunOnWorkQueueWithReturnValue:(SyncWorkQueueBlockWithReturnValue)block error:(NSError * __autoreleasing *)error
{
__block id rv = nil;
auto adapter = ^{
rv = block();
};

[self syncRunOnWorkQueue:adapter error:error];

return rv;
}

- (BOOL)syncRunOnWorkQueueWithBoolReturnValue:(SyncWorkQueueBlockWithBoolReturnValue)block error:(NSError * __autoreleasing *)error
{
__block BOOL success = NO;
auto adapter = ^{
success = block();
};
[self syncRunOnWorkQueue:adapter error:error];

return success;
}

- (chip::FabricIndex)fabricIndex
{
return _storedFabricIndex;
Expand Down
3 changes: 0 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (readonly, assign) os_unfair_lock_t deviceMapLock;

@property (readwrite, nonatomic) NSUUID * uniqueIdentifier;

// queue used to serialize all work performed by the MTRDeviceController
// (moved here so subclasses can initialize differently)
@property (readwrite, retain) dispatch_queue_t chipWorkQueue;

- (instancetype)initForSubclasses:(BOOL)startSuspended;

Expand Down
7 changes: 4 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @interface MTRDeviceController_XPC ()
@property (nonnull, atomic, readwrite, retain) MTRXPCDeviceControllerParameters * xpcParameters;
@property (atomic, readwrite, assign) NSTimeInterval xpcRetryTimeInterval;
@property (atomic, readwrite, assign) BOOL xpcConnectedOrConnecting;
@property (nonatomic, readonly, retain) dispatch_queue_t workQueue;

@end

Expand Down Expand Up @@ -194,7 +195,7 @@ - (void)_startXPCConnectionRetry
self.xpcRetryTimeInterval = 0.5;
mtr_weakify(self);

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (self.xpcRetryTimeInterval * NSEC_PER_SEC)), self.chipWorkQueue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (self.xpcRetryTimeInterval * NSEC_PER_SEC)), self.workQueue, ^{
mtr_strongify(self);
[self _xpcConnectionRetry];
});
Expand All @@ -214,7 +215,7 @@ - (void)_xpcConnectionRetry
self.xpcRetryTimeInterval = MIN(60.0, self.xpcRetryTimeInterval);
mtr_weakify(self);

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.xpcRetryTimeInterval * NSEC_PER_SEC)), self.chipWorkQueue, ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.xpcRetryTimeInterval * NSEC_PER_SEC)), self.workQueue, ^{
mtr_strongify(self);
[self _xpcConnectionRetry];
});
Expand Down Expand Up @@ -302,7 +303,7 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete

self.uniqueIdentifier = UUID;
self.xpcParameters = xpcParameters;
self.chipWorkQueue = dispatch_queue_create("MTRDeviceController_XPC_queue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
_workQueue = dispatch_queue_create("MTRDeviceController_XPC_queue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);

if (![self _setupXPCConnection]) {
return nil;
Expand Down

0 comments on commit edd9202

Please sign in to comment.