|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
A minimal, real-time safe spin lock with a TTAS wait loop. More...
#include <SpinLock.h>
Classes | |
| class | ScopedLock |
| RAII wrapper that acquires the lock on construction and releases on destruction. More... | |
| class | ScopedTryLock |
| RAII wrapper that tries to acquire the lock without blocking. More... | |
Public Member Functions | |
| SpinLock () noexcept=default | |
| Constructs an unlocked SpinLock. | |
| SpinLock (const SpinLock &)=delete | |
| SpinLock & | operator= (const SpinLock &)=delete |
| void | lock () noexcept |
| Acquires the lock, spinning until successful. | |
| bool | tryLock () noexcept |
| Attempts to acquire the lock without waiting. | |
| bool | try_lock () noexcept |
| Standard-library spelling of tryLock(). | |
| void | unlock () noexcept |
| Releases the lock, restoring it to the clear state. | |
A minimal, real-time safe spin lock with a TTAS wait loop.
Fulfills the standard Lockable requirements (lock / try_lock / unlock), so it composes with std::lock_guard, std::unique_lock and std::scoped_lock.
lock() busy-waits using a Test-and-Test-and-Set (TTAS) pattern to avoid cache thrashing.tryLock() attempts a single acquire without waiting: the right call on the audio thread.unlock() releases the lock safely. Definition at line 69 of file SpinLock.h.
|
defaultnoexcept |
Constructs an unlocked SpinLock.
|
delete |
|
inlinenoexcept |
Acquires the lock, spinning until successful.
Employs a TTAS (Test-and-Test-and-Set) loop: after a failed acquire it re-reads the flag with memory_order_relaxed (C++20 atomic_flag::test), keeping the cache line in a shared state and avoiding bus traffic until the lock appears free.
Definition at line 88 of file SpinLock.h.
|
inlinenoexcept |
Standard-library spelling of tryLock().
Completes the C++ Lockable requirements so the lock works with std::unique_lock(std::try_to_lock) and multi-lock std::scoped_lock.
Definition at line 119 of file SpinLock.h.
|
inlinenoexcept |
Attempts to acquire the lock without waiting.
Definition at line 108 of file SpinLock.h.
|
inlinenoexcept |
Releases the lock, restoring it to the clear state.
Definition at line 124 of file SpinLock.h.