Sharded atomic counter.
More...
|
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...
|
|
◆ Function
◆ Pad
◆ Type
◆ 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] | dst | Destination shard |
[in] | src | Source 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] | shards | Sharded counter to increment. |
[in] | id | Shard key. |
[in] | n | Number 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] | shards | Shards 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] | dst | Destination shard |
[in] | src | Source 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] | shards | Sharded counter to decrement. |
[in] | id | Shard 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] | shards | Shards to iterate over |
[in] | f | Callback 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] | shards | Sharded counter to increment. |
[in] | id | Shard 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] | shards | Sharded counter to increment. |
[in] | id | Shard 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] | shards | Sharded counter to increment. |
[in] | id | Shard key. |
[in] | n | Number 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
-
- Returns
- total value.
◆ Memory_order
constexpr auto Counter::Memory_order = std::memory_order_relaxed |
|
constexpr |
Relaxed order by default.