Merge branch 'master' of http://www-dev.cockos.com/wdl/WDL into updatewdl
[wdl/wdl-ol.git] / WDL / wdlatomic.h
blobcc2a181b2b13074ceaec921b7562fdefdc4f1140
1 #ifndef _WDL_ATOMIC_H_
2 #define _WDL_ATOMIC_H_
4 #ifdef _WIN32
6 static int wdl_atomic_incr(int *v) { return (int) InterlockedIncrement((LONG *)v); }
7 static int wdl_atomic_decr(int *v) { return (int) InterlockedDecrement((LONG *)v); }
9 #elif !defined(__ppc__) && (defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))))
11 static int wdl_atomic_incr(int *v) { return __sync_add_and_fetch(v,1); }
12 static int wdl_atomic_decr(int *v) { return __sync_add_and_fetch(v,~0); }
14 #elif defined(__APPLE__)
15 // used by GCC < 4.2 on OSX
16 #include <libkern/OSAtomic.h>
18 static int wdl_atomic_incr(int *v) { return (int) OSAtomicIncrement32Barrier((int32_t*)v); }
19 static int wdl_atomic_decr(int *v) { return (int) OSAtomicDecrement32Barrier((int32_t*)v); }
20 #else
22 // unsupported!
23 #pragma message("Need win32 or apple or gcc 4.2+ for wdlatomic.h, doh")
25 #endif
27 #endif