Commit 3fcef2fc authored by David Reid's avatar David Reid

Add atomic compare and swap.

parent fda0c076
...@@ -7499,6 +7499,9 @@ Atomics ...@@ -7499,6 +7499,9 @@ Atomics
#define ma_atomic_exchange_64(a, b) InterlockedExchange64((LONGLONG*)a, (LONGLONG)b) #define ma_atomic_exchange_64(a, b) InterlockedExchange64((LONGLONG*)a, (LONGLONG)b)
#define ma_atomic_increment_32(a) InterlockedIncrement((LONG*)a) #define ma_atomic_increment_32(a) InterlockedIncrement((LONG*)a)
#define ma_atomic_decrement_32(a) InterlockedDecrement((LONG*)a) #define ma_atomic_decrement_32(a) InterlockedDecrement((LONG*)a)
#define ma_compare_and_swap_32(d, e, c) _InterlockedCompareExchange((LONG*)d, (LONG)e, (LONG)c)
#define ma_compare_and_swap_64(d, e, c) _InterlockedCompareExchange64((LONGLONG*)d, (LONGLONG)e, (LONGLONG)c)
#define ma_compare_and_swap_ptr(d, e, c) _InterlockedCompareExchangePointer((void*volatile*)d, (void*)e, (void*)c)
#else #else
#define ma_memory_barrier() __sync_synchronize() #define ma_memory_barrier() __sync_synchronize()
#if defined(MA_HAS_SYNC_SWAP) #if defined(MA_HAS_SYNC_SWAP)
...@@ -7513,6 +7516,9 @@ Atomics ...@@ -7513,6 +7516,9 @@ Atomics
#endif #endif
#define ma_atomic_increment_32(a) __sync_add_and_fetch(a, 1) #define ma_atomic_increment_32(a) __sync_add_and_fetch(a, 1)
#define ma_atomic_decrement_32(a) __sync_sub_and_fetch(a, 1) #define ma_atomic_decrement_32(a) __sync_sub_and_fetch(a, 1)
#define ma_compare_and_swap_32(d, e, c) __sync_val_compare_and_swap(d, e, c)
#define ma_compare_and_swap_64(d, e, c) __sync_val_compare_and_swap(d, e, c)
#define ma_compare_and_swap_ptr(d, e, c) __sync_val_compare_and_swap(d, e, c)
#endif #endif
#ifdef MA_64BIT #ifdef MA_64BIT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment