MySQL 26.7.0
Source Code Documentation
mysql::scheduler::Sharded_counter Class Reference

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_typem_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...
 

Detailed Description

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).

Member Typedef Documentation

◆ Map_value_type

using mysql::scheduler::Sharded_counter::Map_value_type = std::atomic<long long>
protected

Member Function Documentation

◆ add()

void mysql::scheduler::Sharded_counter::add ( long long  arg,
std::size_t  thread_id = 0 
)

Updates value (add operation) for specific thread id.

Parameters
argUpdate op argument
thread_idRequested thread id

◆ get() [1/2]

long long mysql::scheduler::Sharded_counter::get ( ) const

Coalescing get operation, available only for integer type.

◆ get() [2/2]

long long mysql::scheduler::Sharded_counter::get ( std::size_t  thread_id) const

Obtains value for specific thread id.

Parameters
thread_idRequested thread id

◆ get_timer() [1/2]

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.

Returns
Coalesced timer value

◆ get_timer() [2/2]

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

Parameters
thread_idRequested thread id
Returns
Timer value for the specified thread

◆ init()

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.

Parameters
num_threadsRequested number of threads
enabledSpecify whether this statistic is enabled

◆ reset()

void mysql::scheduler::Sharded_counter::reset ( )

Sets the internal value to 0.

◆ start_time()

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.

Parameters
thread_idRequested thread id

◆ stop_time()

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

Parameters
thread_idRequested thread id

◆ store()

void mysql::scheduler::Sharded_counter::store ( long long  arg,
std::size_t  thread_id = 0 
)

Stores value for specific thread id.

Parameters
argUpdate op argument
thread_idRequested thread id

Member Data Documentation

◆ m_enabled

bool mysql::scheduler::Sharded_counter::m_enabled {true}
protected

Flag specifying whether this statistic is enabled, when false, methods are noop and return default values.

◆ m_value

std::unordered_map<long long, Map_value_type> mysql::scheduler::Sharded_counter::m_value
protected

Keeps mapping between thread id and value of the counter for this thread id.


The documentation for this class was generated from the following files: