Return the original value from CompExchange*
This commit is contained in:
@@ -2187,14 +2187,14 @@ static void ReleaseContext(ALCcontext *context, ALCdevice *device)
|
||||
ALCcontext_DecRef(context);
|
||||
}
|
||||
|
||||
if(CompExchangePtr((XchgPtr*)&GlobalContext, context, NULL))
|
||||
if(CompExchangePtr((XchgPtr*)&GlobalContext, context, NULL) == context)
|
||||
ALCcontext_DecRef(context);
|
||||
|
||||
ALCdevice_Lock(device);
|
||||
tmp_ctx = &device->ContextList;
|
||||
while(*tmp_ctx)
|
||||
{
|
||||
if(CompExchangePtr((XchgPtr*)tmp_ctx, context, context->next))
|
||||
if(CompExchangePtr((XchgPtr*)tmp_ctx, context, context->next) == context)
|
||||
break;
|
||||
tmp_ctx = &(*tmp_ctx)->next;
|
||||
}
|
||||
@@ -2903,7 +2903,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
|
||||
|
||||
do {
|
||||
ALContext->next = device->ContextList;
|
||||
} while(!CompExchangePtr((XchgPtr*)&device->ContextList, ALContext->next, ALContext));
|
||||
} while(CompExchangePtr((XchgPtr*)&device->ContextList, ALContext->next, ALContext) != ALContext->next);
|
||||
UnlockLists();
|
||||
|
||||
ALCdevice_DecRef(device);
|
||||
@@ -3284,7 +3284,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
|
||||
do {
|
||||
device->next = DeviceList;
|
||||
} while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
|
||||
} while(CompExchangePtr((XchgPtr*)&DeviceList, device->next, device) != device->next);
|
||||
|
||||
TRACE("Created device %p, \"%s\"\n", device, device->DeviceName);
|
||||
return device;
|
||||
@@ -3415,7 +3415,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
|
||||
|
||||
do {
|
||||
device->next = DeviceList;
|
||||
} while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
|
||||
} while(CompExchangePtr((XchgPtr*)&DeviceList, device->next, device) != device->next);
|
||||
|
||||
TRACE("Created device %p, \"%s\"\n", device, device->DeviceName);
|
||||
return device;
|
||||
@@ -3598,7 +3598,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
|
||||
V(device->Backend,open)("Loopback");
|
||||
do {
|
||||
device->next = DeviceList;
|
||||
} while(!CompExchangePtr((XchgPtr*)&DeviceList, device->next, device));
|
||||
} while(CompExchangePtr((XchgPtr*)&DeviceList, device->next, device) != device->next);
|
||||
|
||||
TRACE("Created device %p\n", device);
|
||||
return device;
|
||||
|
||||
+19
-22
@@ -19,13 +19,13 @@ inline void *ExchangePtr(XchgPtr *ptr, void *newval)
|
||||
{
|
||||
return __sync_lock_test_and_set(ptr, newval);
|
||||
}
|
||||
inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
|
||||
inline int CompExchangeInt(volatile int *ptr, int oldval, int newval)
|
||||
{
|
||||
return __sync_bool_compare_and_swap(ptr, oldval, newval);
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
}
|
||||
inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
|
||||
inline void *CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
|
||||
{
|
||||
return __sync_bool_compare_and_swap(ptr, oldval, newval);
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
}
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
@@ -55,17 +55,6 @@ inline int ExchangeInt(volatile int *dest, int newval)
|
||||
: "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline ALboolean CompExchangeInt(volatile int *dest, int oldval, int newval)
|
||||
{
|
||||
int ret;
|
||||
__asm__ __volatile__("lock; cmpxchgl %2,(%1)"
|
||||
: "=a" (ret)
|
||||
: "r" (dest), "r" (newval), "0" (oldval)
|
||||
: "memory");
|
||||
return ret == oldval;
|
||||
}
|
||||
|
||||
inline void *ExchangePtr(XchgPtr *dest, void *newval)
|
||||
{
|
||||
void *ret;
|
||||
@@ -81,8 +70,16 @@ inline void *ExchangePtr(XchgPtr *dest, void *newval)
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
|
||||
inline int CompExchangeInt(volatile int *dest, int oldval, int newval)
|
||||
{
|
||||
int ret;
|
||||
__asm__ __volatile__("lock; cmpxchgl %2,(%1)"
|
||||
: "=a" (ret)
|
||||
: "r" (dest), "r" (newval), "0" (oldval)
|
||||
: "memory");
|
||||
return ret;
|
||||
}
|
||||
inline void *CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
|
||||
{
|
||||
void *ret;
|
||||
__asm__ __volatile__(
|
||||
@@ -95,7 +92,7 @@ inline ALboolean CompExchangePtr(XchgPtr *dest, void *oldval, void *newval)
|
||||
: "r" (dest), "r" (newval), "0" (oldval)
|
||||
: "memory"
|
||||
);
|
||||
return ret == oldval;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
@@ -123,17 +120,17 @@ inline void *ExchangePtr(XchgPtr *ptr, void *newval)
|
||||
{
|
||||
return InterlockedExchangePointer(ptr, newval);
|
||||
}
|
||||
inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval)
|
||||
inline int CompExchangeInt(volatile int *ptr, int oldval, int newval)
|
||||
{
|
||||
union {
|
||||
volatile int *i;
|
||||
volatile LONG *l;
|
||||
} u = { ptr };
|
||||
return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
|
||||
return InterlockedCompareExchange(u.l, newval, oldval);
|
||||
}
|
||||
inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
|
||||
inline void *CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval)
|
||||
{
|
||||
return InterlockedCompareExchangePointer(ptr, newval, oldval) == oldval;
|
||||
return InterlockedCompareExchangePointer(ptr, newval, oldval);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
+2
-2
@@ -93,8 +93,8 @@ extern inline RefCount IncrementRef(volatile RefCount *ptr);
|
||||
extern inline RefCount DecrementRef(volatile RefCount *ptr);
|
||||
extern inline int ExchangeInt(volatile int *ptr, int newval);
|
||||
extern inline void *ExchangePtr(XchgPtr *ptr, void *newval);
|
||||
extern inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int newval);
|
||||
extern inline ALboolean CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval);
|
||||
extern inline int CompExchangeInt(volatile int *ptr, int oldval, int newval);
|
||||
extern inline void *CompExchangePtr(XchgPtr *ptr, void *oldval, void *newval);
|
||||
|
||||
extern inline void LockUIntMapRead(UIntMap *map);
|
||||
extern inline void UnlockUIntMapRead(UIntMap *map);
|
||||
|
||||
Reference in New Issue
Block a user