|
LLVM 22.0.0git
|
Atomic pointer that's lock-free, but that can coordinate concurrent writes from a lazy generator. More...
#include "llvm/ADT/LazyAtomicPointer.h"
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) |
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<T>::wait() instead of spinning and call std::atomic<T>::notify_all() in loadOrGenerate().
Definition at line 34 of file LazyAtomicPointer.h.
|
inline |
Definition at line 141 of file LazyAtomicPointer.h.
|
inline |
Definition at line 142 of file LazyAtomicPointer.h.
|
inline |
Definition at line 143 of file LazyAtomicPointer.h.
|
inline |
Definition at line 144 of file LazyAtomicPointer.h.
|
inline |
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.
|
inline |
Compare-exchange.
Returns false if there is a concurrent loadOrGenerate() call, setting ExistingValue to nullptr.
Report the existing value as "None" if busy.
Definition at line 65 of file LazyAtomicPointer.h.
Referenced by llvm::LazyAtomicPointer< TrieNode >::exchange().
|
inline |
Set a value.
Return the old value. Waits for concurrent loadOrGenerate() calls.
Definition at line 54 of file LazyAtomicPointer.h.
Referenced by llvm::LazyAtomicPointer< TrieNode >::store().
|
inline |
Return the current stored value.
Returns None if there is a concurrent loadOrGenerate() in flight.
Definition at line 100 of file LazyAtomicPointer.h.
Referenced by llvm::LazyAtomicPointer< TrieNode >::operator bool(), operator T*(), and llvm::LazyAtomicPointer< TrieNode >::operator*().
|
inline |
Get the current value, or call Generator to generate a value.
Guarantees that only one thread's Generator will run.
Generator doesn't return nullptr. Definition at line 109 of file LazyAtomicPointer.h.
|
inlineexplicit |
Definition at line 131 of file LazyAtomicPointer.h.
|
inline |
Definition at line 132 of file LazyAtomicPointer.h.
|
inline |
Definition at line 134 of file LazyAtomicPointer.h.
Referenced by llvm::LazyAtomicPointer< TrieNode >::operator->().
|
inline |
Definition at line 139 of file LazyAtomicPointer.h.
|
inline |
Definition at line 155 of file LazyAtomicPointer.h.
|
inline |
Definition at line 147 of file LazyAtomicPointer.h.
|
inline |
Definition at line 151 of file LazyAtomicPointer.h.
|
inline |
Store a value. Waits for concurrent loadOrGenerate() calls.
Definition at line 50 of file LazyAtomicPointer.h.
Referenced by llvm::LazyAtomicPointer< TrieNode >::operator=(), llvm::LazyAtomicPointer< TrieNode >::operator=(), and llvm::LazyAtomicPointer< TrieNode >::operator=().