diff options
author | Chris Robinson <[email protected]> | 2022-02-08 09:39:02 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-02-08 09:39:02 -0800 |
commit | 843cff0537ca07446ab01421ffc7aa6181414502 (patch) | |
tree | 73d8c96794879f9ea8abe717e0d5f105ca6c3b15 | |
parent | 370f8623929f6c4cd245ac79b8569f1be53e6c51 (diff) |
Hold mPropLock when deferring updates
-rw-r--r-- | al/state.cpp | 2 | ||||
-rw-r--r-- | alc/alc.cpp | 6 | ||||
-rw-r--r-- | alc/context.cpp | 1 | ||||
-rw-r--r-- | alc/context.h | 10 |
4 files changed, 15 insertions, 4 deletions
diff --git a/al/state.cpp b/al/state.cpp index bd62c4e3..6da55d6f 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -878,6 +878,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if UNLIKELY(!context) return; + std::lock_guard<std::mutex> _{context->mPropLock}; context->deferUpdates(); } END_API_FUNC @@ -888,6 +889,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if UNLIKELY(!context) return; + std::lock_guard<std::mutex> _{context->mPropLock}; context->processUpdates(); } END_API_FUNC diff --git a/alc/alc.cpp b/alc/alc.cpp index 82e31667..1659593f 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2292,7 +2292,10 @@ START_API_FUNC if(!ctx) alcSetError(nullptr, ALC_INVALID_CONTEXT); else + { + std::lock_guard<std::mutex> _{ctx->mPropLock}; ctx->deferUpdates(); + } } END_API_FUNC @@ -2306,7 +2309,10 @@ START_API_FUNC if(!ctx) alcSetError(nullptr, ALC_INVALID_CONTEXT); else + { + std::lock_guard<std::mutex> _{ctx->mPropLock}; ctx->processUpdates(); + } } END_API_FUNC diff --git a/alc/context.cpp b/alc/context.cpp index 290c4f01..ea806d95 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -249,7 +249,6 @@ bool ALCcontext::deinit() void ALCcontext::processUpdates() { - std::lock_guard<std::mutex> _{mPropLock}; if(mDeferUpdates.exchange(false, std::memory_order_acq_rel)) { /* Tell the mixer to stop applying updates, then wait for any active diff --git a/alc/context.h b/alc/context.h index b22aaf62..22c2418a 100644 --- a/alc/context.h +++ b/alc/context.h @@ -153,11 +153,15 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext>, ContextBase { /** * Defers/suspends updates for the given context's listener and sources. * This does *NOT* stop mixing, but rather prevents certain property - * changes from taking effect. + * changes from taking effect. mPropLock must be held when called. */ - void deferUpdates() noexcept { mDeferUpdates.exchange(true, std::memory_order_acq_rel); } + bool deferUpdates() noexcept + { return mDeferUpdates.exchange(true, std::memory_order_acq_rel); } - /** Resumes update processing after being deferred. */ + /** + * Resumes update processing after being deferred. mPropLock must be held + * when called. + */ void processUpdates(); #ifdef __USE_MINGW_ANSI_STDIO |