Use atomic_flags and atomic<bools>s where appropriate
This commit is contained in:
+7
-9
@@ -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);
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ struct ALeffectslot {
|
||||
EffectState *State{nullptr};
|
||||
} Effect;
|
||||
|
||||
ATOMIC(ALenum) PropsClean{AL_TRUE};
|
||||
std::atomic_flag PropsClean{true};
|
||||
|
||||
RefCount ref{0u};
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user