diff options
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alMain.h | 35 | ||||
-rw-r--r-- | OpenAL32/alState.c | 11 |
2 files changed, 38 insertions, 8 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 641baf7c..fa11a3d8 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -249,6 +249,12 @@ static __inline RefCount IncrementRef(volatile RefCount *ptr) static __inline RefCount DecrementRef(volatile RefCount *ptr) { return __sync_sub_and_fetch(ptr, 1); } +#define DECL_TEMPLATE(T) \ +static __inline T Exchange_##T(volatile T *ptr, T newval) \ +{ \ + return __sync_lock_test_and_set(ptr, newval); \ +} + #elif defined(_WIN32) typedef LONG RefCount; @@ -257,6 +263,16 @@ static __inline RefCount IncrementRef(volatile RefCount *ptr) static __inline RefCount DecrementRef(volatile RefCount *ptr) { return InterlockedDecrement(ptr); } +#define DECL_TEMPLATE(T) \ +static __inline T Exchange_##T(volatile T *ptr, T newval) \ +{ \ + union { \ + volatile T *t; \ + volatile LONG *l; \ + } u = { ptr }; \ + return InterlockedExchange(u.l, newval); \ +} + #elif defined(__APPLE__) #include <libkern/OSAtomic.h> @@ -267,10 +283,29 @@ static __inline RefCount IncrementRef(volatile RefCount *ptr) static __inline RefCount DecrementRef(volatile RefCount *ptr) { return OSAtomicDecrement32Barrier(ptr); } +#define DECL_TEMPLATE(T) \ +static __inline T Exchange_##T(volatile T *ptr, T newval) \ +{ \ + union { \ + volatile T *t; \ + volatile int32_t *l; \ + } u = { ptr }; \ + /* Really? No regular old atomic swap? */ \ + T oldval; \ + do { \ + oldval = *u.i; \ + } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, u.i)); \ + return oldval; \ +} + #else #error "No atomic functions available on this platform!" #endif +DECL_TEMPLATE(ALenum) + +#undef DECL_TEMPLATE + #include "alListener.h" #include "alu.h" diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c index 8e4c4671..7e73f407 100644 --- a/OpenAL32/alState.c +++ b/OpenAL32/alState.c @@ -604,22 +604,17 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) continue; } - if((*src)->NeedsUpdate || UpdateSources) - { - (*src)->NeedsUpdate = AL_FALSE; + if(Exchange_ALenum(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources) ALsource_Update(*src, Context); - } + src++; } for(e = 0;e < Context->EffectSlotMap.size;e++) { ALEffectSlot = Context->EffectSlotMap.array[e].value; - if(ALEffectSlot->NeedsUpdate) - { - ALEffectSlot->NeedsUpdate = AL_FALSE; + if(Exchange_ALenum(&ALEffectSlot->NeedsUpdate, AL_FALSE)) ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot); - } } } |