Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::Seqlock< T > Class Template Reference

Seqlock. More...

#include <seqlock.h>

Inheritance diagram for roc::core::Seqlock< T >:
Collaboration diagram for roc::core::Seqlock< T >:

Public Member Functions

 Seqlock (T value)
 Initialize with given value. More...
 
seqlock_version_t version () const
 Load value version. Wait-free. More...
 
bool try_store (const T &value)
 Store value. Can be called concurrently, but only one concurrent call will succeed. Is both lock-free and wait-free, i.e. it never waits for sleeping threads and never spins. After this call returns, any thread calling wait_load() is guaranteed to get the updated value, and try_load() is guaranteed either return the updated value or fail (if changes are not fully published yet). More...
 
bool try_store_ver (const T &value, seqlock_version_t &ver)
 Store value. Like try_store(), but also returns updated version. More...
 
void exclusive_store (const T &value)
 Store value. Can NOT be called concurrently, assumes that writes are serialized. Is both lock-free and wait-free, i.e. it never waits for sleeping threads and never spins. After this call returns, any thread calling wait_load() is guaranteed to get the updated value, and try_load() is guaranteed either return the updated value or fail (if changes are not fully published yet). More...
 
void exclusive_store_ver (const T &value, seqlock_version_t &ver)
 Store value. Like exclusive_store(), but also returns updated version. More...
 
bool try_load (T &value) const
 Try to load value. Returns true if the value was loaded. May return false if concurrent store is currently in progress. Is both lock-free and wait-free, i.e. it never waits for sleeping threads and never spins. More...
 
bool try_load_ver (T &value, seqlock_version_t &ver) const
 Try to load value and version. Like try_load(), but also returns version. More...
 
wait_load () const
 Load value. May spin until concurrent store completes. Is NOT lock-free (or wait-free). More...
 
void wait_load_ver (T &value, seqlock_version_t &ver) const
 Load value and version. Like wait_load(), but also returns version. More...
 

Detailed Description

template<class T>
class roc::core::Seqlock< T >

Seqlock.

Provides safe concurrent access to a single value. Provides sequential consistency. Optimized for infrequent writes and frequent reads. Writes are lock-free and take priority over reads.

See details on the barriers here: https://elixir.bootlin.com/linux/latest/source/include/linux/seqlock.h https://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf

Definition at line 43 of file seqlock.h.

Constructor & Destructor Documentation

◆ Seqlock()

template<class T >
roc::core::Seqlock< T >::Seqlock ( value)
inlineexplicit

Initialize with given value.

Definition at line 46 of file seqlock.h.

Member Function Documentation

◆ exclusive_store()

template<class T >
void roc::core::Seqlock< T >::exclusive_store ( const T &  value)
inline

Store value. Can NOT be called concurrently, assumes that writes are serialized. Is both lock-free and wait-free, i.e. it never waits for sleeping threads and never spins. After this call returns, any thread calling wait_load() is guaranteed to get the updated value, and try_load() is guaranteed either return the updated value or fail (if changes are not fully published yet).

Definition at line 82 of file seqlock.h.

◆ exclusive_store_ver()

template<class T >
void roc::core::Seqlock< T >::exclusive_store_ver ( const T &  value,
seqlock_version_t ver 
)
inline

Store value. Like exclusive_store(), but also returns updated version.

Definition at line 89 of file seqlock.h.

◆ try_load()

template<class T >
bool roc::core::Seqlock< T >::try_load ( T &  value) const
inline

Try to load value. Returns true if the value was loaded. May return false if concurrent store is currently in progress. Is both lock-free and wait-free, i.e. it never waits for sleeping threads and never spins.

Definition at line 98 of file seqlock.h.

◆ try_load_ver()

template<class T >
bool roc::core::Seqlock< T >::try_load_ver ( T &  value,
seqlock_version_t ver 
) const
inline

Try to load value and version. Like try_load(), but also returns version.

Definition at line 105 of file seqlock.h.

◆ try_store()

template<class T >
bool roc::core::Seqlock< T >::try_store ( const T &  value)
inline

Store value. Can be called concurrently, but only one concurrent call will succeed. Is both lock-free and wait-free, i.e. it never waits for sleeping threads and never spins. After this call returns, any thread calling wait_load() is guaranteed to get the updated value, and try_load() is guaranteed either return the updated value or fail (if changes are not fully published yet).

Definition at line 64 of file seqlock.h.

◆ try_store_ver()

template<class T >
bool roc::core::Seqlock< T >::try_store_ver ( const T &  value,
seqlock_version_t ver 
)
inline

Store value. Like try_store(), but also returns updated version.

Definition at line 71 of file seqlock.h.

◆ version()

template<class T >
seqlock_version_t roc::core::Seqlock< T >::version ( ) const
inline

Load value version. Wait-free.

Definition at line 53 of file seqlock.h.

◆ wait_load()

template<class T >
T roc::core::Seqlock< T >::wait_load ( ) const
inline

Load value. May spin until concurrent store completes. Is NOT lock-free (or wait-free).

Definition at line 112 of file seqlock.h.

◆ wait_load_ver()

template<class T >
void roc::core::Seqlock< T >::wait_load_ver ( T &  value,
seqlock_version_t ver 
) const
inline

Load value and version. Like wait_load(), but also returns version.

Definition at line 121 of file seqlock.h.


The documentation for this class was generated from the following file: