summaryrefslogtreecommitdiffstats
path: root/include/haproxy/atomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/haproxy/atomic.h')
-rw-r--r--include/haproxy/atomic.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/include/haproxy/atomic.h b/include/haproxy/atomic.h
index d64e192..146f2ad 100644
--- a/include/haproxy/atomic.h
+++ b/include/haproxy/atomic.h
@@ -185,6 +185,7 @@
#define __ha_barrier_full() do { } while (0)
#define __ha_compiler_barrier() do { } while (0)
#define __ha_cpu_relax() ({ 1; })
+#define __ha_cpu_relax_for_read() ({ 1; })
#else /* !USE_THREAD */
@@ -198,10 +199,11 @@
#define HA_ATOMIC_LOAD(val) \
({ \
- typeof(*(val)) ret = \
- ({ __sync_synchronize(); *(volatile typeof(val))val; }); \
+ typeof((val)) __val_load = (val); \
+ typeof(*(val)) __ret_val = \
+ ({ __sync_synchronize(); *(volatile typeof(__val_load))__val_load; }); \
__sync_synchronize(); \
- ret; \
+ __ret_val; \
})
#define HA_ATOMIC_STORE(val, new) \
@@ -586,6 +588,9 @@ __ha_cas_dw(void *target, void *compare, const void *set)
/* short-lived CPU relaxation */
#define __ha_cpu_relax() ({ asm volatile("rep;nop\n"); 1; })
+/* dummy relaxation: x86 prefers not to wait at all in read loops */
+#define __ha_cpu_relax_for_read() ({ 1; })
+
#elif defined(__arm__) && (defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__))
static __inline void
@@ -651,6 +656,9 @@ static __inline int __ha_cas_dw(void *target, void *compare, const void *set)
/* short-lived CPU relaxation */
#define __ha_cpu_relax() ({ asm volatile(""); 1; })
+/* short wait in read loops */
+#define __ha_cpu_relax_for_read() ({ asm volatile(""); 1; })
+
#elif defined (__aarch64__)
static __inline void
@@ -697,6 +705,9 @@ __ha_barrier_atomic_full(void)
*/
#define __ha_cpu_relax() ({ asm volatile("isb" ::: "memory"); 1; })
+/* aarch64 prefers to wait for real in read loops */
+#define __ha_cpu_relax_for_read() ({ asm volatile("isb" ::: "memory"); 1; })
+
#if defined(__ARM_FEATURE_ATOMICS) && !defined(__clang__) // ARMv8.1-A atomics
/* returns 0 on failure, non-zero on success */
@@ -799,6 +810,9 @@ static __inline int __ha_cas_dw(void *target, void *compare, void *set)
/* short-lived CPU relaxation */
#define __ha_cpu_relax() ({ asm volatile(""); 1; })
+/* default wait in read loops */
+#define __ha_cpu_relax_for_read() ({ asm volatile(""); 1; })
+
#endif /* end of arch-specific barrier/dwcas */
static inline void __ha_compiler_barrier(void)