CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | List of all members
CppCommon::SeqLock< T > Class Template Reference

Sequential lock synchronization primitive. More...

#include <seq_lock.h>

Public Member Functions

 SeqLock ()
 
 SeqLock (const T &data)
 
 SeqLock (const SeqLock &)=delete
 
 SeqLock (SeqLock &&)=default
 
 ~SeqLock ()=default
 
SeqLockoperator= (const T &data) noexcept
 
SeqLockoperator= (const SeqLock &)=delete
 
SeqLockoperator= (SeqLock &&)=delete
 
Read () const noexcept
 Read data under the sequential lock. More...
 
void Write (const T &data) noexcept
 Write data under the sequential lock. More...
 

Detailed Description

template<typename T>
class CppCommon::SeqLock< T >

Sequential lock synchronization primitive.

Sequential locks are an important synchronization mechanism and represent a significant improvement over conventional read/write locks in some contexts. They avoid the need to update a synchronization variable during a reader critical section, and hence improve performance by avoiding cache coherence misses on the lock object itself.

Thread-safe.

https://en.wikipedia.org/wiki/Seqlock

Examples
threads_seq_lock.cpp.

Definition at line 30 of file seq_lock.h.

Constructor & Destructor Documentation

◆ SeqLock() [1/4]

template<typename T >
CppCommon::SeqLock< T >::SeqLock
inline

Definition at line 12 of file seq_lock.inl.

◆ SeqLock() [2/4]

template<typename T >
CppCommon::SeqLock< T >::SeqLock ( const T &  data)
inlineexplicit

Definition at line 19 of file seq_lock.inl.

◆ SeqLock() [3/4]

template<typename T >
CppCommon::SeqLock< T >::SeqLock ( const SeqLock< T > &  )
delete

◆ SeqLock() [4/4]

template<typename T >
CppCommon::SeqLock< T >::SeqLock ( SeqLock< T > &&  )
default

◆ ~SeqLock()

template<typename T >
CppCommon::SeqLock< T >::~SeqLock ( )
default

Member Function Documentation

◆ operator=() [1/3]

template<typename T >
SeqLock& CppCommon::SeqLock< T >::operator= ( const SeqLock< T > &  )
delete

◆ operator=() [2/3]

template<typename T >
SeqLock< T > & CppCommon::SeqLock< T >::operator= ( const T &  data)
inlinenoexcept

Definition at line 25 of file seq_lock.inl.

◆ operator=() [3/3]

template<typename T >
SeqLock& CppCommon::SeqLock< T >::operator= ( SeqLock< T > &&  )
delete

◆ Read()

template<typename T >
T CppCommon::SeqLock< T >::Read
inlinenoexcept

Read data under the sequential lock.

Will block in a spin loop.

Returns
Read data

Definition at line 32 of file seq_lock.inl.

◆ Write()

template<typename T >
void CppCommon::SeqLock< T >::Write ( const T &  data)
inlinenoexcept

Write data under the sequential lock.

Will not block.

Parameters
data- Data to write

Definition at line 51 of file seq_lock.inl.


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