diff options
author | Chris Robinson <[email protected]> | 2018-11-20 10:45:01 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-20 10:45:01 -0800 |
commit | 191ea90de3994f9e98377ea9318c4c7b6885179c (patch) | |
tree | 53d42071b9ff0693b706c956a56f760361a11d41 | |
parent | 1e31ac469e129ccd5cde5fb890b31fa8b6815a9b (diff) |
Use atomic_flags and atomic<bools>s where appropriate
-rw-r--r-- | Alc/alc.cpp | 16 | ||||
-rw-r--r-- | Alc/alcontext.h | 4 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alListener.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alSource.h | 2 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.cpp | 4 | ||||
-rw-r--r-- | OpenAL32/alListener.cpp | 8 | ||||
-rw-r--r-- | OpenAL32/alSource.cpp | 12 | ||||
-rw-r--r-- | OpenAL32/alState.cpp | 14 |
9 files changed, 30 insertions, 34 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 10a1511e..00148246 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1604,7 +1604,7 @@ void SetDefaultChannelOrder(ALCdevice *device) */ void ALCcontext_DeferUpdates(ALCcontext *context) { - ATOMIC_STORE_SEQ(&context->DeferUpdates, AL_TRUE); + context->DeferUpdates.store(true); } /* ALCcontext_ProcessUpdates @@ -1614,7 +1614,7 @@ void ALCcontext_DeferUpdates(ALCcontext *context) void ALCcontext_ProcessUpdates(ALCcontext *context) { almtx_lock(&context->PropLock); - if(context->DeferUpdates.exchange(AL_FALSE)) + if(context->DeferUpdates.exchange(false)) { /* Tell the mixer to stop applying updates, then wait for any active * updating to finish, before providing updates. @@ -1623,9 +1623,9 @@ void ALCcontext_ProcessUpdates(ALCcontext *context) while((ATOMIC_LOAD(&context->UpdateCount, almemory_order_acquire)&1) != 0) althrd_yield(); - if(!context->PropsClean.exchange(AL_TRUE, std::memory_order_acq_rel)) + if(!context->PropsClean.test_and_set(std::memory_order_acq_rel)) UpdateContextProps(context); - if(!context->Listener.PropsClean.exchange(AL_TRUE, std::memory_order_acq_rel)) + if(!context->Listener.PropsClean.test_and_set(std::memory_order_acq_rel)) UpdateListenerProps(context); UpdateAllEffectSlotProps(context); UpdateAllSourceProps(context); @@ -2319,7 +2319,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } } - ATOMIC_STORE(&source->PropsClean, AL_FALSE, almemory_order_release); + source->PropsClean.clear(std::memory_order_release); } } @@ -2356,9 +2356,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } almtx_unlock(&context->SourceLock); - ATOMIC_STORE(&context->PropsClean, AL_TRUE, almemory_order_release); + context->PropsClean.test_and_set(std::memory_order_release); UpdateContextProps(context); - ATOMIC_STORE(&context->Listener.PropsClean, AL_TRUE, almemory_order_release); + context->Listener.PropsClean.test_and_set(std::memory_order_release); UpdateListenerProps(context); UpdateAllSourceProps(context); almtx_unlock(&context->PropLock); @@ -2538,8 +2538,6 @@ static ALvoid InitContext(ALCcontext *Context) Context->DopplerVelocity = 1.0f; Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC; Context->MetersPerUnit = AL_DEFAULT_METERS_PER_UNIT; - ATOMIC_INIT(&Context->PropsClean, AL_TRUE); - ATOMIC_INIT(&Context->DeferUpdates, AL_FALSE); alsem_init(&Context->EventSem, 0); almtx_init(&Context->EventCbLock, almtx_plain); diff --git a/Alc/alcontext.h b/Alc/alcontext.h index 424f1447..ce715bc2 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -69,8 +69,8 @@ struct ALCcontext_struct { ALfloat SpeedOfSound{}; ALfloat MetersPerUnit{1.0f}; - ATOMIC(ALenum) PropsClean{AL_TRUE}; - ATOMIC(ALenum) DeferUpdates{AL_FALSE}; + std::atomic_flag PropsClean{true}; + std::atomic<bool> DeferUpdates{false}; almtx_t PropLock; diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 6e315e8f..dd44b436 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -69,7 +69,7 @@ struct ALeffectslot { EffectState *State{nullptr}; } Effect; - ATOMIC(ALenum) PropsClean{AL_TRUE}; + std::atomic_flag PropsClean{true}; RefCount ref{0u}; diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h index 1e0a8265..6b1dcda9 100644 --- a/OpenAL32/Include/alListener.h +++ b/OpenAL32/Include/alListener.h @@ -28,7 +28,7 @@ struct ALlistener { ALfloat Up[3]{0.0f, 1.0f, 0.0f}; ALfloat Gain{1.0f}; - ATOMIC(ALenum) PropsClean{AL_TRUE}; + std::atomic_flag PropsClean{true}; /* Pointer to the most recent property values that are awaiting an update. */ diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index 3d7d733e..9ad5577d 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -97,7 +97,7 @@ typedef struct ALsource { /** Source Buffer Queue head. */ ALbufferlistitem *queue; - ATOMIC(ALenum) PropsClean; + std::atomic_flag PropsClean{true}; /* Index into the context's Voices array. Lazily updated, only checked and * reset when looking up the voice. diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index ea1765bb..df2c2a43 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -175,7 +175,7 @@ inline EffectStateFactory *getFactoryByType(ALenum type) if(!context->DeferUpdates.load(std::memory_order_acquire)) \ UpdateEffectSlotProps(slot, context.get()); \ else \ - slot->PropsClean.store(AL_FALSE, std::memory_order_release); \ + slot->PropsClean.clear(std::memory_order_release); \ } while(0) } // namespace @@ -652,7 +652,7 @@ void UpdateAllEffectSlotProps(ALCcontext *context) for(ALsizei i{0};i < auxslots->count;i++) { ALeffectslot *slot = auxslots->slot[i]; - if(!slot->PropsClean.exchange(AL_TRUE, std::memory_order_acq_rel)) + if(!slot->PropsClean.test_and_set(std::memory_order_acq_rel)) UpdateEffectSlotProps(slot, context); } } diff --git a/OpenAL32/alListener.cpp b/OpenAL32/alListener.cpp index d60f5254..bd004368 100644 --- a/OpenAL32/alListener.cpp +++ b/OpenAL32/alListener.cpp @@ -30,10 +30,10 @@ #include "alSource.h" #define DO_UPDATEPROPS() do { \ - if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \ + if(!context->DeferUpdates.load(std::memory_order_acquire)) \ UpdateListenerProps(context); \ else \ - ATOMIC_STORE(&listener->PropsClean, AL_FALSE, almemory_order_release);\ + listener->PropsClean.clear(std::memory_order_release); \ } while(0) @@ -60,10 +60,10 @@ AL_API ALvoid AL_APIENTRY alListenerf(ALenum param, ALfloat value) if(!(value >= AL_MIN_METERS_PER_UNIT && value <= AL_MAX_METERS_PER_UNIT)) SETERR_GOTO(context, AL_INVALID_VALUE, done, "Listener meters per unit out of range"); context->MetersPerUnit = value; - if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) + if(!context->DeferUpdates.load(std::memory_order_acquire)) UpdateContextProps(context); else - ATOMIC_STORE(&context->PropsClean, AL_FALSE, almemory_order_release); + context->PropsClean.clear(std::memory_order_release); break; default: diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp index 2c452918..c487d877 100644 --- a/OpenAL32/alSource.cpp +++ b/OpenAL32/alSource.cpp @@ -222,7 +222,7 @@ static inline ALenum GetSourceState(ALsource *source, ALvoice *voice) */ static inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) { - return !ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire) && + return !context->DeferUpdates.load(std::memory_order_acquire) && IsPlayingOrPaused(source); } @@ -520,7 +520,7 @@ static ALint Int64ValsByProp(ALenum prop) (voice=GetSourceVoice(Source, Context)) != NULL) \ UpdateSourceProps(Source, voice, device->NumAuxSends, Context); \ else \ - ATOMIC_STORE(&Source->PropsClean, AL_FALSE, almemory_order_release); \ + Source->PropsClean.clear(std::memory_order_release); \ } while(0) static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values) @@ -1038,7 +1038,7 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p if((voice=GetSourceVoice(Source, Context)) != NULL) UpdateSourceProps(Source, voice, device->NumAuxSends, Context); else - ATOMIC_STORE(&Source->PropsClean, AL_FALSE, almemory_order_release); + Source->PropsClean.clear(std::memory_order_release); } else { @@ -2489,7 +2489,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) voice = context->Voices[vidx]; voice->Playing.store(false, std::memory_order_release); - source->PropsClean.exchange(AL_TRUE, std::memory_order_acquire); + source->PropsClean.test_and_set(std::memory_order_acquire); UpdateSourceProps(source, voice, device->NumAuxSends, context); /* A source that's not playing or paused has any offset applied when it @@ -3113,8 +3113,6 @@ static void InitSourceParams(ALsource *Source, ALsizei num_sends) Source->queue = NULL; - ATOMIC_INIT(&Source->PropsClean, AL_TRUE); - Source->VoiceIdx = -1; } @@ -3248,7 +3246,7 @@ void UpdateAllSourceProps(ALCcontext *context) { ALvoice *voice = context->Voices[pos]; ALsource *source = ATOMIC_LOAD(&voice->Source, almemory_order_acquire); - if(source && !source->PropsClean.exchange(AL_TRUE, std::memory_order_acq_rel)) + if(source && !source->PropsClean.test_and_set(std::memory_order_acq_rel)) UpdateSourceProps(source, voice, num_sends, context); } } diff --git a/OpenAL32/alState.cpp b/OpenAL32/alState.cpp index e3e8856f..2901baa2 100644 --- a/OpenAL32/alState.cpp +++ b/OpenAL32/alState.cpp @@ -67,10 +67,10 @@ extern "C" AL_API const ALchar* AL_APIENTRY alsoft_get_version(void) } #define DO_UPDATEPROPS() do { \ - if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \ + if(!context->DeferUpdates.load(std::memory_order_acquire)) \ UpdateContextProps(context.get()); \ else \ - ATOMIC_STORE(&context->PropsClean, AL_FALSE, almemory_order_release); \ + context->PropsClean.clear(std::memory_order_release); \ } while(0) @@ -160,7 +160,7 @@ AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) break; case AL_DEFERRED_UPDATES_SOFT: - if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) + if(context->DeferUpdates.load(std::memory_order_acquire)) value = AL_TRUE; break; @@ -211,7 +211,7 @@ AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) break; case AL_DEFERRED_UPDATES_SOFT: - if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) + if(context->DeferUpdates.load(std::memory_order_acquire)) value = (ALdouble)AL_TRUE; break; @@ -260,7 +260,7 @@ AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) break; case AL_DEFERRED_UPDATES_SOFT: - if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) + if(context->DeferUpdates.load(std::memory_order_acquire)) value = (ALfloat)AL_TRUE; break; @@ -309,7 +309,7 @@ AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) break; case AL_DEFERRED_UPDATES_SOFT: - if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) + if(context->DeferUpdates.load(std::memory_order_acquire)) value = (ALint)AL_TRUE; break; @@ -358,7 +358,7 @@ extern "C" AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname) break; case AL_DEFERRED_UPDATES_SOFT: - if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) + if(context->DeferUpdates.load(std::memory_order_acquire)) value = (ALint64SOFT)AL_TRUE; break; |