14 template<
class Lockable_>
40 template<
class Rep,
class Period>
42 template<
class Clock,
class Dur>
53 _lock = rhs._lock; _owns = rhs._owns;
54 rhs._lock =
nullptr; rhs._owns =
false;
60 _lock = &rhs.mutex(); _owns =
true;
61 _lock->unlockAndLockShared();
68 assert(_lock,
"Lock has been released");
69 assert(!_owns,
"Lock already held");
76 assert(_lock,
"Lock has been released");
77 assert(_owns,
"Lock not held");
78 _lock->unlockShared();
84 assert(_lock,
"Lock has been released");
85 assert(!_owns,
"Lock already held");
86 return _owns = _lock->tryLockShared();
89 template<
class Rep,
class Period>
92 assert(_lock,
"Lock has been released");
93 assert(!_owns,
"Lock already held");
94 return _owns = _lock->tryLockShared(time);
97 template<
class Clock,
class Dur>
100 assert(_lock,
"Lock has been released");
101 assert(!_owns,
"Lock already held");
102 return _owns = _lock->tryLockShared(time);
105 bool owns()
const {
return _owns; }
106 explicit operator bool()
const {
return owns(); }
110 assert(_lock,
"Lock has been released");
116 Lockable& ret =
mutex();
A scoped lock that references any lockable. Locks on construction and unlocks on destruction.
Definition: Mutex.h:10
TimePoint represented by a duration since a clock's epoch time.
Definition: TimePoint.h:11
bool tryLock(TimePoint< Clock, Dur > time)
Definition: Shared.h:98
bool tryLock(Duration< Rep, Period > time)
Definition: Shared.h:90
bool owns() const
Definition: Shared.h:105
Try to lock (non-blocking)
Lockable & mutex()
Definition: Shared.h:108
SharedLock(UniqueLock< Lockable > &&rhs)
Atomically unlock unique writer lock and acquire shared reader lock without blocking. The unique lock is released.
Definition: Shared.h:47
void unlock()
Definition: Shared.h:74
SharedLock & operator=(UniqueLock< Lockable > &&rhs)
Definition: Shared.h:58
Inherit to declare that class is not copyable.
Definition: Meta.h:286
SharedLock(Lockable &lock, Duration< Rep, Period > time)
Definition: Shared.h:41
SharedLock(Lockable &lock, TimePoint< Clock, Dur > time)
Definition: Shared.h:43
SharedLock(Lockable &lock, lock::Op op=lock::Op::lock)
Definition: Shared.h:22
SharedLock(SharedLock &&rhs) noexcept
Definition: Shared.h:45
void lock()
Definition: Shared.h:66
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Lockable & release()
Definition: Shared.h:114
Not yet locked, will lock manually.
bool tryLock()
Definition: Shared.h:82
~SharedLock()
Definition: Shared.h:49
Duration represented by repetitions of a period. The period must be a ratio.
Definition: Duration.h:7
SharedLock & operator=(SharedLock &&rhs)
Definition: Shared.h:51
Op
Definition: Unique.h:16
SharedLock()
Definition: Shared.h:20
A scoped lock that references a shared mutex. Does a shared read lock on construction and unlocks on ...
Definition: Shared.h:15
Global Honeycomb namespace.
Lockable_ Lockable
Definition: Shared.h:18