summaryrefslogtreecommitdiffstats
path: root/src/atomic.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-05-15 11:07:03 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-05-15 12:39:02 -0400
commit41c2f7a68bf41b0114a640a039bd8bf411988d23 (patch)
treec3aae85a99ae9b0960a735210745c20ef6753854 /src/atomic.h
parent423cfa40efe859448b69fbbbce62a5be750bc9fd (diff)
downloadbfs-41c2f7a68bf41b0114a640a039bd8bf411988d23.tar.xz
atomic: Add atomic_{thread,signal}_fence() wrappers
Diffstat (limited to 'src/atomic.h')
-rw-r--r--src/atomic.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/atomic.h b/src/atomic.h
index f1a6bea..7d32e73 100644
--- a/src/atomic.h
+++ b/src/atomic.h
@@ -8,6 +8,7 @@
#ifndef BFS_ATOMIC_H
#define BFS_ATOMIC_H
+#include "sanity.h"
#include <stdatomic.h>
/**
@@ -82,4 +83,22 @@
#define fetch_and(obj, arg, order) \
atomic_fetch_and_explicit(obj, arg, memory_order_##order)
+/**
+ * Shorthand for atomic_thread_fence().
+ */
+#if SANITIZE_THREAD
+// TSan doesn't support fences: https://github.com/google/sanitizers/issues/1415
+# define thread_fence(obj, order) \
+ fetch_add(obj, 0, order)
+#else
+# define thread_fence(obj, order) \
+ atomic_thread_fence(memory_order_##order)
+#endif
+
+/**
+ * Shorthand for atomic_signal_fence().
+ */
+#define signal_fence(order) \
+ atomic_signal_fence(memory_order_##order)
+
#endif // BFS_ATOMIC_H