A TLObserver provides read‐optimized caching for an Observer using thread‐local storage. This avoids creating a shared_ptr for every read.

Synopsis

Declared in <folly/observer/Observer.h>

template<typename T>
class TLObserver;

Description

The functionality is similar to that of AtomicObserver except it allows types that don't support atomics. If possible, use AtomicObserver instead.

TLObserver can consume significant amounts of memory if accessed from many threads. The problem is exacerbated if you chain several TLObservers. Therefore, TLObserver should be used sparingly.

Observer<int> observer = ...; TLObserver<int> tlObserver(observer); auto& snapshot = *tlObserver;

Member Functions

Name

Description

TLObserver [constructor]

Constructors

getSnapshotRef

Returns a reference to the thread‐local snapshot.

getUnderlyingObserver

Returns the underlying Observer.

operator*

Returns a reference to the thread‐local snapshot.

with

Invoke a function with the current observed value. The snapshot is held alive for the duration of the call, preventing read‐after‐free when accessing members of the observed object.

Non-Member Functions

Name

Description

makeTLObserver

Same as makeObserver(...), but creates TLObserver.

Created with MrDocs