![]() |
MySQL 26.7.0
Source Code Documentation
|
Concurrent counter, relaxing contention on atomic counter when being updated by different threads. More...
#include <sharded_counter.h>
Public Member Functions | |
| long long | get (std::size_t thread_id) const |
| Obtains value for specific thread id. More... | |
| long long | get () const |
| Coalescing get operation, available only for integer type. More... | |
| void | store (long long arg, std::size_t thread_id=0) |
| Stores value for specific thread id. More... | |
| void | add (long long arg, std::size_t thread_id=0) |
| Updates value (add operation) for specific thread id. More... | |
| void | init (std::size_t num_threads, bool enabled=true) |
| Initializes this counter for requested number of threads, starting with thread id equal to 0, up to num_threads-1. More... | |
| void | start_time (std::size_t thread_id=0) |
| Special function to handle timer (helper for add/get when builing a timer over a concurrent counter). More... | |
| void | stop_time (std::size_t thread_id=0) |
| Special function to handle timer (helper for add/get when builing a timer over a concurrent counter). More... | |
| long long | get_timer (std::size_t thread_id) const |
| Special function to handle timer (helper for add/get when builing a timer over a concurrent counter). More... | |
| long long | get_timer () const |
| Special function to handle timer (helper for add/get when builing a timer over a concurrent counter). More... | |
| void | reset () |
| Sets the internal value to 0. More... | |
Protected Types | |
| using | Map_value_type = std::atomic< long long > |
Protected Attributes | |
| std::unordered_map< long long, Map_value_type > | m_value |
| Keeps mapping between thread id and value of the counter for this thread id. More... | |
| bool | m_enabled {true} |
| Flag specifying whether this statistic is enabled, when false, methods are noop and return default values. More... | |
Concurrent counter, relaxing contention on atomic counter when being updated by different threads.
The caller is able to get a value for specific thread, and store the value held by a specific thread (get, store). In addition to that, the caller can extract cumulative value for all of the threads (via get), atomically increment the counter by a specific value, or use helper time counters (start_timer, stop_timer, get_timer).
|
protected |
| void mysql::scheduler::Sharded_counter::add | ( | long long | arg, |
| std::size_t | thread_id = 0 |
||
| ) |
Updates value (add operation) for specific thread id.
| arg | Update op argument |
| thread_id | Requested thread id |
| long long mysql::scheduler::Sharded_counter::get | ( | ) | const |
Coalescing get operation, available only for integer type.
| long long mysql::scheduler::Sharded_counter::get | ( | std::size_t | thread_id | ) | const |
Obtains value for specific thread id.
| thread_id | Requested thread id |
| long long mysql::scheduler::Sharded_counter::get_timer | ( | ) | const |
Special function to handle timer (helper for add/get when builing a timer over a concurrent counter).
Get coalesced timer value.
| long long mysql::scheduler::Sharded_counter::get_timer | ( | std::size_t | thread_id | ) | const |
Special function to handle timer (helper for add/get when builing a timer over a concurrent counter).
Get timer value for the specified thread id
| thread_id | Requested thread id |
| void mysql::scheduler::Sharded_counter::init | ( | std::size_t | num_threads, |
| bool | enabled = true |
||
| ) |
Initializes this counter for requested number of threads, starting with thread id equal to 0, up to num_threads-1.
| num_threads | Requested number of threads |
| enabled | Specify whether this statistic is enabled |
| void mysql::scheduler::Sharded_counter::reset | ( | ) |
Sets the internal value to 0.
| void mysql::scheduler::Sharded_counter::start_time | ( | std::size_t | thread_id = 0 | ) |
Special function to handle timer (helper for add/get when builing a timer over a concurrent counter).
Start timer.
| thread_id | Requested thread id |
| void mysql::scheduler::Sharded_counter::stop_time | ( | std::size_t | thread_id = 0 | ) |
Special function to handle timer (helper for add/get when builing a timer over a concurrent counter).
Stop timer for the specified thread id
| thread_id | Requested thread id |
| void mysql::scheduler::Sharded_counter::store | ( | long long | arg, |
| std::size_t | thread_id = 0 |
||
| ) |
Stores value for specific thread id.
| arg | Update op argument |
| thread_id | Requested thread id |
|
protected |
Flag specifying whether this statistic is enabled, when false, methods are noop and return default values.
|
protected |
Keeps mapping between thread id and value of the counter for this thread id.