folly::TLRefCount

A reference counter that keeps per-thread counts to avoid contention.

Synopsis

Declared in <folly/concurrency/memory/TLRefCount.h>

class TLRefCount;

Description

The count is maintained in thread-local sub-counters while in the local phase, then folded into a single global atomic counter once useGlobal() is called. This makes increments and decrements cheap in the common case.

Type Aliases

NameDescription
Int The signed integer type used for the count.

Member Functions

NameDescription
TLRefCount [constructor]Constructs the counter in the local phase with an initial count of one.
~TLRefCount [destructor]Destroys the counter; requires the global count to have reached zero.
operator* Reads the current reference count.
operator++ Increments the reference count.
operator-- Decrements the reference count.
useGlobal Switches this counter to the global phase.

Static Member Functions

NameDescription
useGlobal Switches several counters to the global phase together.