|
EtcPal
HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
|
View other versions:
|
A value bundled with a lock, where access requires holding the lock.
SynchronizedValue wraps a value of type T together with a lock and only hands out access to the value through RAII handles that hold that lock. This makes it impossible to touch the value without synchronization, in the style of Rust's Mutex<T>.
The value is reached either transiently with operator-> (locked for one call), for a scope via a handle returned from Synchronize(), through a callable with Apply(), or without blocking via TryToSynchronize(). By default the lock is an etcpal::Mutex.
Example usage:
An API that requires an already-locked value can take a StrictLockPtr&, which owns its lock unless it has been moved from. A UniqueLockPtr that owns its lock can be converted into one, either directly (StrictLockPtr<T>{std::move(unique)}) or Boost-style via Release() and an AdoptLockTag constructor.
func(*v.Synchronize(), *v.Synchronize()) or v->Append(v->GetPrefix()), since each handle lives until the end of the full expression. Data Structures | |
| struct | AdoptLockTag |
| Tag requesting that a lock already held by the calling thread be adopted rather than acquired. More... | |
| struct | DeferLockTag |
| Tag requesting that the lock be left unacquired on construction, to be acquired later with ConstUniqueLockPtr::Lock() or ConstUniqueLockPtr::TryLock(). More... | |
| struct | TryToLockTag |
| Tag requesting that the lock be acquired with a poll or optional timed wait, never failing with an exception; check OwnsLock() for the result. More... | |
| struct | SupportsTimedLock< LockType > |
Trait reporting whether SynchronizedValue::TryToSynchronize() honors its timeout for LockType on the target platform. More... | |
| class | ConstStrictLockPtr< T, LockType > |
| An RAII handle holding a SynchronizedValue's lock and granting read-only access to the value. More... | |
| class | StrictLockPtr< T, LockType > |
| An RAII handle holding a SynchronizedValue's lock and granting mutable access to the value. More... | |
| class | ConstUniqueLockPtr< T, LockType > |
| An RAII handle for read-only access whose lock may or may not be held. More... | |
| class | UniqueLockPtr< T, LockType > |
| An RAII handle for mutable access whose lock may or may not be held. More... | |
| class | SynchronizedValue< T, LockType > |
| A value bundled with a lock that guards all access to it. More... | |