An AtomicObserver provides read‐optimized caching for an Observer using std::atomic. Reading only requires atomic loads unless the cached value is stale. If the cache needs to be refreshed, a mutex is used to synchronize the update. This avoids creating a shared_ptr for every read.
Synopsis
Declared in <folly/observer/Observer.h>
template<typename T>
class AtomicObserver;
Description
AtomicObserver models CopyConstructible and MoveConstructible. Copying or moving simply invalidates the cache.
AtomicObserver is ideal when there are lots of reads on a trivially‐copyable type. if std::atomic<T> is not possible but you still want to optimize reads, consider a TLObserver.
Observer<int> observer = ...; AtomicObserver<int> atomicObserver(observer); auto value = *atomicObserver;
Member Functions
Name |
Description |
|
Constructors |
Assignment operators |
|
Returns the cached value. |
|
Returns the underlying Observer. |
|
Returns the cached value. |
Non-Member Functions
Name |
Description |
Same as makeObserver(...), but creates AtomicObserver. |
Created with MrDocs