summaryrefslogtreecommitdiffstats
path: root/lib/frratomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/frratomic.h')
-rw-r--r--lib/frratomic.h105
1 files changed, 65 insertions, 40 deletions
diff --git a/lib/frratomic.h b/lib/frratomic.h
index 183790aeb..4ae84c401 100644
--- a/lib/frratomic.h
+++ b/lib/frratomic.h
@@ -47,7 +47,8 @@
#define atomic_fetch_add_explicit __atomic_fetch_add
#define atomic_fetch_sub_explicit __atomic_fetch_sub
-#define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1, mem2) \
+#define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1, \
+ mem2) \
__atomic_compare_exchange_n(atom, expect, desire, 1, mem1, mem2)
/* gcc 4.1 and newer,
@@ -55,7 +56,7 @@
*
* __sync_swap isn't in gcc's documentation, but clang has it
*
- * note __sync_synchronize()
+ * note __sync_synchronize()
*/
#elif defined(HAVE___SYNC)
@@ -68,48 +69,72 @@
#define memory_order_acq_rel 0
#define memory_order_seq_cst 0
-#define atomic_load_explicit(ptr, mem) \
- ({ __sync_synchronize(); \
- typeof(*ptr) rval = __sync_fetch_and_add((ptr), 0); \
- __sync_synchronize(); rval; })
-#define atomic_store_explicit(ptr, val, mem) \
- ({ __sync_synchronize(); \
- *(ptr) = (val); \
- __sync_synchronize(); (void)0; })
+#define atomic_load_explicit(ptr, mem) \
+ ({ \
+ __sync_synchronize(); \
+ typeof(*ptr) rval = __sync_fetch_and_add((ptr), 0); \
+ __sync_synchronize(); \
+ rval; \
+ })
+#define atomic_store_explicit(ptr, val, mem) \
+ ({ \
+ __sync_synchronize(); \
+ *(ptr) = (val); \
+ __sync_synchronize(); \
+ (void)0; \
+ })
#ifdef HAVE___SYNC_SWAP
-#define atomic_exchange_explicit(ptr, val, mem) \
- ({ __sync_synchronize(); \
- typeof(*ptr) rval = __sync_swap((ptr, val), 0); \
- __sync_synchronize(); rval; })
+#define atomic_exchange_explicit(ptr, val, mem) \
+ ({ \
+ __sync_synchronize(); \
+ typeof(*ptr) rval = __sync_swap((ptr, val), 0); \
+ __sync_synchronize(); \
+ rval; \
+ })
#else /* !HAVE___SYNC_SWAP */
-#define atomic_exchange_explicit(ptr, val, mem) \
- ({ typeof(ptr) _ptr = (ptr); typeof(val) _val = (val); \
- __sync_synchronize(); \
- typeof(*ptr) old1, old2 = __sync_fetch_and_add(_ptr, 0); \
- do { \
- old1 = old2; \
- old2 = __sync_val_compare_and_swap (_ptr, old1, _val); \
- } while (old1 != old2); \
- __sync_synchronize(); \
- old2; \
+#define atomic_exchange_explicit(ptr, val, mem) \
+ ({ \
+ typeof(ptr) _ptr = (ptr); \
+ typeof(val) _val = (val); \
+ __sync_synchronize(); \
+ typeof(*ptr) old1, old2 = __sync_fetch_and_add(_ptr, 0); \
+ do { \
+ old1 = old2; \
+ old2 = __sync_val_compare_and_swap(_ptr, old1, _val); \
+ } while (old1 != old2); \
+ __sync_synchronize(); \
+ old2; \
})
#endif /* !HAVE___SYNC_SWAP */
-#define atomic_fetch_add_explicit(ptr, val, mem) \
- ({ __sync_synchronize(); \
- typeof(*ptr) rval = __sync_fetch_and_add((ptr), (val)); \
- __sync_synchronize(); rval; })
-#define atomic_fetch_sub_explicit(ptr, val, mem) \
- ({ __sync_synchronize(); \
- typeof(*ptr) rval = __sync_fetch_and_sub((ptr), (val)); \
- __sync_synchronize(); rval; })
-
-#define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1, mem2) \
- ({ typeof(atom) _atom = (atom); typeof(expect) _expect = (expect); \
- typeof(desire) _desire = (desire); \
- __sync_synchronize(); \
- typeof(*atom) rval = __sync_val_compare_and_swap(_atom, *_expect, _desire); \
- __sync_synchronize(); \
- bool ret = (rval == *_expect); *_expect = rval; ret; })
+#define atomic_fetch_add_explicit(ptr, val, mem) \
+ ({ \
+ __sync_synchronize(); \
+ typeof(*ptr) rval = __sync_fetch_and_add((ptr), (val)); \
+ __sync_synchronize(); \
+ rval; \
+ })
+#define atomic_fetch_sub_explicit(ptr, val, mem) \
+ ({ \
+ __sync_synchronize(); \
+ typeof(*ptr) rval = __sync_fetch_and_sub((ptr), (val)); \
+ __sync_synchronize(); \
+ rval; \
+ })
+
+#define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1, \
+ mem2) \
+ ({ \
+ typeof(atom) _atom = (atom); \
+ typeof(expect) _expect = (expect); \
+ typeof(desire) _desire = (desire); \
+ __sync_synchronize(); \
+ typeof(*atom) rval = \
+ __sync_val_compare_and_swap(_atom, *_expect, _desire); \
+ __sync_synchronize(); \
+ bool ret = (rval == *_expect); \
+ *_expect = rval; \
+ ret; \
+ })
#else /* !HAVE___ATOMIC && !HAVE_STDATOMIC_H */
#error no atomic functions...