DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
SpinLock.h File Reference

Lightweight spin lock for real-time audio thread synchronisation. More...

#include <atomic>
Include dependency graph for SpinLock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::SpinLock
 A minimal, real-time safe spin lock with a TTAS wait loop. More...
 
class  dspark::SpinLock::ScopedLock
 RAII wrapper that acquires the lock on construction and releases on destruction. More...
 
class  dspark::SpinLock::ScopedTryLock
 RAII wrapper that tries to acquire the lock without blocking. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Macros

#define DSPARK_SPIN_PAUSE()   ((void)0)
 

Detailed Description

Lightweight spin lock for real-time audio thread synchronisation.

A busy-wait mutex built on std::atomic_flag. Designed for protecting very short critical sections (a few assignments) where sleeping would introduce unacceptable latency: typically parameter hand-off between a GUI thread and the audio thread.

Dependencies: C++20 standard library only (<atomic>).

Warning
Do NOT use for long critical sections or high-contention scenarios. In those cases, prefer std::mutex or a lock-free data structure.
// From the GUI thread:
{
sharedParams = newParams;
}
// From the audio thread (non-blocking attempt):
{
if (guard.isLocked())
localCopy = sharedParams;
}
RAII wrapper that acquires the lock on construction and releases on destruction.
Definition SpinLock.h:136
RAII wrapper that tries to acquire the lock without blocking.
Definition SpinLock.h:162
A minimal, real-time safe spin lock with a TTAS wait loop.
Definition SpinLock.h:70

Definition in file SpinLock.h.

Macro Definition Documentation

◆ DSPARK_SPIN_PAUSE

#define DSPARK_SPIN_PAUSE ( )    ((void)0)

Definition at line 54 of file SpinLock.h.