perfc 0.11.0
Loading...
Searching...
No Matches

Detailed Description

Atomic counters types.

For an introduction with examples see Counters.

Three template specializations are provided. All satisfy the basic concept AtomicCounter :

T constraints Clock constraints Counter::ValueType Notes Link
Integral - T
  • Specialization is lock-free if std::atomic<T> is lock-free.
  • Specialization can be fully lock-free on most architectures.
  • Provides additional member functions like pre/post increment, FetchAdd/FetchSub.
  • No internal timestamp.
Counter<T>
Non-Integral - T
  • Specialization is lock-free if std::atomic<T> is lock-free.
  • No internal timestamp.
Counter<T>
None Clock satisfy TrivialClock Timestamped<T, TimePoint>
  • Default Clock is std::chrono::steady_clock.
  • Keeps internal timestamp.
  • Automatically updates timestamp on writes, if time is not provided by caller.
Counter<T, Clock>

Commonly used types have pre-defined aliases for double, signed and unsigned 64bit integer, with and without timestamp, see list below.

Note
As counters are potential synchronization objects they provide no copy or move constructor.

Files

file  counter.hpp
 Performance counter implementation.
 

Classes

struct  perfc::Timestamped< T, TimePoint >
 Trivial type describing a counter value and associated timestamp. More...
 
class  perfc::Counter< T, void, typename std::enable_if< std::is_integral< T >::value >::type >
 Integrals w/o timestamp Partial specialization for integral types T and without clock. More...
 
class  perfc::Counter< T, void, typename std::enable_if<!std::is_integral< T >::value >::type >
 Non-integrals w/o timestamp Partial specialization matching void clocks and non-integral T's. More...
 
class  perfc::Counter< T, Clock, typename std::enable_if<!std::is_void< Clock >::value >::type >
 With timestamp Partial specialization for non-void Clock type. More...
 

Enumerations

enum class  perfc::MemoryOrder : std::underlying_type_t< std::memory_order >
 Memory ordering constraints. More...
 

Aliases of timestamped counters

These aliases are using the clock std::steady_clock as a timestamp source.

using perfc::CounterDoubleTs = Counter<double, std::chrono::steady_clock>
 
using perfc::CounterU64Ts = Counter<std::uint64_t, std::chrono::steady_clock>
 
using perfc::CounterI64Ts = Counter<std::int64_t, std::chrono::steady_clock>
 

Aliases of non-timestamped counters

These counters aliases have no internal timestamp and are very light weight and on most 64bit architectures they are fully lock-free.

using perfc::CounterDouble = Counter<double, void>
 
using perfc::CounterU64 = Counter<std::uint64_t, void>
 
using perfc::CounterI64 = Counter<std::int64_t, void>
 

Synchronization functions

Provides capability to synchronize relaxed atomic counter reads and writes.

void perfc::CounterAcquire () noexcept
 Synchronizes-with CounterRelease() or Counter store operations using MemoryOrder::Release.
 
void perfc::CounterRelease () noexcept
 Synchronizes-with CounterAcquire() or counter load operations using MemoryOrder::Acquire.
 

Typedef Documentation

◆ CounterDouble

using perfc::CounterDouble = Counter<double, void>

Definition at line 498 of file counter.hpp.

◆ CounterDoubleTs

using perfc::CounterDoubleTs = Counter<double, std::chrono::steady_clock>

Definition at line 484 of file counter.hpp.

◆ CounterI64

using perfc::CounterI64 = Counter<std::int64_t, void>

Definition at line 500 of file counter.hpp.

◆ CounterI64Ts

using perfc::CounterI64Ts = Counter<std::int64_t, std::chrono::steady_clock>

Definition at line 486 of file counter.hpp.

◆ CounterU64

using perfc::CounterU64 = Counter<std::uint64_t, void>

Definition at line 499 of file counter.hpp.

◆ CounterU64Ts

using perfc::CounterU64Ts = Counter<std::uint64_t, std::chrono::steady_clock>

Definition at line 485 of file counter.hpp.

Enumeration Type Documentation

◆ MemoryOrder

template<class T, class Clock = std::chrono::steady_clock, class = void>
enum class MemoryOrder : std::underlying_type_t< std::memory_order >
related

Memory ordering constraints.

Definition at line 81 of file counter.hpp.

Function Documentation

◆ CounterAcquire()

void perfc::CounterAcquire ( )
inlinenoexcept

Synchronizes-with CounterRelease() or Counter store operations using MemoryOrder::Release.

CounterRelease() is only necessary ensure that preceding relaxed operations to Counter are synchronized with reads.

Definition at line 458 of file counter.hpp.

◆ CounterRelease()

void perfc::CounterRelease ( )
inlinenoexcept

Synchronizes-with CounterAcquire() or counter load operations using MemoryOrder::Acquire.

CounterRelease() is only necessary ensure that preceding relaxed operations to Counter are synchronized with reads.

Definition at line 471 of file counter.hpp.