1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef ATOMIC_H
30 #define ATOMIC_H
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #ifdef __gnu_linux__
37
38 #define ws_atomic_inc32(intptr) __sync_fetch_and_add(intptr,
1)
39 #define ws_atomic_dec32(intptr) __sync_fetch_and_sub(intptr,
1) -
1
40 #define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val)
41 #define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, val)
42
43 #elif defined(
OSX)
44 #include <libkern/OSAtomic.h>
45
46 #define ws_atomic_inc32(intptr) OSAtomicIncrement32((
volatile int32_t *)intptr)
47 #define ws_atomic_dec32(intptr) OSAtomicDecrement32((
volatile int32_t *)intptr)
48
49 #elif defined(
BSD)
50 #define ws_atomic_inc32(intptr) __sync_fetch_and_add(intptr,
1)
51 #define ws_atomic_dec32(intptr) __sync_fetch_and_sub(intptr,
1) -
1
52 #define ws_atomic_add32(intptr, val) __sync_fetch_and_add(intptr, val)
53 #define ws_atomic_sub32(intptr, val) __sync_fetch_and_sub(intptr, va
54 #else
55
56 #include <atomic.h>
57
58 #define ws_atomic_inc32(intptr) atomic_inc_32_nv(intptr)
59 #define ws_atomic_dec32(intptr) atomic_dec_32_nv(intptr)
60
61
62 #endif
63
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69 #endif
70
71