folly::SingletonRelaxedCounter

A singleton-per-tag relaxed counter.

Synopsis

Declared in <folly/concurrency/SingletonRelaxedCounter.h>

template<
    typename Int,
    typename Tag>
class SingletonRelaxedCounter;

Description

It is optimized for increment/decrement performance under contention. Each unique pair of integral type and tag type names a distinct counter. The value is computed by summing a global counter and all per-thread counters, so it is a relaxed approximation rather than a point-in-time snapshot; it is exact once the system quiesces. For unsigned types, decrements are assumed not to exceed increments and any observed excess is ignored.

Static Member Functions

NameDescription
add Adds a value to the counter.
count Computes the current value of the counter.
sub Subtracts a value from the counter.

Template Parameters

NameDescription
IntThe integral counter type.
TagA tag type selecting which counter instance to use.