24 #include <seastar/util/modules.hh>
26 #ifndef SEASTAR_MODULE
30 #if defined(__x86_64__) || defined(__i386__)
31 #include <xmmintrin.h>
38 #if defined(__x86_64__) || defined(__i386__)
45 [[gnu::always_inline]]
46 inline void cpu_relax() {
50 #elif defined(__PPC__)
52 [[gnu::always_inline]]
53 inline void cpu_relax() {
54 __asm__
volatile(
"yield");
57 #elif defined(__s390x__) || defined(__zarch__)
60 [[gnu::always_inline]]
61 inline void cpu_relax() {}
63 #elif defined(__aarch64__)
65 [[gnu::always_inline]]
66 inline void cpu_relax() {
67 __asm__
volatile(
"yield");
72 [[gnu::always_inline]]
73 inline void cpu_relax() {}
74 #warn "Using an empty cpu_relax() for this architecture"
89 std::atomic<bool> _busy = {
false };
93 ~
spinlock() { assert(!_busy.load(std::memory_order_relaxed)); }
94 bool try_lock() noexcept {
95 return !_busy.exchange(
true, std::memory_order_acquire);
97 void lock() noexcept {
98 while (_busy.exchange(
true, std::memory_order_acquire)) {
99 internal::cpu_relax();
102 void unlock() noexcept {
103 _busy.store(
false, std::memory_order_release);
Definition: spinlock.hh:88
Seastar API namespace.
Definition: abort_on_ebadf.hh:26