MySQL 9.0.0
Source Code Documentation
|
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... | |
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.
using container::Padded_indexing< T >::type = std::atomic<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.
|
virtualdefault |
Class destructor.
|
static |
The array element size, in bytes.
size_t container::Padded_indexing< T >::size |
The size of the array.
size_t container::Padded_indexing< T >::translate | ( | size_t | index | ) | const |
Translates the element index to the byte position in the array.
index | the element index to be translated. |
|
private |
The size of the CPU cache line.
|
private |
The size of the array.