From fb1d23941771ceaa1b412f4473d2a08d5d65f990 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 12 Dec 2022 16:15:34 -0500 Subject: [PATCH] Create dispatch queues in the Darwin framework more consistently. (#24005) * Create dispatch queues in the Darwin framework more consistently. * Use a common prefix for all the queue labels ("org.csa-iot.matter.framework"). * Use DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL for all the queues. * Use a common suffix ("workqueue") for all work queues. * Address review comment --- src/darwin/Framework/CHIP/MTRDevice.mm | 3 ++- .../Framework/CHIP/MTRDeviceAttestationDelegateBridge.h | 3 ++- src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.mm | 3 ++- src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm | 3 ++- .../Framework/CHIP/MTRPersistentStorageDelegateBridge.mm | 3 ++- src/platform/Darwin/BleConnectionDelegateImpl.mm | 3 ++- src/platform/Darwin/PlatformManagerImpl.h | 4 ++-- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index b8ac46c3004b47..389a4ce1ceeca8 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -162,7 +162,8 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle _nodeID = [nodeID copy]; _fabricIndex = controller.fabricIndex; _deviceController = controller; - _queue = dispatch_queue_create("com.apple.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL); + _queue + = dispatch_queue_create("org.csa-iot.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); _readCache = [NSMutableDictionary dictionary]; _expectedValueCache = [NSMutableDictionary dictionary]; _asyncCallbackWorkQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithContext:self queue:_queue]; diff --git a/src/darwin/Framework/CHIP/MTRDeviceAttestationDelegateBridge.h b/src/darwin/Framework/CHIP/MTRDeviceAttestationDelegateBridge.h index 201137d63b3bc4..cef43549da5eb0 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceAttestationDelegateBridge.h +++ b/src/darwin/Framework/CHIP/MTRDeviceAttestationDelegateBridge.h @@ -33,7 +33,8 @@ class MTRDeviceAttestationDelegateBridge : public chip::Credentials::DeviceAttes : mResult(chip::Credentials::AttestationVerificationResult::kSuccess) , mDeviceController(deviceController) , mDeviceAttestationDelegate(deviceAttestationDelegate) - , mQueue(dispatch_queue_create("com.csa.matter.framework.device_attestation.workqueue", DISPATCH_QUEUE_SERIAL)) + , mQueue(dispatch_queue_create( + "org.csa-iot.matter.framework.device_attestation.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL)) , mExpiryTimeoutSecs(expiryTimeoutSecs) , mShouldWaitAfterDeviceAttestation(shouldWaitAfterDeviceAttestation) { diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.mm index b78f498b2fbb82..844c7d26e7c63a 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.mm @@ -31,7 +31,8 @@ static void SetupXPCQueue(void) { dispatch_once(&workQueueInitOnceToken, ^{ - globalWorkQueue = dispatch_queue_create("com.apple.matter.framework.xpc.workqueue", DISPATCH_QUEUE_SERIAL); + globalWorkQueue + = dispatch_queue_create("org.csa-iot.matter.framework.xpc.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); }); } diff --git a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm index 7d5e8c165669bd..d0d6dfc3487347 100644 --- a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm @@ -419,7 +419,8 @@ void ResetState() MTROTAProviderDelegateBridge::MTROTAProviderDelegateBridge(id delegate) : mDelegate(delegate) - , mDelegateNotificationQueue(dispatch_queue_create("com.csa.matter.framework.otaprovider.workqueue", DISPATCH_QUEUE_SERIAL)) + , mDelegateNotificationQueue( + dispatch_queue_create("org.csa-iot.matter.framework.otaprovider.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL)) { gOtaSender.SetDelegate(delegate, mDelegateNotificationQueue); Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, this); diff --git a/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm b/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm index 69e4103645d4ea..f0d535bc3a5ba1 100644 --- a/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm @@ -23,7 +23,8 @@ MTRPersistentStorageDelegateBridge::MTRPersistentStorageDelegateBridge(id delegate) : mDelegate(delegate) - , mWorkQueue(dispatch_queue_create("com.csa.matter.framework.storage.workqueue", DISPATCH_QUEUE_SERIAL)) + , mWorkQueue( + dispatch_queue_create("org.csa-iot.matter.framework.storage.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL)) { } diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index aa891b1fc7ae4a..6858594620257c 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -139,7 +139,8 @@ - (id)init self = [super init]; if (self) { self.shortServiceUUID = [UUIDHelper GetShortestServiceUUID:&chip::Ble::CHIP_BLE_SVC_ID]; - _workQueue = dispatch_queue_create("com.chip.ble.work_queue", DISPATCH_QUEUE_SERIAL); + _workQueue + = dispatch_queue_create("org.csa-iot.matter.framework.ble.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); _chipWorkQueue = chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue(); _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, _workQueue); _centralManager = [CBCentralManager alloc]; diff --git a/src/platform/Darwin/PlatformManagerImpl.h b/src/platform/Darwin/PlatformManagerImpl.h index 354ee517e18b88..c40f74e05d437c 100644 --- a/src/platform/Darwin/PlatformManagerImpl.h +++ b/src/platform/Darwin/PlatformManagerImpl.h @@ -26,7 +26,7 @@ #include #include -static constexpr const char * const CHIP_CONTROLLER_QUEUE = "com.csa.matter.framework.controller.workqueue"; +static constexpr const char * const CHIP_CONTROLLER_QUEUE = "org.csa-iot.matter.framework.controller.workqueue"; namespace chip { namespace DeviceLayer { @@ -47,7 +47,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener { if (mWorkQueue == nullptr) { - mWorkQueue = dispatch_queue_create(CHIP_CONTROLLER_QUEUE, DISPATCH_QUEUE_SERIAL); + mWorkQueue = dispatch_queue_create(CHIP_CONTROLLER_QUEUE, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); dispatch_suspend(mWorkQueue); mIsWorkQueueSuspended = true; }