From 117732470db677d5db961cd2d969ba8f953cb313 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 6 Sep 2023 12:44:36 -0400 Subject: [PATCH] Stop using dispatch_get_current_queue. (#29075) This function is deprecated. --- src/platform/Darwin/PlatformManagerImpl.cpp | 16 +++++++++++++++- src/platform/Darwin/PlatformManagerImpl.h | 12 +----------- 2 files changed, 16 insertions(+), 12 deletions(-) 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);