Add atomic compare and swap.

This commit is contained in:
David Reid
2020-05-30 13:25:02 +10:00
parent fda0c07626
commit 3fcef2fc7e
+6
View File
@@ -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
#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