Added atomic workaround header.
[awesomized/libmemcached] / clients / ms_atomic.h
1 #ifndef CLIENTS_MS_ATOMIC_H
2 #define CLIENTS_MS_ATOMIC_H
3
4 #if defined(__SUNC)
5
6 #define _KERNEL
7 #include <atomic.h>
8 #undef _KERNEL
9
10 inline int32_t __sync_add_and_fetch(volatile int32_t* ptr, int32_t val)
11 {
12 (val == 1) ? atomic_inc_32((volatile uint32_t*)ptr) : atomic_add_32((volatile uint32_t*)ptr, val);
13 return *ptr;
14 }
15
16
17 inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val)
18 {
19 (val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val);
20 return *ptr;
21 }
22
23 #endif /* defined(__SUNC) */
24 #endif /* CLIENTS_MS_ATOMIC_H */