1 #ifndef MY_ATOMIC_INCLUDED
2 #define MY_ATOMIC_INCLUDED
57 #ifndef my_atomic_rwlock_init
64 #undef MY_ATOMIC_HAS_8_16
66 #ifndef MY_ATOMIC_MODE_RWLOCKS
70 #include "atomic/nolock.h"
73 #ifndef make_atomic_cas_body
75 #include "atomic/rwlock.h"
79 #ifndef make_atomic_add_body
80 #define make_atomic_add_body(S) \
82 while (!my_atomic_cas ## S(a, &tmp, tmp+v)) ; \
85 #ifndef make_atomic_fas_body
86 #define make_atomic_fas_body(S) \
88 while (!my_atomic_cas ## S(a, &tmp, v)) ; \
91 #ifndef make_atomic_load_body
92 #define make_atomic_load_body(S) \
94 (void)(my_atomic_cas ## S(a, &ret, ret));
96 #ifndef make_atomic_store_body
97 #define make_atomic_store_body(S) \
98 (void)(my_atomic_fas ## S (a, v));
109 #if defined(__GNUC__) && !defined(__cplusplus) && \
110 ! (defined(__APPLE__) && (defined(_ARCH_PPC64) ||defined (_ARCH_PPC)))
120 #define make_transparent_unions(S) \
124 } U_ ## S __attribute__ ((transparent_union)); \
126 int ## S volatile *i; \
127 uint ## S volatile *u; \
128 } Uv_ ## S __attribute__ ((transparent_union));
129 #define uintptr intptr
130 make_transparent_unions(8)
131 make_transparent_unions(16)
132 make_transparent_unions(32)
133 make_transparent_unions(64)
134 make_transparent_unions(ptr)
136 #undef make_transparent_unions
151 #define Uv_ptr intptr
152 #define U_a volatile *a
158 #define make_atomic_cas(S) \
159 static inline int my_atomic_cas ## S(Uv_ ## S U_a, \
160 Uv_ ## S U_cmp, U_ ## S U_set) \
163 make_atomic_cas_body(S); \
167 #define make_atomic_add(S) \
168 static inline int ## S my_atomic_add ## S( \
169 Uv_ ## S U_a, U_ ## S U_v) \
171 make_atomic_add_body(S); \
175 #define make_atomic_fas(S) \
176 static inline int ## S my_atomic_fas ## S( \
177 Uv_ ## S U_a, U_ ## S U_v) \
179 make_atomic_fas_body(S); \
183 #define make_atomic_load(S) \
184 static inline int ## S my_atomic_load ## S(Uv_ ## S U_a) \
187 make_atomic_load_body(S); \
191 #define make_atomic_store(S) \
192 static inline void my_atomic_store ## S( \
193 Uv_ ## S U_a, U_ ## S U_v) \
195 make_atomic_store_body(S); \
198 #ifdef MY_ATOMIC_HAS_8_16
206 #ifdef MY_ATOMIC_HAS_8_16
213 #ifdef MY_ATOMIC_HAS_8_16
219 make_atomic_load(ptr)
221 #ifdef MY_ATOMIC_HAS_8_16
229 #ifdef MY_ATOMIC_HAS_8_16
231 make_atomic_store(16)
233 make_atomic_store(32)
234 make_atomic_store(64)
235 make_atomic_store(ptr)
237 #ifdef _atomic_h_cleanup_
238 #include _atomic_h_cleanup_
239 #undef _atomic_h_cleanup_
260 #undef make_atomic_add
261 #undef make_atomic_cas
262 #undef make_atomic_load
263 #undef make_atomic_store
264 #undef make_atomic_fas
265 #undef make_atomic_add_body
266 #undef make_atomic_cas_body
267 #undef make_atomic_load_body
268 #undef make_atomic_store_body
269 #undef make_atomic_fas_body
278 #define LF_BACKOFF (1)
281 #define MY_ATOMIC_OK 0
282 #define MY_ATOMIC_NOT_1CPU 1
284 extern int my_atomic_initialize();