24#ifndef MYSQL_SCHEDULER_SHARDED_COUNTER_H
25#define MYSQL_SCHEDULER_SHARDED_COUNTER_H
29#include <unordered_map>
47 long long get()
const;
60 void init(std::size_t num_threads,
bool enabled =
true);
86 std::unordered_map<long long, Map_value_type>
m_value;
Concurrent counter, relaxing contention on atomic counter when being updated by different threads.
Definition: sharded_counter.h:41
long long get_timer() const
Special function to handle timer (helper for add/get when builing a timer over a concurrent counter).
Definition: sharded_counter.cpp:120
std::atomic< long long > Map_value_type
Definition: sharded_counter.h:83
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,...
Definition: sharded_counter.cpp:62
void reset()
Sets the internal value to 0.
Definition: sharded_counter.cpp:76
void add(long long arg, std::size_t thread_id=0)
Updates value (add operation) for specific thread id.
Definition: sharded_counter.cpp:55
long long get() const
Coalescing get operation, available only for integer type.
Definition: sharded_counter.cpp:37
std::unordered_map< long long, Map_value_type > m_value
Keeps mapping between thread id and value of the counter for this thread id.
Definition: sharded_counter.h:86
void store(long long arg, std::size_t thread_id=0)
Stores value for specific thread id.
Definition: sharded_counter.cpp:48
bool m_enabled
Flag specifying whether this statistic is enabled, when false, methods are noop and return default va...
Definition: sharded_counter.h:89
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).
Definition: sharded_counter.cpp:101
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).
Definition: sharded_counter.cpp:93
static my_thread_id thread_id
Definition: my_thr_init.cc:60
Definition: base_dependency_tracker.h:41
required bool enabled
Definition: replication_group_member_actions.proto:33