aboutsummaryrefslogtreecommitdiffstats
path: root/alc/context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alc/context.cpp')
-rw-r--r--alc/context.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/alc/context.cpp b/alc/context.cpp
index 906a160e..f9aec221 100644
--- a/alc/context.cpp
+++ b/alc/context.cpp
@@ -84,6 +84,7 @@ constexpr ALchar alExtList[] =
} // namespace
+std::atomic<bool> ALCcontext::sGlobalContextLock{false};
std::atomic<ALCcontext*> ALCcontext::sGlobalContext{nullptr};
thread_local ALCcontext *ALCcontext::sLocalContext{nullptr};
@@ -203,7 +204,14 @@ bool ALCcontext::deinit()
ALCcontext *origctx{this};
if(sGlobalContext.compare_exchange_strong(origctx, nullptr))
+ {
+ while(sGlobalContextLock.load()) {
+ /* Wait to make sure another thread didn't get the context and is
+ * trying to increment its refcount.
+ */
+ }
dec_ref();
+ }
bool ret{};
/* First make sure this context exists in the device's list. */