12 template<
class Lockable>
class SharedLock;
27 function<void ()>
lockGuard(Lock&
lock) {
return [&] { lock.lock(); }; }
40 template<
class Lockable_>
41 class UniqueLock : mt::NoCopy
67 template<
class Rep,
class Period>
69 template<
class Clock,
class Dur>
81 _lock = rhs._lock; _owns = rhs._owns;
82 rhs._lock =
nullptr; rhs._owns =
false;
88 _lock = &rhs.mutex(); _owns =
true;
89 _lock->unlockShared();
97 assert(_lock,
"Lock has been released");
98 assert(!_owns,
"Lock already held");
105 assert(_lock,
"Lock has been released");
106 assert(_owns,
"Lock not held");
113 assert(_lock,
"Lock has been released");
114 assert(!_owns,
"Lock already held");
115 return _owns = _lock->tryLock();
118 template<
class Rep,
class Period>
121 assert(_lock,
"Lock has been released");
122 assert(!_owns,
"Lock already held");
123 return _owns = _lock->tryLock(time);
126 template<
class Clock,
class Dur>
129 assert(_lock,
"Lock has been released");
130 assert(!_owns,
"Lock already held");
131 return _owns = _lock->tryLock(time);
135 bool owns()
const {
return _owns; }
137 explicit operator bool()
const {
return owns(); }
142 assert(_lock,
"Lock has been released");
149 Lockable& ret =
mutex();
Lockable & mutex()
Get the referenced mutex.
Definition: Unique.h:140
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 owns() const
Check if mutex is locked by this instance.
Definition: Unique.h:135
~UniqueLock()
Unlock the mutex if we own it.
Definition: Unique.h:77
function< void()> releaseGuard(Lock &lock)
Definition: Unique.h:31
Try to lock (non-blocking)
void lock(Locks &&...locks)
Lock all lockables safely without deadlocking.
Definition: Util.h:110
UniqueLock(Lockable &lock, Duration< Rep, Period > time)
Definition: Unique.h:68
UniqueLock(Lockable &lock, TimePoint< Clock, Dur > time)
Definition: Unique.h:70
UniqueLock(UniqueLock &&rhs) noexcept
Definition: Unique.h:72
Lockable & release()
Release the mutex from further operations. The mutex will no longer be owned and its state will remai...
Definition: Unique.h:147
UniqueLock(SharedLock< Lockable > &&rhs)
Unlock shared lock (reader) and block until unique lock (writer) is acquired. The shared lock is rele...
Definition: Unique.h:74
bool tryLock(TimePoint< Clock, Dur > time)
Definition: Unique.h:127
function< void()> lockGuard(Lock &lock)
Definition: Unique.h:27
void unlock()
Definition: Unique.h:103
UniqueLock(Lockable &lock, lock::Op op=lock::Op::lock)
Construct with a reference to a mutex and an operation to perform on construction.
Definition: Unique.h:49
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Lockable_ Lockable
Definition: Unique.h:44
Not yet locked, will lock manually.
void lock()
Definition: Unique.h:95
Duration represented by repetitions of a period. The period must be a ratio.
Definition: Duration.h:7
bool tryLock()
Definition: Unique.h:111
function< void()> unlockGuard(Lock &lock)
Definition: Unique.h:29
Op
Definition: Unique.h:16
UniqueLock & operator=(UniqueLock &&rhs)
Definition: Unique.h:79
bool tryLock(Duration< Rep, Period > time)
Definition: Unique.h:119
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.
UniqueLock & operator=(SharedLock< Lockable > &&rhs)
Definition: Unique.h:86
UniqueLock()
Definition: Unique.h:46