diff options
-rw-r--r-- | src/atomic.h | 19 |
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 |