diff options
-rw-r--r-- | Alc/alu.cpp | 8 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.cpp | 2 | ||||
-rw-r--r-- | OpenAL32/alListener.cpp | 2 | ||||
-rw-r--r-- | OpenAL32/alSource.cpp | 2 | ||||
-rw-r--r-- | OpenAL32/alState.cpp | 2 | ||||
-rw-r--r-- | common/atomic.h | 16 |
6 files changed, 17 insertions, 15 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 9a02d4b6..e26f5f57 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -330,7 +330,7 @@ static bool CalcContextParams(ALCcontext *Context) Listener.Params.SourceDistanceModel = props->SourceDistanceModel; Listener.Params.mDistanceModel = props->mDistanceModel; - ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &Context->FreeContextProps, props); + AtomicReplaceHead(Context->FreeContextProps, props); return true; } @@ -376,7 +376,7 @@ static bool CalcListenerParams(ALCcontext *Context) Listener.Params.Gain = props->Gain * Context->GainBoost; - ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &Context->FreeListenerProps, props); + AtomicReplaceHead(Context->FreeListenerProps, props); return true; } @@ -449,7 +449,7 @@ static bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool f } } - ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props); + AtomicReplaceHead(context->FreeEffectslotProps, props); } else state = slot->Params.EffectState; @@ -1465,7 +1465,7 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) FAM_SIZE(struct ALvoiceProps, Send, context->Device->NumAuxSends) ); - ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &context->FreeVoiceProps, props); + AtomicReplaceHead(context->FreeVoiceProps, props); } props = voice->Props; diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index fc4b4d1b..037c99dd 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -730,7 +730,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) if(props->State) ALeffectState_DecRef(props->State); props->State = nullptr; - ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props); + AtomicReplaceHead(context->FreeEffectslotProps, props); } if(oldstate) diff --git a/OpenAL32/alListener.cpp b/OpenAL32/alListener.cpp index 05fd7a21..574f897c 100644 --- a/OpenAL32/alListener.cpp +++ b/OpenAL32/alListener.cpp @@ -498,6 +498,6 @@ void UpdateListenerProps(ALCcontext *context) /* If there was an unused update container, put it back in the * freelist. */ - ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &context->FreeListenerProps, props); + AtomicReplaceHead(context->FreeListenerProps, props); } } diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp index 2fe81320..ac220a2e 100644 --- a/OpenAL32/alSource.cpp +++ b/OpenAL32/alSource.cpp @@ -3236,7 +3236,7 @@ static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_send /* If there was an unused update container, put it back in the * freelist. */ - ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &context->FreeVoiceProps, props); + AtomicReplaceHead(context->FreeVoiceProps, props); } } diff --git a/OpenAL32/alState.cpp b/OpenAL32/alState.cpp index 85789c5e..836853bb 100644 --- a/OpenAL32/alState.cpp +++ b/OpenAL32/alState.cpp @@ -794,6 +794,6 @@ void UpdateContextProps(ALCcontext *context) /* If there was an unused update container, put it back in the * freelist. */ - ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &context->FreeContextProps, props); + AtomicReplaceHead(context->FreeContextProps, props); } } diff --git a/common/atomic.h b/common/atomic.h index dbb75d29..5e46436f 100644 --- a/common/atomic.h +++ b/common/atomic.h @@ -91,12 +91,14 @@ inline uint DecrementRef(RefCount *ptr) * changing the head without giving this a chance to actually swap in the new * one (practically impossible with this little code, but...). */ -#define ATOMIC_REPLACE_HEAD(T, _head, _entry) do { \ - T _first = ATOMIC_LOAD(_head, almemory_order_acquire); \ - do { \ - ATOMIC_STORE(&(_entry)->next, _first, almemory_order_relaxed); \ - } while(ATOMIC_COMPARE_EXCHANGE_WEAK(_head, &_first, _entry, \ - almemory_order_acq_rel, almemory_order_acquire) == 0); \ -} while(0) +template<typename T> +inline void AtomicReplaceHead(std::atomic<T> &head, T newhead) +{ + T first_ = head.load(std::memory_order_acquire); + do { + newhead->next.store(first_, std::memory_order_relaxed); + } while(!head.compare_exchange_weak(first_, newhead, + std::memory_order_acq_rel, std::memory_order_acquire)); +} #endif /* AL_ATOMIC_H */ |