diff options
author | Chris Robinson <[email protected]> | 2019-01-01 16:38:54 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-01 16:42:54 -0800 |
commit | 1630a33567b155718b7cb984badb378b140f0889 (patch) | |
tree | 09e043b8c0c90d958431b3ef816c952511b8ad0d /Alc | |
parent | 2f1566e0b4e71f9b03ae8081e81a85f52ddeab23 (diff) |
Use standard unique_lock and lock_guard for the backend lock
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 41 | ||||
-rw-r--r-- | Alc/backends/base.h | 6 |
2 files changed, 23 insertions, 24 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 59582ea6..b69c4756 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2494,9 +2494,6 @@ ALCcontext_struct::~ALCcontext_struct() */ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) { - ALCcontext *origctx, *newhead; - bool ret = true; - if(LocalContext.get() == context) { WARN("%p released while current on thread\n", context); @@ -2504,27 +2501,28 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) ALCcontext_DecRef(context); } - origctx = context; + ALCcontext *origctx{context}; if(GlobalContext.compare_exchange_strong(origctx, nullptr)) ALCcontext_DecRef(context); - device->Backend->lock(); - origctx = context; - newhead = context->next.load(std::memory_order_relaxed); - if(!device->ContextList.compare_exchange_strong(origctx, newhead)) - { - ALCcontext *list; - do { - /* origctx is what the desired context failed to match. Try - * swapping out the next one in the list. - */ - list = origctx; - origctx = context; - } while(!list->next.compare_exchange_strong(origctx, newhead)); + bool ret{true}; + { BackendLockGuard _{*device->Backend}; + origctx = context; + ALCcontext *newhead{context->next.load(std::memory_order_relaxed)}; + if(!device->ContextList.compare_exchange_strong(origctx, newhead)) + { + ALCcontext *list; + do { + /* origctx is what the desired context failed to match. Try + * swapping out the next one in the list. + */ + list = origctx; + origctx = context; + } while(!list->next.compare_exchange_strong(origctx, newhead)); + } + else + ret = !!newhead; } - else - ret = !!newhead; - device->Backend->unlock(); /* Make sure the context is finished and no longer processing in the mixer * before sending the message queue kill event. The backend's lock does @@ -4146,9 +4144,8 @@ FORCE_ALIGN ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, AL alcSetError(dev.get(), ALC_INVALID_VALUE); else { - dev->Backend->lock(); + BackendLockGuard _{*device->Backend}; aluMixData(dev.get(), buffer, samples); - dev->Backend->unlock(); } } diff --git a/Alc/backends/base.h b/Alc/backends/base.h index fc50af2b..93685d5a 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -41,8 +41,8 @@ struct BackendBase { virtual ClockLatency getClockLatency(); - virtual void lock() { mMutex.lock(); }; - virtual void unlock() { mMutex.unlock(); }; + virtual void lock() { mMutex.lock(); } + virtual void unlock() { mMutex.unlock(); } ALCdevice *mDevice; @@ -52,6 +52,8 @@ struct BackendBase { virtual ~BackendBase(); }; using BackendPtr = std::unique_ptr<BackendBase>; +using BackendUniqueLock = std::unique_lock<BackendBase>; +using BackendLockGuard = std::lock_guard<BackendBase>; enum class BackendType { Playback, |