summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/atomic.h14
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