From 41c2f7a68bf41b0114a640a039bd8bf411988d23 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 15 May 2024 11:07:03 -0400 Subject: atomic: Add atomic_{thread,signal}_fence() wrappers --- src/atomic.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 /** @@ -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 -- cgit v1.2.3