|
VLink 2.0.0
A high-performance communication middleware
|
Adaptive, cache-line-aligned spin lock. More...
#include <spin_lock.h>
Public Member Functions | |
| SpinLock () noexcept=default | |
Default constructor. Initialises the flag to false (unlocked). | |
| ~SpinLock () noexcept=default | |
| Destructor. | |
| void | lock () noexcept |
| Acquires the lock, spinning until successful. | |
| bool | try_lock () noexcept |
| Attempts to acquire the lock without blocking. | |
| void | unlock () noexcept |
| Releases the lock. | |
Adaptive, cache-line-aligned spin lock.
Implements the Lockable named requirement: lock(), try_lock(), and unlock(). Can be used directly with std::lock_guard.
|
defaultnoexcept |
Default constructor. Initialises the flag to false (unlocked).
|
defaultnoexcept |
Destructor.
|
inlinenoexcept |
Acquires the lock, spinning until successful.
Details.
Uses an exponential back-off strategy to reduce bus contention:
load(relaxed) for up to backoff iterations.Utils::yield_cpu() (PAUSE/WFE/yield) when backoff is reached.
|
inlinenoexcept |
Attempts to acquire the lock without blocking.
Performs a single exchange(true, acquire). Returns immediately regardless of whether the lock was acquired.
true if the lock was successfully acquired, false if it was already held by another thread.
|
inlinenoexcept |
Releases the lock.
Stores false with release memory order. Must only be called by the thread that successfully called lock() or try_lock().