diff options
author | Chris Robinson <[email protected]> | 2022-12-30 20:56:37 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-12-30 20:56:37 -0800 |
commit | beaffdda716e2063d1112cb09956d44d948f40b5 (patch) | |
tree | 1aee3242e17c5f59030e4cf26a617e4791ba3ac2 /alc/context.cpp | |
parent | 98ba092c9126ae5534b509a602bfe020d9cebca9 (diff) |
Use a simple spinlock to protect the current global context
This will be much for efficient than a recursive mutex, given the amount of
contention will be very low.
Diffstat (limited to 'alc/context.cpp')
-rw-r--r-- | alc/context.cpp | 8 |
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. */ |