MySQL 8.3.0
Source Code Documentation
ut0counter.h File Reference

Counter utility class. More...

#include <my_rdtsc.h>
#include "univ.i"
#include "os0thread.h"
#include "ut0cpu_cache.h"
#include "ut0dbg.h"
#include <array>
#include <atomic>
#include <functional>

Go to the source code of this file.

Classes

struct  generic_indexer_t< Type, N >
 Get the offset into the counter array. More...
 
struct  counter_indexer_t< Type, N >
 Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles, to index into the counter array. More...
 
struct  single_indexer_t< Type, N >
 For counters where N=1. More...
 
class  ib_counter_t< Type, N, Indexer >
 Class for using fuzzy counters. More...
 
struct  Counter::Shard
 Counter shard. More...
 
struct  Counter::Shards< COUNT >
 

Namespaces

namespace  Counter
 Sharded atomic counter.
 

Macros

#define default_indexer_t   counter_indexer_t
 

Typedefs

using Counter::Type = uint64_t
 
using Counter::N = std::atomic< Type >
 
using Counter::Pad = byte[ut::INNODB_CACHE_LINE_SIZE - sizeof(N)]
 
using Counter::Function = std::function< void(const Type)>
 

Functions

template<size_t COUNT>
Type Counter::add (Shards< COUNT > &shards, size_t id, size_t n)
 Increment the counter for a shard by n. More...
 
template<size_t COUNT>
Type Counter::sub (Shards< COUNT > &shards, size_t id, size_t n)
 Decrement the counter for a shard by n. More...
 
template<size_t COUNT>
Type Counter::inc (Shards< COUNT > &shards, size_t id)
 Increment the counter of a shard by 1. More...
 
template<size_t COUNT>
Type Counter::dec (Shards< COUNT > &shards, size_t id)
 Decrement the counter of a shard by 1. More...
 
template<size_t COUNT>
Type Counter::get (const Shards< COUNT > &shards, size_t id) noexcept
 Get the counter value for a shard. More...
 
template<size_t COUNT>
void Counter::for_each (const Shards< COUNT > &shards, Function &&f) noexcept
 Iterate over the shards. More...
 
template<size_t COUNT>
Type Counter::total (const Shards< COUNT > &shards) noexcept
 Get the total value of all shards. More...
 
template<size_t COUNT>
void Counter::clear (Shards< COUNT > &shards) noexcept
 Clear the counter - reset to 0. More...
 
template<size_t COUNT>
void Counter::copy (Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
 Copy the counters, overwrite destination. More...
 
template<size_t COUNT>
void Counter::add (Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
 Accumulate the counters, add source to destination. More...
 

Variables

constexpr uint32_t IB_N_SLOTS = 64
 Default number of slots to use in ib_counter_t. More...
 
constexpr auto Counter::Memory_order = std::memory_order_relaxed
 Relaxed order by default. More...
 

Detailed Description

Counter utility class.

Created 2012/04/12 by Sunny Bains

Macro Definition Documentation

◆ default_indexer_t

#define default_indexer_t   counter_indexer_t

Variable Documentation

◆ IB_N_SLOTS

constexpr uint32_t IB_N_SLOTS = 64
constexpr

Default number of slots to use in ib_counter_t.