MySQL  8.0.20
Source Code Documentation
ut0counter.h File Reference

Counter utility class. More...

#include <my_rdtsc.h>
#include "univ.i"
#include "os0thread.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...
 

Namespaces

 Counter
 Sharded atomic counter.
 

Macros

#define INNOBASE_CACHE_LINE_SIZE   64
 CPU cache line size. More...
 
#define IB_N_SLOTS   64
 Default number of slots to use in ib_counter_t. More...
 
#define default_indexer_t   counter_indexer_t
 

Typedefs

using Counter::Type = uint64_t
 
using Counter::N = std::atomic< Type >
 
using Counter::Pad = byte[INNOBASE_CACHE_LINE_SIZE - sizeof(N)]
 
template<size_t COUNT = 128>
using Counter::Shards = std::array< Shard, COUNT >
 
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 auto Counter::Memory_order = std::memory_order_relaxed
 

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

◆ IB_N_SLOTS

#define IB_N_SLOTS   64

Default number of slots to use in ib_counter_t.

◆ INNOBASE_CACHE_LINE_SIZE

#define INNOBASE_CACHE_LINE_SIZE   64

CPU cache line size.