diff options
author | Chris Robinson <[email protected]> | 2011-08-29 21:30:12 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-29 21:30:12 -0700 |
commit | 7408396fd4bc1e99c1f8bd66006c5587362a5d8e (patch) | |
tree | c01e5440dcfe31efa4eda1c001386b68659c554e | |
parent | da081b81c425805eef5b3d4a07c7a213490e04b7 (diff) |
Use a generic int type to handle enum swaps
-rw-r--r-- | Alc/ALu.c | 6 | ||||
-rw-r--r-- | Alc/helpers.c | 4 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 86 | ||||
-rw-r--r-- | OpenAL32/alError.c | 4 | ||||
-rw-r--r-- | OpenAL32/alState.c | 10 |
5 files changed, 48 insertions, 62 deletions
@@ -982,7 +982,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ALenum UpdateSources = AL_FALSE; if(!DeferUpdates) - UpdateSources = Exchange_ALenum(&ctx->UpdateSources, AL_FALSE); + UpdateSources = ExchangeInt(&ctx->UpdateSources, AL_FALSE); src = ctx->ActiveSources; src_end = src + ctx->ActiveSourceCount; @@ -995,7 +995,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) continue; } - if(!DeferUpdates && (Exchange_ALenum(&(*src)->NeedsUpdate, AL_FALSE) || + if(!DeferUpdates && (ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources)) ALsource_Update(*src, ctx); @@ -1019,7 +1019,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ALEffectSlot->PendingClicks[i] = 0.0f; } - if(!DeferUpdates && Exchange_ALenum(&ALEffectSlot->NeedsUpdate, AL_FALSE)) + if(!DeferUpdates && ExchangeInt(&ALEffectSlot->NeedsUpdate, AL_FALSE)) ALEffect_Update(ALEffectSlot->EffectState, ctx, ALEffectSlot); ALEffect_Process(ALEffectSlot->EffectState, ALEffectSlot, diff --git a/Alc/helpers.c b/Alc/helpers.c index 265c8210..90bec01c 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -268,13 +268,13 @@ void SetRTPriority(void) static void Lock(volatile ALenum *l) { - while(Exchange_ALenum(l, AL_TRUE) == AL_TRUE) + while(ExchangeInt(l, AL_TRUE) == AL_TRUE) Sleep(0); } static void Unlock(volatile ALenum *l) { - Exchange_ALenum(l, AL_FALSE); + ExchangeInt(l, AL_FALSE); } void ReadLock(RWLock *lock) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index a0c83254..454bb715 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -231,14 +231,13 @@ 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); \ -} \ -static __inline ALboolean CompExchange_##T(volatile T *ptr, T oldval, T newval)\ -{ \ - return __sync_bool_compare_and_swap(ptr, oldval, newval); \ +static __inline int ExchangeInt(volatile int *ptr, int newval) +{ + return __sync_lock_test_and_set(ptr, newval); +} +static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval) +{ + return __sync_bool_compare_and_swap(ptr, oldval, newval); } #elif defined(_WIN32) @@ -249,22 +248,23 @@ 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); \ -} \ -static __inline ALboolean CompExchange_##T(volatile T *ptr, T oldval, T newval)\ -{ \ - union { \ - volatile T *t; \ - volatile LONG *l; \ - } u = { ptr }; \ - return InterlockedCompareExchange(u.l, newval, oldval) == oldval; \ +static LONG_size_does_not_match_int[(sizeof(LONG)==sizeof(int))?0:-1]; + +static __inline int ExchangeInt(volatile int *ptr, int newval) +{ + union { + volatile int *i; + volatile LONG *l; + } u = { ptr }; + return InterlockedExchange(u.l, newval); +} +static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval) +{ + union { + volatile int *i; + volatile LONG *l; + } u = { ptr }; + return InterlockedCompareExchange(u.l, newval, oldval) == oldval; } #elif defined(__APPLE__) @@ -277,39 +277,25 @@ 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; \ -} \ -static __inline ALboolean CompExchange_##T(volatile T *ptr, T oldval, T newval)\ -{ \ - union { \ - volatile T *t; \ - volatile int32_t *i; \ - } u = { ptr }; \ - return OSAtomicCompareAndSwap32Barrier(oldval, newval, u.i); \ +static __inline int ExchangeInt(volatile int *ptr, int newval) +{ + /* Really? No regular old atomic swap? */ + int oldval; + do { + oldval = *ptr; + } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr)); + return oldval; +} +static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval) +{ + return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr); } #else #error "No atomic functions available on this platform!" typedef ALuint RefCount; -#define DECL_TEMPLATE(T) #endif -DECL_TEMPLATE(ALenum) - -#undef DECL_TEMPLATE - typedef struct { volatile RefCount read_count; diff --git a/OpenAL32/alError.c b/OpenAL32/alError.c index edca01f2..88e284b0 100644 --- a/OpenAL32/alError.c +++ b/OpenAL32/alError.c @@ -32,7 +32,7 @@ AL_API ALenum AL_APIENTRY alGetError(ALvoid) Context = GetReffedContext(); if(!Context) return AL_INVALID_OPERATION; - errorCode = Exchange_ALenum(&Context->LastError, AL_NO_ERROR); + errorCode = ExchangeInt(&Context->LastError, AL_NO_ERROR); ALCcontext_DecRef(Context); @@ -41,5 +41,5 @@ AL_API ALenum AL_APIENTRY alGetError(ALvoid) ALvoid alSetError(ALCcontext *Context, ALenum errorCode) { - CompExchange_ALenum(&Context->LastError, AL_NO_ERROR, errorCode); + CompExchangeInt(&Context->LastError, AL_NO_ERROR, errorCode); } diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c index 76628038..297250bd 100644 --- a/OpenAL32/alState.c +++ b/OpenAL32/alState.c @@ -591,7 +591,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) Context->DeferUpdates = AL_TRUE; /* Make sure all pending updates are performed */ - UpdateSources = Exchange_ALenum(&Context->UpdateSources, AL_FALSE); + UpdateSources = ExchangeInt(&Context->UpdateSources, AL_FALSE); src = Context->ActiveSources; src_end = src + Context->ActiveSourceCount; @@ -604,7 +604,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) continue; } - if(Exchange_ALenum(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources) + if(ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources) ALsource_Update(*src, Context); src++; @@ -614,7 +614,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) for(e = 0;e < Context->EffectSlotMap.size;e++) { ALEffectSlot = Context->EffectSlotMap.array[e].value; - if(Exchange_ALenum(&ALEffectSlot->NeedsUpdate, AL_FALSE)) + if(ExchangeInt(&ALEffectSlot->NeedsUpdate, AL_FALSE)) ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot); } UnlockUIntMapRead(&Context->EffectSlotMap); @@ -631,7 +631,7 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void) Context = GetReffedContext(); if(!Context) return; - if(Exchange_ALenum(&Context->DeferUpdates, AL_FALSE)) + if(ExchangeInt(&Context->DeferUpdates, AL_FALSE)) { ALsizei pos; @@ -645,7 +645,7 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void) if(Source->lOffset != -1) ApplyOffset(Source); - new_state = Exchange_ALenum(&Source->new_state, AL_NONE); + new_state = ExchangeInt(&Source->new_state, AL_NONE); if(new_state) SetSourceState(Source, Context, new_state); } |