commit f95cf6ad70565ee2322cf23bc519b7bb0b3831b2
|
|
Author: Olivier Houchard <ohouchard@haproxy.com>
|
|
Date: Tue Apr 30 13:38:02 2019 +0200
|
|
|
|
MINOR: threads: Implement HA_ATOMIC_LOAD().
|
|
|
|
The same way we have HA_ATOMIC_STORE(), implement HA_ATOMIC_LOAD().
|
|
|
|
This should be backported to 1.8 and 1.9, as we need it for a bug fix
|
|
in port ranges.
|
|
|
|
(cherry picked from commit 9ce62b5498b27fbf4217d9c25779d5b2ceca23f2)
|
|
Signed-off-by: Olivier Houchard <cognet@ci0.org>
|
|
(cherry picked from commit 358c979611370fa2bc3b8e47ed50a325cf9126cf)
|
|
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
|
|
|
|
diff --git a/include/common/hathreads.h b/include/common/hathreads.h
|
|
index 8134839a..11d7cab6 100644
|
|
--- a/include/common/hathreads.h
|
|
+++ b/include/common/hathreads.h
|
|
@@ -62,6 +62,7 @@ enum { tid = 0 };
|
|
*(val) = new; \
|
|
__old_xchg; \
|
|
})
|
|
+#define HA_ATOMIC_LOAD(val) *(val)
|
|
#define HA_ATOMIC_STORE(val, new) ({*(val) = new;})
|
|
#define HA_ATOMIC_UPDATE_MAX(val, new) \
|
|
({ \
|
|
@@ -203,6 +204,16 @@ static inline unsigned long thread_isolated()
|
|
} while (!__sync_bool_compare_and_swap(__val_xchg, __old_xchg, __new_xchg)); \
|
|
__old_xchg; \
|
|
})
|
|
+
|
|
+#define HA_ATOMIC_LOAD(val) \
|
|
+ ({ \
|
|
+ typeof(*(val)) ret; \
|
|
+ __sync_synchronize(); \
|
|
+ ret = *(volatile typeof(val))val; \
|
|
+ __sync_synchronize(); \
|
|
+ ret; \
|
|
+ })
|
|
+
|
|
#define HA_ATOMIC_STORE(val, new) \
|
|
({ \
|
|
typeof((val)) __val_store = (val); \
|
|
@@ -221,6 +232,8 @@ static inline unsigned long thread_isolated()
|
|
#define HA_ATOMIC_OR(val, flags) __atomic_or_fetch(val, flags, __ATOMIC_SEQ_CST)
|
|
#define HA_ATOMIC_XCHG(val, new) __atomic_exchange_n(val, new, __ATOMIC_SEQ_CST)
|
|
#define HA_ATOMIC_STORE(val, new) __atomic_store_n(val, new, __ATOMIC_SEQ_CST)
|
|
+#define HA_ATOMIC_LOAD(val) __atomic_load_n(val, __ATOMIC_SEQ_CST)
|
|
+
|
|
#endif
|
|
|
|
#define HA_ATOMIC_UPDATE_MAX(val, new) \
|