]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: atomic: use the __atomic variant of BTS/BTR on modern compilers
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Apr 2021 12:04:22 +0000 (14:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 16:18:37 +0000 (18:18 +0200)
Probably due to the result of an old copy-paste, HA_ATOMIC_BTS/BTR were
still implemented using the __sync_*  builtins instead of the more
modern __atomic_* which allow to specify the memory model. Let's update
this to use the newer there and also implement the relaxed variants
(which are not used for now).

include/haproxy/atomic.h

index 722e918fb181897832813a89a9381dd6bf25e937..bb99e8db3e474009a30338d2587fa0983c4b0e1e 100644 (file)
 #define HA_ATOMIC_BTS(val, bit)                                                \
        ({                                                              \
                typeof(*(val)) __b_bts = (1UL << (bit));                \
-               __sync_fetch_and_or((val), __b_bts) & __b_bts;          \
+               __atomic_fetch_or((val), __b_bts, __ATOMIC_SEQ_CST) & __b_bts; \
        })
 
 #define HA_ATOMIC_BTR(val, bit)                                                \
        ({                                                              \
                typeof(*(val)) __b_btr = (1UL << (bit));                \
-               __sync_fetch_and_and((val), ~__b_btr) & __b_btr;        \
+               __atomic_fetch_and((val), ~__b_btr, __ATOMIC_SEQ_CST) & __b_btr; \
        })
 
 #define HA_ATOMIC_CAS(val, old, new) __atomic_compare_exchange_n(val, old, new, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
 #define _HA_ATOMIC_FETCH_ADD(val, i)     __atomic_fetch_add(val, i, __ATOMIC_RELAXED)
 #define _HA_ATOMIC_FETCH_SUB(val, i)     __atomic_fetch_sub(val, i, __ATOMIC_RELAXED)
 
+#define _HA_ATOMIC_BTS(val, bit)                                       \
+       ({                                                              \
+               typeof(*(val)) __b_bts = (1UL << (bit));                \
+               __atomic_fetch_or((val), __b_bts, __ATOMIC_RELAXED) & __b_bts; \
+       })
+
+#define _HA_ATOMIC_BTR(val, bit)                                       \
+       ({                                                              \
+               typeof(*(val)) __b_btr = (1UL << (bit));                \
+               __atomic_fetch_and((val), ~__b_btr, __ATOMIC_RELAXED) & __b_btr; \
+       })
+
 #define _HA_ATOMIC_CAS(val, old, new) __atomic_compare_exchange_n(val, old, new, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED)
 /* warning, n is a pointer to the double value for dwcas */
 #define _HA_ATOMIC_DWCAS(val, o, n)   __ha_cas_dw(val, o, n)
@@ -689,6 +701,14 @@ static inline void __ha_compiler_barrier(void)
 
 
 /* fallbacks to remap all undefined _HA_ATOMIC_* on to their safe equivalent */
+#ifndef _HA_ATOMIC_BTR
+#define _HA_ATOMIC_BTR HA_ATOMIC_BTR
+#endif /* !_HA_ATOMIC_BTR */
+
+#ifndef _HA_ATOMIC_BTS
+#define _HA_ATOMIC_BTS HA_ATOMIC_BTS
+#endif /* !_HA_ATOMIC_BTS */
+
 #ifndef _HA_ATOMIC_CAS
 #define _HA_ATOMIC_CAS HA_ATOMIC_CAS
 #endif /* !_HA_ATOMIC_CAS */