]> git.lttng.org Git - urcu.git/commitdiff
arm: Use atomic builtins for xchg if supported
authorOlivier Dion <odion@efficios.com>
Mon, 2 Dec 2024 15:22:01 +0000 (10:22 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 2 Dec 2024 18:18:09 +0000 (13:18 -0500)
If the toolchain supports the C11 memory model, then implement
`uatomic_xchg_mo' with `__atomic_exchange_n' instead of
`__sync_lock_test_and_set'.  This reduces the number of memory barriers
except for the default memory order FULL_FENCE.

Change-Id: I2261f93134071e37e152a23bb78b21332844429b
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/urcu/uatomic/arm.h

index 69233719b79b19e09069d4b2143d5c55404b254b..d2ceb714b540e776d1c7dd4d70729f5b75471b31 100644 (file)
@@ -25,6 +25,25 @@ extern "C" {
 #endif
 
 /* xchg */
+
+/*
+ * If the toolchain supports the C11 memory model, then it is safe to implement
+ * `uatomic_xchg()' in term of __atomic builtins.  This has the effect of
+ * reducing the number of emitted memory barriers except for the
+ * CMM_SEQ_CST_FENCE memory order.
+ */
+#ifdef _CMM_TOOLCHAIN_SUPPORT_C11_MM
+#  define uatomic_xchg_mo(addr, v, mo)                                 \
+       __extension__                                                   \
+       ({                                                              \
+               __typeof__((*addr)) _old =                              \
+                       __atomic_exchange_n(cmm_cast_volatile(addr), v, \
+                                       cmm_to_c11(mo));                \
+               cmm_seq_cst_fence_after_atomic(mo);                     \
+               _old;                                                   \
+       })
+#else
+
 static inline void _cmm_compat_c11_smp_mb__before_xchg_mo(enum cmm_memorder mo)
 {
        switch (mo) {
@@ -51,11 +70,12 @@ static inline void _cmm_compat_c11_smp_mb__before_xchg_mo(enum cmm_memorder mo)
  *
  * [1] https://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
  */
-#define uatomic_xchg_mo(addr, v, mo)                           \
+#  define uatomic_xchg_mo(addr, v, mo)                         \
        ({                                                      \
                _cmm_compat_c11_smp_mb__before_xchg_mo(mo);     \
                __sync_lock_test_and_set(addr, v);              \
        })
+#endif /* _CMM_TOOLCHAIN_SUPPORT_C11_MM */
 
 #ifdef __cplusplus
 }
This page took 0.033673 seconds and 4 git commands to generate.