From 886f874ff3025fac7bd07b9439f8ecc3b78fcc36 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 1 Jan 2012 15:00:03 -0800 Subject: Use a proper typedef for handling atomic pointer swaps --- Alc/ALc.c | 12 ++++++------ OpenAL32/Include/alMain.h | 18 ++++++++++-------- OpenAL32/alAuxEffectSlot.c | 2 +- OpenAL32/alSource.c | 6 +++--- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index 01d4ddd5..a9b8a84c 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1457,7 +1457,7 @@ static void ReleaseContext(ALCcontext *context, ALCdevice *device) ALCcontext_DecRef(context); } - if(CompExchangePtr((void**)&GlobalContext, context, NULL)) + if(CompExchangePtr((XchgPtr*)&GlobalContext, context, NULL)) { WARN("%p released while current\n", context); ALCcontext_DecRef(context); @@ -1648,7 +1648,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, do { device->next = DeviceList; - } while(!CompExchangePtr((void**)&DeviceList, device->next, device)); + } while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device)); TRACE("Created device %p\n", device); return device; @@ -2309,7 +2309,7 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context) return ALC_FALSE; } /* context's reference count is already incremented */ - context = ExchangePtr((void**)&GlobalContext, context); + context = ExchangePtr((XchgPtr*)&GlobalContext, context); if(context) ALCcontext_DecRef(context); if((context=pthread_getspecific(LocalContext)) != NULL) @@ -2509,7 +2509,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) do { device->next = DeviceList; - } while(!CompExchangePtr((void**)&DeviceList, device->next, device)); + } while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device)); TRACE("Created device %p\n", device); return device; @@ -2623,7 +2623,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void) ALCdevice_OpenPlayback(device, "Loopback"); do { device->next = DeviceList; - } while(!CompExchangePtr((void**)&DeviceList, device->next, device)); + } while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device)); TRACE("Created device %p\n", device); return device; @@ -2689,7 +2689,7 @@ static void ReleaseALC(void) free(alcCaptureDefaultDeviceSpecifier); alcCaptureDefaultDeviceSpecifier = NULL; - if((dev=ExchangePtr((void**)&DeviceList, NULL)) != NULL) + if((dev=ExchangePtr((XchgPtr*)&DeviceList, NULL)) != NULL) { ALCuint num = 0; do { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 0d8f14dc..b8057fa1 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -226,6 +226,8 @@ void *GetSymbol(void *handle, const char *name); #endif +typedef void *volatile XchgPtr; + #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) typedef ALuint RefCount; static __inline RefCount IncrementRef(volatile RefCount *ptr) @@ -237,7 +239,7 @@ static __inline int ExchangeInt(volatile int *ptr, int newval) { return __sync_lock_test_and_set(ptr, newval); } -static __inline void *ExchangePtr(void *volatile*ptr, void *newval) +static __inline void *ExchangePtr(XchgPtr *ptr, void *newval) { return __sync_lock_test_and_set(ptr, newval); } @@ -245,7 +247,7 @@ static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int new { return __sync_bool_compare_and_swap(ptr, oldval, newval); } -static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval) +static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval) { return __sync_bool_compare_and_swap(ptr, oldval, newval); } @@ -288,7 +290,7 @@ static __inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int ne return ret == oldval; } -static __inline void *ExchangePtr(void *volatile*dest, void *newval) +static __inline void *ExchangePtr(XchgPtr *dest, void *newval) { void *ret; __asm__ __volatile__( @@ -304,7 +306,7 @@ static __inline void *ExchangePtr(void *volatile*dest, void *newval) return ret; } -static __inline ALboolean CompExchangePtr(void *volatile*dest, void *oldval, void *newval) +static __inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval) { void *ret; __asm__ __volatile__( @@ -338,7 +340,7 @@ static __inline int ExchangeInt(volatile int *ptr, int newval) } u = { ptr }; return InterlockedExchange(u.l, newval); } -static __inline void *ExchangePtr(void *volatile*ptr, void *newval) +static __inline void *ExchangePtr(XchgPtr *ptr, void *newval) { return InterlockedExchangePointer(ptr, newval); } @@ -350,7 +352,7 @@ static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int new } u = { ptr }; return InterlockedCompareExchange(u.l, newval, oldval) == oldval; } -static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval) +static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval) { return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval; } @@ -374,7 +376,7 @@ static __inline int ExchangeInt(volatile int *ptr, int newval) } while(!OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr)); return oldval; } -static __inline void *ExchangePtr(void *volatile*ptr, void *newval) +static __inline void *ExchangePtr(XchgPtr *ptr, void *newval) { void *oldval; do { @@ -386,7 +388,7 @@ static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int new { return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr); } -static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval) +static __inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval) { return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr); } diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index c8a12d33..03a6218b 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -570,7 +570,7 @@ static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, AL alSetError(Context, AL_OUT_OF_MEMORY); return; } - State = ExchangePtr((void**)&EffectSlot->EffectState, State); + State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State); if(!effect) memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 7d0aa978..982da4c4 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -583,7 +583,7 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) // Increment reference counter for buffer IncrementRef(&buffer->ref); - oldlist = ExchangePtr((void**)&Source->queue, BufferListItem); + oldlist = ExchangePtr((XchgPtr*)&Source->queue, BufferListItem); Source->BuffersInQueue = 1; ReadLock(&buffer->lock); @@ -600,7 +600,7 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) { // Source is now in UNDETERMINED mode Source->lSourceType = AL_UNDETERMINED; - oldlist = ExchangePtr((void**)&Source->queue, NULL); + oldlist = ExchangePtr((XchgPtr*)&Source->queue, NULL); } // Delete all previous elements in the queue @@ -780,7 +780,7 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum eParam, ALint lValue1, /* Release refcount on the previous slot, and add one for * the new slot */ if(ALEffectSlot) IncrementRef(&ALEffectSlot->ref); - ALEffectSlot = ExchangePtr((void**)&Source->Send[lValue2].Slot, ALEffectSlot); + ALEffectSlot = ExchangePtr((XchgPtr*)&Source->Send[lValue2].Slot, ALEffectSlot); if(ALEffectSlot) DecrementRef(&ALEffectSlot->ref); if(!ALFilter) -- cgit v1.2.3