Use a proper typedef for handling atomic pointer swaps

This commit is contained in:
Chris Robinson 2012-01-01 15:00:03 -08:00
parent 466cac328f
commit 886f874ff3
4 changed files with 20 additions and 18 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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));

View File

@ -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)