aboutsummaryrefslogtreecommitdiffstats
path: root/include/atomic.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-11-21 23:58:28 -0800
committerChris Robinson <[email protected]>2016-11-21 23:58:28 -0800
commit616adea4cc0629c7ce20a2c7e713342cadc26435 (patch)
treedf8151ebd9fc9a3779f7d47015eb61c06a46102f /include/atomic.h
parent8bf4fe2eea11afd753e25dd495c26e6522436b5f (diff)
Improve seqlock behavior
Diffstat (limited to 'include/atomic.h')
-rw-r--r--include/atomic.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/atomic.h b/include/atomic.h
index 1dcf9ec5..7d743286 100644
--- a/include/atomic.h
+++ b/include/atomic.h
@@ -42,6 +42,8 @@ extern "C" {
#define ATOMIC_COMPARE_EXCHANGE_WEAK(T, ...) \
PARAM5(atomic_compare_exchange_weak_explicit, __VA_ARGS__, memory_order_seq_cst, memory_order_seq_cst)
+#define ATOMIC_THREAD_FENCE atomic_thread_fence
+
/* Atomics using GCC intrinsics */
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined(__QNXNTO__)
@@ -83,6 +85,13 @@ enum almemory_order {
*(_oldval) == _o; \
})
+#define ATOMIC_THREAD_FENCE(order) do { \
+ enum { must_be_constant = (order) }; \
+ const int _o = must_be_constant; \
+ if(_o > almemory_order_relaxed) \
+ __asm__ __volatile__("" ::: "memory"); \
+} while(0)
+
/* Atomics using x86/x86-64 GCC inline assembly */
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
@@ -169,6 +178,13 @@ enum almemory_order {
*(_oldval) == _old; \
})
+#define ATOMIC_THREAD_FENCE(order) do { \
+ enum { must_be_constant = (order) }; \
+ const int _o = must_be_constant; \
+ if(_o > almemory_order_relaxed) \
+ __asm__ __volatile__("" ::: "memory"); \
+} while(0)
+
/* Atomics using Windows methods */
#elif defined(_WIN32)
@@ -268,6 +284,13 @@ int _al_invalid_atomic_size(); /* not defined */
(sizeof(T)==8) ? WRAP_CMPXCHG(T, CompareAndSwap64, &(_val)->value, (_newval), (_oldval)) : \
(bool)_al_invalid_atomic_size())
+#define ATOMIC_THREAD_FENCE(order) do { \
+ enum { must_be_constant = (order) }; \
+ const int _o = must_be_constant; \
+ if(_o > almemory_order_relaxed) \
+ _ReadWriteBarrier(); \
+} while(0)
+
#else
#error "No atomic functions available on this platform!"