aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/atomic.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-03-09 03:49:40 -0700
committerChris Robinson <[email protected]>2014-03-09 03:49:40 -0700
commit308d87b12aa2b8018be9023c89ad09fcf01d99d1 (patch)
tree18db474b86f611e38f4b2a70d34186c3f04ae23f /Alc/atomic.h
parent372f3178f8cf1d297d88a3c39a5e2b3c78903e86 (diff)
Return the original value from CompExchange*
Diffstat (limited to 'Alc/atomic.h')
-rw-r--r--Alc/atomic.h41
1 files changed, 19 insertions, 22 deletions
diff --git a/Alc/atomic.h b/Alc/atomic.h
index 83985037..3bd5e6af 100644
--- a/Alc/atomic.h
+++ b/Alc/atomic.h
@@ -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