MySQL 8.3.0
Source Code Documentation
memory::Aligned_atomic< T > Class Template Reference

Templated class that encapsulates an std::atomic within a byte buffer that is padded to the processor cache-line size. More...

#include <aligned_atomic.h>

Public Member Functions

 Aligned_atomic ()
 
 Aligned_atomic (T value)
 
 Aligned_atomic (Aligned_atomic< T > const &rhs)=delete
 
 Aligned_atomic (Aligned_atomic< T > &&rhs)
 
virtual ~Aligned_atomic ()
 
Aligned_atomic< T > & operator= (Aligned_atomic< T > const &rhs)=delete
 
Aligned_atomic< T > & operator= (Aligned_atomic< T > &&rhs)
 
Aligned_atomic< T > & operator= (T rhs)
 
 operator T () const
 Casting operator for directly accessing the value of the underlying std::atomic<T>. More...
 
bool operator== (std::nullptr_t rhs) const
 Equality operator to determine if the underlying storage memory is initialized. More...
 
bool operator!= (std::nullptr_t rhs) const
 Inequality operator to determine if the underlying storage memory is initialized. More...
 
bool operator== (T rhs) const
 Equality operator for determining if the value stored in the underlying std::atomic equals the passed parameter. More...
 
bool operator!= (T rhs) const
 Inequality operator for determining if the value stored in the underlying std::atomic differs from the passed parameter. More...
 
std::atomic< T > * operator-> ()
 
const std::atomic< T > * operator-> () const
 
std::atomic< T > & operator* ()
 
const std::atomic< T > & operator* () const
 
size_t size () const
 
size_t allocated_size () const
 

Private Attributes

size_t m_storage_size {0}
 The size of the byte buffer. More...
 
void * m_storage {nullptr}
 The byte buffer to use as underlying storage. More...
 
std::atomic< T > * m_underlying {nullptr}
 The pointer to the underlying std::atomic<T> object. More...
 

Friends

template<typename Accessor_type >
class Aligned_atomic_accessor
 

Detailed Description

template<typename T>
class memory::Aligned_atomic< T >

Templated class that encapsulates an std::atomic within a byte buffer that is padded to the processor cache-line size.

This class purpose is to help prevent false sharing between atomically accessed variables that are contiguous in memory. This is the normal case for arrays or class members declared next to each other.

If the intended usage is none of the above, std::atomic class should be used since the below implementation allocates more memory than needed for storing the intended value (in order to implement the padding to the cache-line).

Constructor & Destructor Documentation

◆ Aligned_atomic() [1/4]

template<typename T >
memory::Aligned_atomic< T >::Aligned_atomic

◆ Aligned_atomic() [2/4]

template<typename T >
memory::Aligned_atomic< T >::Aligned_atomic ( value)

◆ Aligned_atomic() [3/4]

template<typename T >
memory::Aligned_atomic< T >::Aligned_atomic ( Aligned_atomic< T > const &  rhs)
delete

◆ Aligned_atomic() [4/4]

template<typename T >
memory::Aligned_atomic< T >::Aligned_atomic ( Aligned_atomic< T > &&  rhs)

◆ ~Aligned_atomic()

template<typename T >
memory::Aligned_atomic< T >::~Aligned_atomic
virtual

Member Function Documentation

◆ allocated_size()

template<typename T >
size_t memory::Aligned_atomic< T >::allocated_size

◆ operator T()

template<typename T >
memory::Aligned_atomic< T >::operator T

Casting operator for directly accessing the value of the underlying std::atomic<T>.

Returns
The value of type T stored in the underlying std::atomic..

◆ operator!=() [1/2]

template<typename T >
bool memory::Aligned_atomic< T >::operator!= ( std::nullptr_t  rhs) const

Inequality operator to determine if the underlying storage memory is initialized.

Parameters
rhsnullptr value
Returns
true if the underlying storage memory is initialized, false otherwise.

◆ operator!=() [2/2]

template<typename T >
bool memory::Aligned_atomic< T >::operator!= ( rhs) const

Inequality operator for determining if the value stored in the underlying std::atomic differs from the passed parameter.

Parameters
rhsThe value to compare with.
Returns
true if the parameter value differs from the value stored in the underlying std::atomic, false otherwise.

◆ operator*() [1/2]

template<typename T >
std::atomic< T > & memory::Aligned_atomic< T >::operator*

◆ operator*() [2/2]

template<typename T >
const std::atomic< T > & memory::Aligned_atomic< T >::operator*

◆ operator->() [1/2]

template<typename T >
std::atomic< T > * memory::Aligned_atomic< T >::operator->

◆ operator->() [2/2]

template<typename T >
const std::atomic< T > * memory::Aligned_atomic< T >::operator->

◆ operator=() [1/3]

template<typename T >
memory::Aligned_atomic< T > & memory::Aligned_atomic< T >::operator= ( Aligned_atomic< T > &&  rhs)

◆ operator=() [2/3]

template<typename T >
Aligned_atomic< T > & memory::Aligned_atomic< T >::operator= ( Aligned_atomic< T > const &  rhs)
delete

◆ operator=() [3/3]

template<typename T >
memory::Aligned_atomic< T > & memory::Aligned_atomic< T >::operator= ( rhs)

◆ operator==() [1/2]

template<typename T >
bool memory::Aligned_atomic< T >::operator== ( std::nullptr_t  rhs) const

Equality operator to determine if the underlying storage memory is initialized.

Parameters
rhsnullptr value
Returns
true if the underlying storage memory is not initialized, false otherwise.

◆ operator==() [2/2]

template<typename T >
bool memory::Aligned_atomic< T >::operator== ( rhs) const

Equality operator for determining if the value stored in the underlying std::atomic equals the passed parameter.

Parameters
rhsThe value to compare with.
Returns
true if the parameter value equals the value stored in the underlying std::atomic, false otherwise.

◆ size()

template<typename T >
size_t memory::Aligned_atomic< T >::size

Friends And Related Function Documentation

◆ Aligned_atomic_accessor

template<typename T >
template<typename Accessor_type >
friend class Aligned_atomic_accessor
friend

Member Data Documentation

◆ m_storage

template<typename T >
void* memory::Aligned_atomic< T >::m_storage {nullptr}
private

The byte buffer to use as underlying storage.

◆ m_storage_size

template<typename T >
size_t memory::Aligned_atomic< T >::m_storage_size {0}
private

The size of the byte buffer.

◆ m_underlying

template<typename T >
std::atomic<T>* memory::Aligned_atomic< T >::m_underlying {nullptr}
private

The pointer to the underlying std::atomic<T> object.


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