LLVM: llvm::LazyAtomicPointer< T > Class Template Reference (original) (raw)
Atomic pointer that's lock-free, but that can coordinate concurrent writes from a lazy generator. More...
#include "[llvm/ADT/LazyAtomicPointer.h](LazyAtomicPointer%5F8h%5Fsource.html)"
| Public Member Functions | |
|---|---|
| void | store (T *Value) |
| Store a value. Waits for concurrent loadOrGenerate() calls. | |
| T * | exchange (T *Value) |
| Set a value. | |
| bool | compare_exchange_weak (T *&ExistingValue, T *NewValue) |
| Compare-exchange. | |
| bool | compare_exchange_strong (T *&ExistingValue, T *NewValue) |
| Compare-exchange. | |
| T * | load () const |
| Return the current stored value. | |
| T & | loadOrGenerate (function_ref< T *()> Generator) |
| Get the current value, or call Generator to generate a value. | |
| operator bool () const | |
| operator T* () const | |
| T & | operator* () const |
| T * | operator-> () const |
| LazyAtomicPointer () | |
| LazyAtomicPointer (std::nullptr_t) | |
| LazyAtomicPointer (T *Value) | |
| LazyAtomicPointer (const LazyAtomicPointer &RHS) | |
| LazyAtomicPointer & | operator= (std::nullptr_t) |
| LazyAtomicPointer & | operator= (T *RHS) |
| LazyAtomicPointer & | operator= (const LazyAtomicPointer &RHS) |
template<class T>
class llvm::LazyAtomicPointer< T >
Atomic pointer that's lock-free, but that can coordinate concurrent writes from a lazy generator.
Should be reserved for cases where concurrent uses of a generator for the same storage is unlikely.
The laziness comes in with loadOrGenerate(), which lazily calls the provided generator ONLY when the value is currently nullptr. With concurrent calls, only one generator is called and the rest see that value.
Most other APIs treat an in-flight loadOrGenerate() as if nullptr were stored. APIs that are required to write a value will spin.
The underlying storage is std::atomic<uintptr_t>.
TODO: In C++20, use std::atomic::wait() instead of spinning and call std::atomic::notify_all() in loadOrGenerate().
Definition at line 34 of file LazyAtomicPointer.h.
◆ LazyAtomicPointer() [2/4]
◆ LazyAtomicPointer() [3/4]
◆ LazyAtomicPointer() [4/4]
◆ compare_exchange_strong()
Compare-exchange.
Keeps trying if there is a concurrent loadOrGenerate() call.
Keep trying as long as it's busy.
Definition at line 80 of file LazyAtomicPointer.h.
◆ compare_exchange_weak()
◆ exchange()
◆ load()
◆ loadOrGenerate()
Get the current value, or call Generator to generate a value.
Guarantees that only one thread's Generator will run.
Precondition
Generator doesn't return nullptr.
Definition at line 109 of file LazyAtomicPointer.h.
◆ operator bool()
◆ operator T*()
◆ operator*()
◆ operator->()
◆ operator=() [1/3]
◆ operator=() [2/3]
◆ operator=() [3/3]
◆ store()
The documentation for this class was generated from the following file:
- include/llvm/ADT/LazyAtomicPointer.h