diff --git a/src/platform/Darwin/PlatformManagerImpl.cpp b/src/platform/Darwin/PlatformManagerImpl.cpp index bf2dde3d4fe360..69a95c44673b05 100644 --- a/src/platform/Darwin/PlatformManagerImpl.cpp +++ b/src/platform/Darwin/PlatformManagerImpl.cpp @@ -163,9 +163,23 @@ bool PlatformManagerImpl::_IsChipStackLockedByCurrentThread() const }; #endif +static int sPlatformManagerKey; // We use pointer to this as key. + +dispatch_queue_t PlatformManagerImpl::GetWorkQueue() +{ + if (mWorkQueue == nullptr) + { + mWorkQueue = dispatch_queue_create(CHIP_CONTROLLER_QUEUE, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); + dispatch_suspend(mWorkQueue); + dispatch_queue_set_specific(mWorkQueue, &sPlatformManagerKey, this, nullptr); + mIsWorkQueueSuspended = true; + } + return mWorkQueue; +} + bool PlatformManagerImpl::IsWorkQueueCurrentQueue() const { - return dispatch_get_current_queue() == mWorkQueue; + return dispatch_get_specific(&sPlatformManagerKey) == this; } CHIP_ERROR PlatformManagerImpl::StartBleScan(BleScannerDelegate * delegate) diff --git a/src/platform/Darwin/PlatformManagerImpl.h b/src/platform/Darwin/PlatformManagerImpl.h index 79da67a4991d2f..2dfa9104e0dab3 100644 --- a/src/platform/Darwin/PlatformManagerImpl.h +++ b/src/platform/Darwin/PlatformManagerImpl.h @@ -45,17 +45,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener public: // ===== Platform-specific members that may be accessed directly by the application. - dispatch_queue_t GetWorkQueue() - { - if (mWorkQueue == nullptr) - { - mWorkQueue = dispatch_queue_create(CHIP_CONTROLLER_QUEUE, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); - dispatch_suspend(mWorkQueue); - mIsWorkQueueSuspended = true; - } - return mWorkQueue; - } - + dispatch_queue_t GetWorkQueue(); bool IsWorkQueueCurrentQueue() const; CHIP_ERROR StartBleScan(BleScannerDelegate * delegate = nullptr);