MySQL 8.3.0
Source Code Documentation
ut::Seq_lock< T > Class Template Reference

A class that allows to read value of variable of some type T atomically and allows the value to be changed, all using lock-free operations. More...

#include <ut0seq_lock.h>

Inheritance diagram for ut::Seq_lock< T >:
[legend]

Public Member Functions

 Seq_lock ()=default
 
template<typename... Args>
 Seq_lock (Args... args)
 
template<typename Op >
void write (Op &&op)
 Writes a new value for the variable of type T. More...
 
template<typename Op >
auto read (Op &&op) const
 

Private Attributes

m_value
 Stored value. More...
 
std::atomic< uint64_t > m_seq {0}
 Sequence count. More...
 

Additional Inherited Members

- Private Member Functions inherited from ut::Non_copyable
 Non_copyable (const Non_copyable &)=delete
 
Non_copyableoperator= (const Non_copyable &)=delete
 
 Non_copyable ()=default
 
 ~Non_copyable ()=default
 

Detailed Description

template<typename T>
class ut::Seq_lock< T >

A class that allows to read value of variable of some type T atomically and allows the value to be changed, all using lock-free operations.

The type T has to be composed of std::atomic fields only. That is because read(op_r) might read it in parallel to write(op_w). Other than that you are allowed to use any type. Inspired by https://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf Figure 6.

Constructor & Destructor Documentation

◆ Seq_lock() [1/2]

template<typename T >
ut::Seq_lock< T >::Seq_lock ( )
default

◆ Seq_lock() [2/2]

template<typename T >
template<typename... Args>
ut::Seq_lock< T >::Seq_lock ( Args...  args)
inline

Member Function Documentation

◆ read()

template<typename T >
template<typename Op >
auto ut::Seq_lock< T >::read ( Op &&  op) const
inline

◆ write()

template<typename T >
template<typename Op >
void ut::Seq_lock< T >::write ( Op &&  op)
inline

Writes a new value for the variable of type T.

The op can use memory_order_relaxed stores. NOTE: The user needs to synchronize all calls to this method.

Member Data Documentation

◆ m_seq

template<typename T >
std::atomic<uint64_t> ut::Seq_lock< T >::m_seq {0}
private

Sequence count.

Even when the value is ready for read, odd when the value is being written to.

◆ m_value

template<typename T >
T ut::Seq_lock< T >::m_value
private

Stored value.


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