MySQL  8.0.18
Source Code Documentation
Counter Namespace Reference

Sharded atomic counter. More...

Classes

struct  Shard
 Counter shard. More...
 

Typedefs

using Type = uint64_t
 
using N = std::atomic< Type >
 
using Pad = byte[INNOBASE_CACHE_LINE_SIZE - sizeof(N)]
 
template<size_t COUNT = 128>
using Shards = std::array< Shard, COUNT >
 
using Function = std::function< void(const Type)>
 

Functions

template<size_t COUNT>
void inc (Shards< COUNT > &shards, size_t id)
 Increment the counter of a shard by 1. More...
 
template<size_t COUNT>
void add (Shards< COUNT > &shards, size_t id, size_t n)
 Increment the counter for a shard by n. More...
 
template<size_t COUNT>
Type get (const Shards< COUNT > &shards, size_t id)
 Get the counter value for a shard. More...
 
template<size_t COUNT>
void for_each (const Shards< COUNT > &shards, Function &&f)
 Iterate over the shards. More...
 
template<size_t COUNT>
Type total (const Shards< COUNT > &shards)
 Get the total value of all shards. More...
 
template<size_t COUNT>
void clear (Shards< COUNT > &shards)
 Clear the counter - reset to 0. 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[INNOBASE_CACHE_LINE_SIZE - sizeof(N)]

◆ Shards

template<size_t COUNT = 128>
using Counter::Shards = typedef std::array<Shard, COUNT>

◆ Type

using Counter::Type = typedef uint64_t

Function Documentation

◆ add()

template<size_t COUNT>
void 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.

◆ clear()

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

Clear the counter - reset to 0.

Parameters
[in,out]shardsShards to clear.

◆ for_each()

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

Iterate over the shards.

Parameters
[in]shardsShards to iterate over
[in]fCallback function
Returns
total value.

◆ get()

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

Get the counter value for a shard.

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

◆ inc()

template<size_t COUNT>
void 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.

◆ total()

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

Get the total value of all shards.

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