diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-05-15 11:08:00 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-05-15 12:39:02 -0400 |
commit | c964524f18fc5c3b7baf5a3d0eac0980f17d3cf0 (patch) | |
tree | b3975cd85b4375add88ff005538bd578d9dc16f3 /src/atomic.h | |
parent | 41c2f7a68bf41b0114a640a039bd8bf411988d23 (diff) | |
download | bfs-c964524f18fc5c3b7baf5a3d0eac0980f17d3cf0.tar.xz |
atomic: Add a spin_loop() hint
Diffstat (limited to 'src/atomic.h')
-rw-r--r-- | src/atomic.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/atomic.h b/src/atomic.h index 7d32e73..360de20 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -8,6 +8,7 @@ #ifndef BFS_ATOMIC_H #define BFS_ATOMIC_H +#include "prelude.h" #include "sanity.h" #include <stdatomic.h> @@ -101,4 +102,17 @@ #define signal_fence(order) \ atomic_signal_fence(memory_order_##order) +/** + * A hint to the CPU to relax while it spins. + */ +#if __has_builtin(__builtin_ia32_pause) +# define spin_loop() __builtin_ia32_pause() +#elif __has_builtin(__builtin_arm_yield) +# define spin_loop() __builtin_arm_yield() +#elif __has_builtin(__builtin_riscv_pause) +# define spin_loop() __builtin_riscv_pause() +#else +# define spin_loop() ((void)0) +#endif + #endif // BFS_ATOMIC_H |