Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::SeqLock< T > Class Template Reference

Lock-free reader/writer for reading multi-field structs as consistent snapshots. More...

#include <seqlock.hpp>

Public Member Functions

 SeqLock ()
 SeqLock (const T &initial)
void write (const T &value)
 Publish a new value.
T read () const
 Read a consistent snapshot.

Detailed Description

template<typename T>
class pulp::runtime::SeqLock< T >

Lock-free reader/writer for reading multi-field structs as consistent snapshots.

Use when a single writer (e.g., the audio thread) publishes a struct that multiple readers need to consume atomically. Readers spin-retry if the data was modified during their read, guaranteeing coherence without mutexes.

Template Parameters
TMust be trivially copyable.
struct Transport { double tempo; double beat_pos; int time_sig_num; };
// Writer (audio thread):
transport.write({120.0, 4.5, 4});
// Reader (UI thread):
auto snap = transport.read(); // always a consistent snapshot
Lock-free reader/writer for reading multi-field structs as consistent snapshots.
Definition seqlock.hpp:42
void write(const T &value)
Publish a new value.
Definition seqlock.hpp:59
T read() const
Read a consistent snapshot.
Definition seqlock.hpp:71
Note
Safe on ARM and x86. Uses acquire/release ordering internally.
Only one writer thread is allowed. Multiple concurrent readers are safe.

Constructor & Destructor Documentation

◆ SeqLock() [1/2]

template<typename T>
pulp::runtime::SeqLock< T >::SeqLock ( )
inline

◆ SeqLock() [2/2]

template<typename T>
pulp::runtime::SeqLock< T >::SeqLock ( const T & initial)
inlineexplicit
Parameters
initialStarting value.

Member Function Documentation

◆ read()

template<typename T>
T pulp::runtime::SeqLock< T >::read ( ) const
inline

Read a consistent snapshot.

Retries automatically on torn reads. Safe to call from any number of reader threads concurrently.

Returns
A coherent copy of the stored value.

◆ write()

template<typename T>
void pulp::runtime::SeqLock< T >::write ( const T & value)
inline

Publish a new value.

Must be called from a single writer thread only.

Parameters
valueThe new value to publish.

The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/runtime/include/pulp/runtime/seqlock.hpp