18#ifndef RIPPLE_BASICS_SPINLOCK_H_INCLUDED
19#define RIPPLE_BASICS_SPINLOCK_H_INCLUDED
21#include <xrpl/beast/utility/instrumentation.h>
47 asm volatile(
"yield");
92 static_assert(std::is_unsigned_v<T>);
95 std::is_same_v<
decltype(std::declval<std::atomic<T>&>().fetch_or(0)), T> &&
97 "std::atomic<T>::fetch_and(T) and std::atomic<T>::fetch_and(T) are required by packed_spinlock");
121 index >= 0 && (
mask_ != 0),
122 "ripple::packed_spinlock::packed_spinlock : valid index and mask");
128 return (
bits_.fetch_or(
mask_, std::memory_order_acquire) &
mask_) == 0;
140 while ((
bits_.load(std::memory_order_relaxed) &
mask_) != 0)
148 bits_.fetch_and(~
mask_, std::memory_order_release);
167 static_assert(std::is_unsigned_v<T>);
194 return lock_.compare_exchange_weak(
197 std::memory_order_acquire,
198 std::memory_order_relaxed);
210 while (
lock_.load(std::memory_order_relaxed) != 0)
218 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.