diff options
-rw-r--r-- | Alc/ALc.c | 14 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alListener.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alSource.h | 2 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 6 | ||||
-rw-r--r-- | OpenAL32/alListener.c | 4 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 13 | ||||
-rw-r--r-- | OpenAL32/alState.c | 2 | ||||
-rw-r--r-- | common/atomic.h | 30 | ||||
-rw-r--r-- | common/rwlock.c | 10 | ||||
-rw-r--r-- | common/rwlock.h | 9 |
12 files changed, 32 insertions, 64 deletions
@@ -1624,9 +1624,9 @@ void ALCcontext_ProcessUpdates(ALCcontext *context) while((ATOMIC_LOAD(&context->UpdateCount, almemory_order_acquire)&1) != 0) althrd_yield(); - if(!ATOMIC_FLAG_TEST_AND_SET(&context->PropsClean, almemory_order_acq_rel)) + if(!ATOMIC_EXCHANGE(&context->PropsClean, AL_TRUE, almemory_order_acq_rel)) UpdateContextProps(context); - if(!ATOMIC_FLAG_TEST_AND_SET(&context->Listener->PropsClean, almemory_order_acq_rel)) + if(!ATOMIC_EXCHANGE(&context->Listener->PropsClean, AL_TRUE, almemory_order_acq_rel)) UpdateListenerProps(context); UpdateAllEffectSlotProps(context); UpdateAllSourceProps(context); @@ -2330,7 +2330,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } } - ATOMIC_FLAG_CLEAR(&source->PropsClean, almemory_order_release); + ATOMIC_STORE(&source->PropsClean, AL_FALSE, almemory_order_release); } } @@ -2367,9 +2367,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } almtx_unlock(&context->SourceLock); - ATOMIC_FLAG_TEST_AND_SET(&context->PropsClean, almemory_order_release); + ATOMIC_STORE(&context->PropsClean, AL_TRUE, almemory_order_release); UpdateContextProps(context); - ATOMIC_FLAG_TEST_AND_SET(&context->Listener->PropsClean, almemory_order_release); + ATOMIC_STORE(&context->Listener->PropsClean, AL_TRUE, almemory_order_release); UpdateListenerProps(context); UpdateAllSourceProps(context); almtx_unlock(&context->PropLock); @@ -2606,7 +2606,7 @@ static ALvoid InitContext(ALCcontext *Context) listener->Up[0] = 0.0f; listener->Up[1] = 1.0f; listener->Up[2] = 0.0f; - ATOMIC_FLAG_TEST_AND_SET(&listener->PropsClean, almemory_order_relaxed); + ATOMIC_INIT(&listener->PropsClean, AL_TRUE); ATOMIC_INIT(&listener->Update, NULL); @@ -2642,7 +2642,7 @@ static ALvoid InitContext(ALCcontext *Context) Context->DopplerVelocity = 1.0f; Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC; Context->MetersPerUnit = AL_DEFAULT_METERS_PER_UNIT; - ATOMIC_FLAG_TEST_AND_SET(&Context->PropsClean, almemory_order_relaxed); + ATOMIC_INIT(&Context->PropsClean, AL_TRUE); ATOMIC_INIT(&Context->DeferUpdates, AL_FALSE); alsem_init(&Context->EventSem, 0); Context->AsyncEvents = NULL; diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 97a3906d..16de9a79 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -111,7 +111,7 @@ typedef struct ALeffectslot { ALeffectState *State; } Effect; - ATOMIC_FLAG PropsClean; + ATOMIC(ALenum) PropsClean; RefCount ref; diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h index 0d80a8d7..9efadf47 100644 --- a/OpenAL32/Include/alListener.h +++ b/OpenAL32/Include/alListener.h @@ -36,7 +36,7 @@ typedef struct ALlistener { ALfloat Up[3]; ALfloat Gain; - ATOMIC_FLAG PropsClean; + ATOMIC(ALenum) PropsClean; /* Pointer to the most recent property values that are awaiting an update. */ diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 8cb22615..666a8ade 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -808,7 +808,7 @@ struct ALCcontext_struct { ALfloat SpeedOfSound; ALfloat MetersPerUnit; - ATOMIC_FLAG PropsClean; + ATOMIC(ALenum) PropsClean; ATOMIC(ALenum) DeferUpdates; almtx_t PropLock; diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index 5f07c09d..f7749de3 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -98,7 +98,7 @@ typedef struct ALsource { /** Source Buffer Queue head. */ ALbufferlistitem *queue; - ATOMIC_FLAG PropsClean; + ATOMIC(ALenum) PropsClean; /* Index into the context's Voices array. Lazily updated, only checked and * reset when looking up the voice. diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index e1d84bb9..4758646f 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -103,7 +103,7 @@ static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \ UpdateEffectSlotProps(slot, context); \ else \ - ATOMIC_FLAG_CLEAR(&slot->PropsClean, almemory_order_release); \ + ATOMIC_STORE(&slot->PropsClean, AL_FALSE, almemory_order_release); \ } while(0) @@ -679,7 +679,7 @@ ALenum InitEffectSlot(ALeffectslot *slot) slot->Gain = 1.0; slot->AuxSendAuto = AL_TRUE; - ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_relaxed); + ATOMIC_INIT(&slot->PropsClean, AL_TRUE); InitRef(&slot->ref, 0); ATOMIC_INIT(&slot->Update, NULL); @@ -773,7 +773,7 @@ void UpdateAllEffectSlotProps(ALCcontext *context) for(i = 0;i < auxslots->count;i++) { ALeffectslot *slot = auxslots->slot[i]; - if(!ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_acq_rel)) + if(!ATOMIC_EXCHANGE(&slot->PropsClean, AL_TRUE, almemory_order_acq_rel)) UpdateEffectSlotProps(slot, context); } UnlockEffectSlotList(context); diff --git a/OpenAL32/alListener.c b/OpenAL32/alListener.c index f1ac3ff4..700fa0af 100644 --- a/OpenAL32/alListener.c +++ b/OpenAL32/alListener.c @@ -30,7 +30,7 @@ if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \ UpdateListenerProps(context); \ else \ - ATOMIC_FLAG_CLEAR(&listener->PropsClean, almemory_order_release); \ + ATOMIC_STORE(&listener->PropsClean, AL_FALSE, almemory_order_release);\ } while(0) @@ -60,7 +60,7 @@ AL_API ALvoid AL_APIENTRY alListenerf(ALenum param, ALfloat value) if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) UpdateContextProps(context); else - ATOMIC_FLAG_CLEAR(&context->PropsClean, almemory_order_release); + ATOMIC_STORE(&context->PropsClean, AL_FALSE, almemory_order_release); break; default: diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 1f76a069..2eb69cb9 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -519,7 +519,7 @@ static ALint Int64ValsByProp(ALenum prop) (voice=GetSourceVoice(Source, Context)) != NULL) \ UpdateSourceProps(Source, voice, device->NumAuxSends, Context); \ else \ - ATOMIC_FLAG_CLEAR(&Source->PropsClean, almemory_order_release); \ + ATOMIC_STORE(&Source->PropsClean, AL_FALSE, almemory_order_release); \ } while(0) static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values) @@ -1036,7 +1036,7 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p if((voice=GetSourceVoice(Source, Context)) != NULL) UpdateSourceProps(Source, voice, device->NumAuxSends, Context); else - ATOMIC_FLAG_CLEAR(&Source->PropsClean, almemory_order_release); + ATOMIC_STORE(&Source->PropsClean, AL_FALSE, almemory_order_release); } else { @@ -2488,7 +2488,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) voice = context->Voices[vidx]; ATOMIC_STORE(&voice->Playing, false, almemory_order_release); - ATOMIC_FLAG_TEST_AND_SET(&source->PropsClean, almemory_order_acquire); + ATOMIC_EXCHANGE(&source->PropsClean, AL_TRUE, almemory_order_acquire); UpdateSourceProps(source, voice, device->NumAuxSends, context); /* A source that's not playing or paused has any offset applied when it @@ -3109,10 +3109,7 @@ static void InitSourceParams(ALsource *Source, ALsizei num_sends) Source->queue = NULL; - /* No way to do an 'init' here, so just test+set with relaxed ordering and - * ignore the test. - */ - ATOMIC_FLAG_TEST_AND_SET(&Source->PropsClean, almemory_order_relaxed); + ATOMIC_INIT(&Source->PropsClean, AL_TRUE); Source->VoiceIdx = -1; } @@ -3246,7 +3243,7 @@ void UpdateAllSourceProps(ALCcontext *context) { ALvoice *voice = context->Voices[pos]; ALsource *source = ATOMIC_LOAD(&voice->Source, almemory_order_acquire); - if(source && !ATOMIC_FLAG_TEST_AND_SET(&source->PropsClean, almemory_order_acq_rel)) + if(source && !ATOMIC_EXCHANGE(&source->PropsClean, AL_TRUE, almemory_order_acq_rel)) UpdateSourceProps(source, voice, num_sends, context); } } diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c index ce93e143..8be08435 100644 --- a/OpenAL32/alState.c +++ b/OpenAL32/alState.c @@ -68,7 +68,7 @@ AL_API const ALchar* AL_APIENTRY alsoft_get_version(void) if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \ UpdateContextProps(context); \ else \ - ATOMIC_FLAG_CLEAR(&context->PropsClean, almemory_order_release); \ + ATOMIC_STORE(&context->PropsClean, AL_FALSE, almemory_order_release); \ } while(0) diff --git a/common/atomic.h b/common/atomic.h index 17e616bb..2c81f62f 100644 --- a/common/atomic.h +++ b/common/atomic.h @@ -43,8 +43,6 @@ using std::memory_order_release; using std::memory_order_acq_rel; using std::memory_order_seq_cst; -using std::atomic_flag; - using std::atomic_init; using std::atomic_load_explicit; using std::atomic_store_explicit; @@ -53,8 +51,6 @@ using std::atomic_fetch_sub_explicit; using std::atomic_exchange_explicit; using std::atomic_compare_exchange_strong_explicit; using std::atomic_compare_exchange_weak_explicit; -using std::atomic_flag_test_and_set_explicit; -using std::atomic_flag_clear_explicit; using std::atomic_thread_fence; #else @@ -79,11 +75,9 @@ extern "C" { #define almemory_order_seq_cst memory_order_seq_cst #define ATOMIC(T) _Atomic(T) -#define ATOMIC_FLAG atomic_flag #define ATOMIC_INIT atomic_init #define ATOMIC_INIT_STATIC ATOMIC_VAR_INIT -/*#define ATOMIC_FLAG_INIT ATOMIC_FLAG_INIT*/ #define ATOMIC_LOAD atomic_load_explicit #define ATOMIC_STORE atomic_store_explicit @@ -95,9 +89,6 @@ extern "C" { #define ATOMIC_COMPARE_EXCHANGE_STRONG atomic_compare_exchange_strong_explicit #define ATOMIC_COMPARE_EXCHANGE_WEAK atomic_compare_exchange_weak_explicit -#define ATOMIC_FLAG_TEST_AND_SET atomic_flag_test_and_set_explicit -#define ATOMIC_FLAG_CLEAR atomic_flag_clear_explicit - #define ATOMIC_THREAD_FENCE atomic_thread_fence /* Atomics using GCC intrinsics */ @@ -113,11 +104,9 @@ enum almemory_order { }; #define ATOMIC(T) struct { T volatile value; } -#define ATOMIC_FLAG ATOMIC(int) #define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0) #define ATOMIC_INIT_STATIC(_newval) {(_newval)} -#define ATOMIC_FLAG_INIT ATOMIC_INIT_STATIC(0) #define ATOMIC_LOAD(_val, _MO) __extension__({ \ __typeof((_val)->value) _r = (_val)->value; \ @@ -142,15 +131,6 @@ enum almemory_order { *(_oldval) == _o; \ }) -#define ATOMIC_FLAG_TEST_AND_SET(_val, _MO) __extension__({ \ - __asm__ __volatile__("" ::: "memory"); \ - __sync_lock_test_and_set(&(_val)->value, 1); \ -}) -#define ATOMIC_FLAG_CLEAR(_val, _MO) __extension__({ \ - __sync_lock_release(&(_val)->value); \ - __asm__ __volatile__("" ::: "memory"); \ -}) - #define ATOMIC_THREAD_FENCE(order) do { \ enum { must_be_constant = (order) }; \ @@ -421,16 +401,6 @@ void *_al_invalid_atomic_ptr_size(); /* not defined */ #define ATOMIC_COMPARE_EXCHANGE_PTR_WEAK ATOMIC_COMPARE_EXCHANGE_PTR_STRONG #endif -/* If no ATOMIC_FLAG is defined, simulate one with an atomic int using exchange - * and store ops. - */ -#ifndef ATOMIC_FLAG -#define ATOMIC_FLAG ATOMIC(int) -#define ATOMIC_FLAG_INIT ATOMIC_INIT_STATIC(0) -#define ATOMIC_FLAG_TEST_AND_SET(_val, _MO) ATOMIC_EXCHANGE(_val, 1, _MO) -#define ATOMIC_FLAG_CLEAR(_val, _MO) ATOMIC_STORE(_val, 0, _MO) -#endif - #define ATOMIC_LOAD_SEQ(_val) ATOMIC_LOAD(_val, almemory_order_seq_cst) #define ATOMIC_STORE_SEQ(_val, _newval) ATOMIC_STORE(_val, _newval, almemory_order_seq_cst) diff --git a/common/rwlock.c b/common/rwlock.c index 67cf3acf..44237282 100644 --- a/common/rwlock.c +++ b/common/rwlock.c @@ -11,19 +11,19 @@ /* A simple spinlock. Yield the thread while the given integer is set by * another. Could probably be improved... */ #define LOCK(l) do { \ - while(ATOMIC_FLAG_TEST_AND_SET(&(l), almemory_order_acq_rel) == true) \ + while(ATOMIC_EXCHANGE(&(l), 1, almemory_order_acq_rel) == true) \ althrd_yield(); \ } while(0) -#define UNLOCK(l) ATOMIC_FLAG_CLEAR(&(l), almemory_order_release) +#define UNLOCK(l) ATOMIC_STORE(&(l), 0, almemory_order_release) void RWLockInit(RWLock *lock) { InitRef(&lock->read_count, 0); InitRef(&lock->write_count, 0); - ATOMIC_FLAG_CLEAR(&lock->read_lock, almemory_order_relaxed); - ATOMIC_FLAG_CLEAR(&lock->read_entry_lock, almemory_order_relaxed); - ATOMIC_FLAG_CLEAR(&lock->write_lock, almemory_order_relaxed); + ATOMIC_INIT(&lock->read_lock, 0); + ATOMIC_INIT(&lock->read_entry_lock, 0); + ATOMIC_INIT(&lock->write_lock, 0); } void ReadLock(RWLock *lock) diff --git a/common/rwlock.h b/common/rwlock.h index 8e36fa1a..fee1b070 100644 --- a/common/rwlock.h +++ b/common/rwlock.h @@ -11,12 +11,13 @@ extern "C" { typedef struct { RefCount read_count; RefCount write_count; - ATOMIC_FLAG read_lock; - ATOMIC_FLAG read_entry_lock; - ATOMIC_FLAG write_lock; + ATOMIC(int) read_lock; + ATOMIC(int) read_entry_lock; + ATOMIC(int) write_lock; } RWLock; #define RWLOCK_STATIC_INITIALIZE { ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), \ - ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT } + ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), \ + ATOMIC_INIT_STATIC(0) } void RWLockInit(RWLock *lock); void ReadLock(RWLock *lock); |