folly::observer::ReadMostlyAtomicObserver

A ReadMostlyAtomicObserver guarantees that reading is exactly one relaxed atomic load and a read from a thread local bool. Like AtomicObserver, the value is cached using std::atomic. However, there is no version check when reading which means that the cached value may be out-of-date with the Observer value. The cached value will be updated asynchronously in a background thread.

Synopsis

Declared in <folly/observer/Observer.h>

template<typename T>
class ReadMostlyAtomicObserver;

Description

When get() is called from makeObserver, the underlying observer is directly snapshotted to ensure dependent observers have current values and capture dependencies.

ReadMostlyAtomicObserver is ideal for fastest possible reads on a trivially-copyable type when a slightly out-of-date value will suffice. It is perfect for very frequent reads coupled with very infrequent writes.

Observer<int> observer = ...; ReadMostlyAtomicObserver<int> atomicObserver(observer); auto value = *atomicObserver;

Member Functions

NameDescription
ReadMostlyAtomicObserver [constructor]Constructors
operator= [deleted]Deleted copy assignment operator.
get Returns the cached value.
getUnderlyingObserver Returns the underlying Observer.
operator* Returns the cached value.

Non-Member Functions

NameDescription
makeReadMostlyAtomicObserverSame as makeObserver(...), but creates ReadMostlyAtomicObserver.