7
atomic_inc - should return the value after increment
8
atomic_dec - should return the value after decrement
9
atomic_compswap - should return the value before the eventual swap
10
sync_barrier - creates a full hardware fence
15
inline unsigned atomic_inc(volatile unsigned *pValue)
17
return __sync_add_and_fetch(pValue, 1);
20
inline unsigned atomic_dec(volatile unsigned *pValue)
22
return __sync_add_and_fetch(pValue, -1);
25
inline unsigned atomic_compswap(volatile unsigned *pValue, unsigned comperand, unsigned value)
27
return __sync_val_compare_and_swap(pValue, comperand, value);
30
inline void sync_barrier()
35
#elif defined(_MSC_VER)
38
#define WIN32_LEAN_AND_MEAN
41
inline unsigned atomic_inc(volatile unsigned *pValue)
43
return _InterlockedIncrement((volatile long *)pValue);
46
inline unsigned atomic_dec(volatile unsigned *pValue)
48
return _InterlockedDecrement((volatile long *)pValue);
51
inline unsigned atomic_compswap(volatile unsigned *pValue, unsigned comperand, unsigned value)
53
return _InterlockedCompareExchange((volatile long *)pValue, (long)value, (long)comperand);
56
inline void sync_barrier()
61
#error missing atomic implementation for this compiler
64
#if defined(CONF_PLATFORM_MACOSX)
66
use semaphore provided by SDL on macosx
73
semaphore() { semaphore_init(&sem); }
74
~semaphore() { semaphore_destroy(&sem); }
75
void wait() { semaphore_wait(&sem); }
76
void signal() { semaphore_signal(&sem); }
82
friend class scope_lock;
86
void take() { lock_wait(var); }
87
void release() { lock_release(var); }