MySQL 8.4.3
Source Code Documentation
Counter Namespace Reference

Sharded atomic counter. More...

Classes

struct  Shard
 Counter shard. More...
 
struct  Shards
 

Typedefs

using Type = uint64_t
 
using N = std::atomic< Type >
 
using Pad = byte[ut::INNODB_CACHE_LINE_SIZE - sizeof(N)]
 
using Function = std::function< void(const Type)>
 

Functions

template<size_t COUNT>
Type add (Shards< COUNT > &shards, size_t id, size_t n)
 Increment the counter for a shard by n. More...
 
template<size_t COUNT>
Type sub (Shards< COUNT > &shards, size_t id, size_t n)
 Decrement the counter for a shard by n. More...
 
template<size_t COUNT>
Type inc (Shards< COUNT > &shards, size_t id)
 Increment the counter of a shard by 1. More...
 
template<size_t COUNT>
Type dec (Shards< COUNT > &shards, size_t id)
 Decrement the counter of a shard by 1. More...
 
template<size_t COUNT>
Type get (const Shards< COUNT > &shards, size_t id) noexcept
 Get the counter value for a shard. More...
 
template<size_t COUNT>
void for_each (const Shards< COUNT > &shards, Function &&f) noexcept
 Iterate over the shards. More...
 
template<size_t COUNT>
Type total (const Shards< COUNT > &shards) noexcept
 Get the total value of all shards. More...
 
template<size_t COUNT>
void clear (Shards< COUNT > &shards) noexcept
 Clear the counter - reset to 0. More...
 
template<size_t COUNT>
void copy (Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
 Copy the counters, overwrite destination. More...
 
template<size_t COUNT>
void add (Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
 Accumulate the counters, add source to destination. More...
 

Variables

constexpr auto Memory_order = std::memory_order_relaxed
 Relaxed order by default. More...
 

Detailed Description

Sharded atomic counter.

Typedef Documentation

◆ Function

using Counter::Function = typedef std::function<void(const Type)>

◆ N

using Counter::N = typedef std::atomic<Type>

◆ Pad

using Counter::Pad = typedef byte[ut::INNODB_CACHE_LINE_SIZE - sizeof(N)]

◆ Type

using Counter::Type = typedef uint64_t

Function Documentation

◆ add() [1/2]

template<size_t COUNT>
void Counter::add ( Shards< COUNT > &  dst,
const Shards< COUNT > &  src 
)
inlinenoexcept

Accumulate the counters, add source to destination.

Parameters
[in,out]dstDestination shard
[in]srcSource shard.

◆ add() [2/2]

template<size_t COUNT>
Type Counter::add ( Shards< COUNT > &  shards,
size_t  id,
size_t  n 
)
inline

Increment the counter for a shard by n.

Parameters
[in,out]shardsSharded counter to increment.
[in]idShard key.
[in]nNumber to add.
Returns
previous value.

◆ clear()

template<size_t COUNT>
void Counter::clear ( Shards< COUNT > &  shards)
inlinenoexcept

Clear the counter - reset to 0.

Parameters
[in,out]shardsShards to clear.

◆ copy()

template<size_t COUNT>
void Counter::copy ( Shards< COUNT > &  dst,
const Shards< COUNT > &  src 
)
inlinenoexcept

Copy the counters, overwrite destination.

Parameters
[in,out]dstDestination shard
[in]srcSource shard.

◆ dec()

template<size_t COUNT>
Type Counter::dec ( Shards< COUNT > &  shards,
size_t  id 
)
inline

Decrement the counter of a shard by 1.

Parameters
[in,out]shardsSharded counter to decrement.
[in]idShard key.
Returns
previous value.

◆ for_each()

template<size_t COUNT>
void Counter::for_each ( const Shards< COUNT > &  shards,
Function &&  f 
)
inlinenoexcept

Iterate over the shards.

Parameters
[in]shardsShards to iterate over
[in]fCallback function

◆ get()

template<size_t COUNT>
Type Counter::get ( const Shards< COUNT > &  shards,
size_t  id 
)
inlinenoexcept

Get the counter value for a shard.

Parameters
[in,out]shardsSharded counter to increment.
[in]idShard key.
Returns
current value.

◆ inc()

template<size_t COUNT>
Type Counter::inc ( Shards< COUNT > &  shards,
size_t  id 
)
inline

Increment the counter of a shard by 1.

Parameters
[in,out]shardsSharded counter to increment.
[in]idShard key.
Returns
previous value.

◆ sub()

template<size_t COUNT>
Type Counter::sub ( Shards< COUNT > &  shards,
size_t  id,
size_t  n 
)
inline

Decrement the counter for a shard by n.

Parameters
[in,out]shardsSharded counter to increment.
[in]idShard key.
[in]nNumber to add.
Returns
previous value.

◆ total()

template<size_t COUNT>
Type Counter::total ( const Shards< COUNT > &  shards)
inlinenoexcept

Get the total value of all shards.

Parameters
[in]shardsShards to sum.
Returns
total value.

Variable Documentation

◆ Memory_order

constexpr auto Counter::Memory_order = std::memory_order_relaxed
constexpr

Relaxed order by default.