|
VLink
2.0.0
A high-performance communication middleware
|
Adaptive spin lock satisfying the C++ Lockable named requirement.
More...
#include <spin_lock.h>
Public Member Functions | |
| SpinLock () noexcept=default | |
| Constructs an unlocked spin lock. More... | |
| ~SpinLock () noexcept=default | |
| Destructor. Assumes the lock has already been released. More... | |
| void | lock () noexcept |
| Acquires the lock, spinning with adaptive back-off until it becomes free. More... | |
| bool | try_lock () noexcept |
| Attempts a single non-blocking acquire of the lock. More... | |
| void | unlock () noexcept |
Releases the lock with memory_order_release. More... | |
Adaptive spin lock satisfying the C++ Lockable named requirement.
Cache-line aligned through alignas(64) to prevent false sharing. Composes with std::lock_guard, std::unique_lock and the supplied SpinLockGuard.
|
defaultnoexcept |
Constructs an unlocked spin lock.
|
defaultnoexcept |
Destructor. Assumes the lock has already been released.
|
inlinenoexcept |
Acquires the lock, spinning with adaptive back-off until it becomes free.
Details.
The inner loop alternates exchange attempts with relaxed-load spins. Each back-off rung doubles the spin budget from 8 up to 1024 then yields the CPU. After 50000 spins the back-off action switches to a 10 us sleep and a one-time warning is emitted.
|
inlinenoexcept |
Attempts a single non-blocking acquire of the lock.
true when the lock was successfully acquired.
|
inlinenoexcept |
Releases the lock with memory_order_release.
May only be called by the thread that currently owns the lock.