18#ifndef RIPPLE_BASICS_SPINLOCK_H_INCLUDED
19#define RIPPLE_BASICS_SPINLOCK_H_INCLUDED
21#include <xrpl/beast/utility/instrumentation.h>
48 asm volatile(
"yield");
93 static_assert(std::is_unsigned_v<T>);
96 std::is_same_v<
decltype(std::declval<std::atomic<T>&>().fetch_or(0)), T> &&
98 "std::atomic<T>::fetch_and(T) and std::atomic<T>::fetch_and(T) are required by packed_spinlock");
122 index >= 0 && (
mask_ != 0),
123 "ripple::packed_spinlock::packed_spinlock : valid index and mask");
129 return (
bits_.fetch_or(
mask_, std::memory_order_acquire) &
mask_) == 0;
141 while ((
bits_.load(std::memory_order_relaxed) &
mask_) != 0)
149 bits_.fetch_and(~
mask_, std::memory_order_release);
168 static_assert(std::is_unsigned_v<T>);
195 return lock_.compare_exchange_weak(
198 std::memory_order_acquire,
199 std::memory_order_relaxed);
211 while (
lock_.load(std::memory_order_relaxed) != 0)
219 lock_.store(0, std::memory_order_release);
Classes to handle arrays of spinlocks packed into a single atomic integer:
packed_spinlock(std::atomic< T > &lock, int index)
A single spinlock packed inside the specified atomic.
packed_spinlock(packed_spinlock const &)=delete
packed_spinlock & operator=(packed_spinlock const &)=delete
A spinlock implemented on top of an atomic integer.
spinlock & operator=(spinlock const &)=delete
spinlock(spinlock const &)=delete
spinlock(std::atomic< T > &lock)
Grabs the.
void spin_pause() noexcept
Inform the processor that we are in a tight spin-wait loop.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.