Skip to content

Commit

Permalink
atomic: Add a spin_loop() hint
Browse files Browse the repository at this point in the history
  • Loading branch information
tavianator committed May 15, 2024
1 parent 41c2f7a commit c964524
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef BFS_ATOMIC_H
#define BFS_ATOMIC_H

#include "prelude.h"
#include "sanity.h"
#include <stdatomic.h>

Expand Down Expand Up @@ -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

0 comments on commit c964524

Please sign in to comment.