libmooshika
atomics.h
Go to the documentation of this file.
1 #undef GCC_SYNC_FUNCTIONS
2 #undef GCC_ATOMIC_FUNCTIONS
3 
4 #ifndef __GNUC__
5 #error Please edit abstract_atomic.h and implement support for \
6  non-GNU compilers.
7 #else /* __GNUC__ */
8 #define ATOMIC_GCC_VERSION (__GNUC__ * 10000 \
9  + __GNUC_MINOR__ * 100 \
10  + __GNUC_PATCHLEVEL__)
11 
12 #if ((ATOMIC_GCC_VERSION) >= 40700)
13 #define GCC_ATOMIC_FUNCTIONS 1
14 #elif ((ATOMIC_GCC_VERSION) >= 40100)
15 #define GCC_SYNC_FUNCTIONS 1
16 #else
17 #error This verison of GCC does not support atomics.
18 #endif /* Version check */
19 #endif /* __GNUC__ */
20 
21 
22 #define atomic_postinc(x) __sync_fetch_and_add(&x, 1)
23 #define atomic_postdec(x) __sync_fetch_and_sub(&x, 1)
24 #define atomic_postadd(x,i) __sync_fetch_and_add(&x, i)
25 #define atomic_postsub(x,i) __sync_fetch_and_sub(&x, i)
26 #define atomic_postmask(x,i) __sync_fetch_and_and(&x, i)
27 #define atomic_inc(x) __sync_add_and_fetch(&x, 1)
28 #define atomic_dec(x) __sync_sub_and_fetch(&x, 1)
29 #define atomic_add(x,i) __sync_add_and_fetch(&x, i)
30 #define atomic_sub(x,i) __sync_sub_and_fetch(&x, i)
31 #define atomic_mask(x,i) __sync_and_and_fetch(&x, i)
32 #define atomic_bool_compare_and_swap __sync_bool_compare_and_swap
33 
34 #ifdef GCC_ATOMIC_FUNCTIONS
35 #define atomic_store(x, n) __atomic_store_n(x, n, __ATOMIC_RELEASE)
36 #elif defined(GCC_SYNC_FUNCTIONS)
37 #define atomic_store(x, n) do { *(x) = n; __sync_synchronize(); } while (0)
38 #endif