6 #if defined(EEGEO_IOS) || defined(EEGEO_OSX)
7 #include <libkern/OSAtomic.h>
9 #elif defined(EEGEO_WIN)
10 #include "EegeoWindowsGuard.h"
17 inline bool AtomicCompareAndSwap32(s32 oldValue, s32 newValue,
volatile s32* theValue)
19 #if defined(EEGEO_IOS)
20 return OSAtomicCompareAndSwap32Barrier((int32_t)oldValue, (int32_t)newValue, (
volatile int32_t*)theValue);
21 #elif defined(EEGEO_OSX)
22 return std::atomic_compare_exchange_strong((
volatile std::atomic<int32_t>*)theValue, (int32_t*)&oldValue, (int32_t)newValue);
23 #elif defined EEGEO_DROID || defined(EMSCRIPTEN)
24 return __sync_bool_compare_and_swap(theValue, oldValue, newValue);
25 #elif defined EEGEO_WIN
26 return InterlockedCompareExchange((
volatile long*)theValue, (
long)newValue, (
long)oldValue) == oldValue;
30 inline s32 AtomicIncrement32(
volatile s32* theValue)
33 #if defined(EEGEO_IOS)
34 return OSAtomicIncrement32Barrier((
volatile int32_t*)theValue);
35 #elif defined(EEGEO_OSX)
36 return std::atomic_fetch_add((
volatile std::atomic<int32_t>*)theValue, (int32_t)1);
37 #elif defined EEGEO_DROID || defined(EMSCRIPTEN)
38 return __sync_fetch_and_add(theValue, (s32)1);
39 #elif defined EEGEO_WIN
40 return InterlockedIncrement((LONG
volatile *)theValue);
44 inline s64 AtomicIncrement64(
volatile s64* theValue)
46 #if defined(EEGEO_WIN)
47 return (uint64_t)InterlockedIncrement64(theValue);
48 #elif defined(EEGEO_IOS)
49 return(uint64_t)OSAtomicIncrement64(theValue);
50 #elif defined(EEGEO_OSX)
51 return (uint64_t)std::atomic_fetch_add((
volatile std::atomic<uint64_t>*)theValue, (uint64_t)1);
53 return __sync_fetch_and_add(theValue, 1);
57 inline s32 AtomicDecrement32(
volatile s32* theValue)
60 #if defined(EEGEO_IOS)
61 return OSAtomicDecrement32Barrier((
volatile int32_t*)theValue);
62 #elif defined(EEGEO_OSX)
63 return std::atomic_fetch_sub((
volatile std::atomic<int32_t>*)theValue, (int32_t)1);
64 #elif defined EEGEO_DROID || defined(EMSCRIPTEN)
65 return __sync_fetch_and_sub(theValue, (s32)1);
66 #elif defined EEGEO_WIN
67 return InterlockedDecrement((LONG
volatile *)theValue);