compat FEATURE new compare-exchange atomic macro
# define ATOMIC_ADD_RELAXED(var, x) atomic_fetch_add_explicit(&(var), x, memory_order_relaxed)
# define ATOMIC_DEC_RELAXED(var) atomic_fetch_sub_explicit(&(var), 1, memory_order_relaxed)
# define ATOMIC_SUB_RELAXED(var, x) atomic_fetch_sub_explicit(&(var), x, memory_order_relaxed)
+# define ATOMIC_COMPARE_EXCHANGE_RELAXED(var, exp, des, result) \
+ result = atomic_compare_exchange_strong_explicit(&(var), &(exp), des, memory_order_relaxed, memory_order_relaxed)
#else
# include <stdint.h>
# define ATOMIC_ADD_RELAXED(var, x) __sync_fetch_and_add(&(var), x)
# define ATOMIC_DEC_RELAXED(var) __sync_fetch_and_sub(&(var), 1)
# define ATOMIC_SUB_RELAXED(var, x) __sync_fetch_and_sub(&(var), x)
+# define ATOMIC_COMPARE_EXCHANGE_RELAXED(var, exp, des, result) \
+ { \
+ ATOMIC_T __old = __sync_val_compare_and_swap(&(var), exp, des); \
+ result = ATOMIC_LOAD_RELAXED(__old) == ATOMIC_LOAD_RELAXED(exp) ? 1 : 0; \
+ ATOMIC_STORE_RELAXED(exp, ATOMIC_LOAD_RELAXED(__old)); \
+ }
#endif
#ifndef HAVE_VDPRINTF
