#include <borrow.h>
Public Member Functions | |
constexpr | Borrowable (GuardedType &object, LockType &lock) noexcept |
template<typename U > | |
constexpr | Borrowable (const Borrowable< U, LockType > &other) |
Borrowable (const Borrowable &)=default | |
Borrowable & | operator= (const Borrowable &)=default |
Borrowable (Borrowable &&other)=default | |
Borrowable & | operator= (Borrowable &&other)=default |
BorrowedPointer< GuardedType, LockType > | acquire () const |
Blocks indefinitely until the object can be borrowed. Failures are fatal. | |
template<int &... ExplicitArgumentBarrier, typename T = LockType, typename = std::enable_if_t<is_lockable_v<T>>> | |
std::optional< BorrowedPointer< GuardedType, LockType > > | try_acquire () const |
Friends | |
template<typename , typename > | |
class | TimedBorrowable |
The Borrowable
is a helper construct that enables callers to borrow an object which is guarded by a lock.
Users who need access to the guarded object can ask to acquire a BorrowedPointer
which permits access while the lock is held.
Thread-safety analysis is not supported for this class, as the BorrowedPointer
s it creates conditionally releases the lock. See also https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#no-conditionally-held-locks
This class is compatible with locks which comply with BasicLockable C++ named requirement. A try_acquire
method is conditionally available if the lock also meets the Lockable requirement. This class is further extended by TimedBorrowable
for locks that meet the TimedLockable requirement.
Borrowable<T>
is covariant with respect to T
, so that Borrowable<U>
can be converted to Borrowable<T>
, if U
is a subclass of T
.
Borrowable
has pointer-like semantics and should be passed by value.
|
inline |
Tries to borrow the object in a non-blocking manner. Returns a BorrowedPointer on success, otherwise std::nullopt
(nothing).