MySQL 9.0.0
Source Code Documentation
container::Padded_indexing< T > Class Template Reference

Indexing provider that pads each of the array elements to the size of the CPU cache line, in order to avoid false sharing and cache misses. More...

#include <atomics_array_index_padding.h>

Public Types

using type = std::atomic< T >
 

Public Member Functions

 Padded_indexing (size_t max_size)
 Constructor for the class that takes the maximum allowed number of elements in the array. More...
 
virtual ~Padded_indexing ()=default
 Class destructor. More...
 
size_t size () const
 The size of the array. More...
 
size_t translate (size_t index) const
 Translates the element index to the byte position in the array. More...
 

Static Public Member Functions

static size_t element_size ()
 The array element size, in bytes. More...
 

Private Attributes

size_t m_size {0}
 The size of the array. More...
 
size_t m_cacheline_size {0}
 The size of the CPU cache line. More...
 

Detailed Description

template<typename T>
class container::Padded_indexing< T >

Indexing provider that pads each of the array elements to the size of the CPU cache line, in order to avoid false sharing and cache misses.

In terms of the array size, this indexing provider will use force the use of more memory than the needed to store the array elements of type T. If the array is of size n, then instead of the allocated memory being n * sizeof(std::atomic<T>), it will be of size n * cache_line_size. Since, typically, in modern systems, the cache line size is 64 or 128 bytes, that would be an increase in the allocated memory.

This class translates element-to-byte indexing as if each element is aligned with the size of the CPU cache line. The CPU cache line size is calculated at runtime.

Member Typedef Documentation

◆ type

template<typename T >
using container::Padded_indexing< T >::type = std::atomic<T>

Constructor & Destructor Documentation

◆ Padded_indexing()

template<typename T >
container::Padded_indexing< T >::Padded_indexing ( size_t  max_size)

Constructor for the class that takes the maximum allowed number of elements in the array.

◆ ~Padded_indexing()

template<typename T >
virtual container::Padded_indexing< T >::~Padded_indexing ( )
virtualdefault

Class destructor.

Member Function Documentation

◆ element_size()

template<typename T >
size_t container::Padded_indexing< T >::element_size
static

The array element size, in bytes.

Returns
The array element size, in bytes.

◆ size()

template<typename T >
size_t container::Padded_indexing< T >::size

The size of the array.

Returns
the size of the array

◆ translate()

template<typename T >
size_t container::Padded_indexing< T >::translate ( size_t  index) const

Translates the element index to the byte position in the array.

Parameters
indexthe element index to be translated.
Returns
the byte position in the byte array.

Member Data Documentation

◆ m_cacheline_size

template<typename T >
size_t container::Padded_indexing< T >::m_cacheline_size {0}
private

The size of the CPU cache line.

◆ m_size

template<typename T >
size_t container::Padded_indexing< T >::m_size {0}
private

The size of the array.


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