|
EtcPal
HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
|
View other versions:
|
A value bundled with a lock that guards all access to it.
The wrapped value can only be reached through an RAII handle that holds the lock, so it cannot be accessed without synchronization. See the synchronized_value (Synchronized Values) module overview for an example.
| T | The type of the guarded value. |
| LockType | The type of lock guarding the value. Must provide bool Lock(), bool TryLock(int timeout_ms), and Unlock() (e.g. etcpal::Mutex or etcpal::RecursiveMutex; defaults to etcpal::Mutex). TryLock() and Unlock() are called from noexcept contexts and must not throw; report failure by return value. |
Public Member Functions | |||||
| template<typename... Args, typename = typename std::enable_if< std::is_constructible<T, Args&&...>::value && !std::is_same<typename std::decay<typename detail::FirstType<Args...>::type>::type, SynchronizedValue>::value>::type> | |||||
| SynchronizedValue (Args &&... args) noexcept(std::is_nothrow_constructible< T, Args... >::value) | |||||
| Construct the guarded value in place, forwarding the given arguments to its constructor. More... | |||||
Unsafe Access | |||||
Access the value or lock directly, without locking. Use with care. | |||||
| T & | GetValueUnsafe () noexcept | ||||
| LockType & | GetLockUnsafe () noexcept | ||||
Locked Access | |||||
Obtain an RAII handle that holds the lock for as long as the handle exists. | |||||
| StrictLockPtr< T, LockType > | operator-> () | ||||
| Lock the value and access a member of it for the duration of the enclosing expression. More... | |||||
| ConstStrictLockPtr< T, LockType > | operator-> () const | ||||
| Lock the value and access a member of it for the duration of the enclosing expression. More... | |||||
| StrictLockPtr< T, LockType > | Synchronize () | ||||
| Lock the value, returning a handle that holds the lock until it is destroyed. More... | |||||
| ConstStrictLockPtr< T, LockType > | Synchronize () const | ||||
| Lock the value, returning a handle that holds the lock until it is destroyed. More... | |||||
Non-blocking Locked Access | |||||
Try to acquire the lock, waiting up to Check OwnsLock() (or
| |||||
| UniqueLockPtr< T, LockType > | TryToSynchronize (int timeout_ms=0) noexcept | ||||
| ConstUniqueLockPtr< T, LockType > | TryToSynchronize (int timeout_ms=0) const noexcept | ||||
Unique Locked Access | |||||
Obtain a UniqueLockPtr handle in a specific acquisition mode, mirroring Boost's unique_synchronize()/defer_synchronize()/adopt_synchronize(). | |||||
| UniqueLockPtr< T, LockType > | UniqueSynchronize () | ||||
| Lock the value, returning a handle that can also Unlock(), re-Lock(), or Release() it. More... | |||||
| ConstUniqueLockPtr< T, LockType > | UniqueSynchronize () const | ||||
| UniqueLockPtr< T, LockType > | DeferSynchronize () noexcept | ||||
| Reference the value without locking; acquire later with Lock() or TryLock() on the handle. | |||||
| ConstUniqueLockPtr< T, LockType > | DeferSynchronize () const noexcept | ||||
| UniqueLockPtr< T, LockType > | AdoptSynchronize () noexcept | ||||
| Adopt the lock, which the calling thread must already hold, into a handle that will release it. | |||||
| ConstUniqueLockPtr< T, LockType > | AdoptSynchronize () const noexcept | ||||
Visitation | |||||
Invoke a callable with the guarded value held under lock for the call's duration.
| |||||
| template<typename F > | |||||
| decltype(auto) | Apply (F &&func) | ||||
| template<typename F > | |||||
| decltype(auto) | Apply (F &&func) const | ||||
Friends | |
| class | ConstStrictLockPtr< T, LockType > |
| class | StrictLockPtr< T, LockType > |
| class | ConstUniqueLockPtr< T, LockType > |
| class | UniqueLockPtr< T, LockType > |
|
inlineexplicitnoexcept |
Construct the guarded value in place, forwarding the given arguments to its constructor.
Excluded from overload resolution when T is not constructible from the arguments (so std::is_constructible reports accurately) and for a single SynchronizedValue argument, so that copy/move attempts select the implicitly-deleted copy constructor (and get a clear diagnostic) instead of trying to construct T from a SynchronizedValue.
|
inline |
Lock the value and access a member of it for the duration of the enclosing expression.
| std::runtime_error | if lock could not be acquired. |
|
inline |
Lock the value and access a member of it for the duration of the enclosing expression.
| std::runtime_error | if lock could not be acquired. |
|
inline |
Lock the value, returning a handle that holds the lock until it is destroyed.
| std::runtime_error | if lock could not be acquired. |
|
inline |
Lock the value, returning a handle that holds the lock until it is destroyed.
| std::runtime_error | if lock could not be acquired. |
|
inline |
Lock the value, returning a handle that can also Unlock(), re-Lock(), or Release() it.
| std::runtime_error | if lock could not be acquired. |