68 : m_mutex{
nullptr}, m_owns{
false} {}
76 : m_mutex{&
mutex}, m_owns{false} {
87 : m_mutex{&
mutex}, m_owns{
false} {
97 : m_mutex{&
mutex}, m_owns{mutex.try_lock()} {
107 : m_mutex{&
mutex}, m_owns{
true} {
118 : m_mutex{other.m_mutex}, m_owns{other.m_owns} {
119 other.m_mutex =
nullptr;
120 other.m_owns =
false;
139 if (
this != &other) {
142 m_mutex = other.m_mutex;
143 m_owns = other.m_owns;
144 other.m_mutex =
nullptr;
145 other.m_owns =
false;
165 if (m_mutex ==
nullptr)
167 m_owns = m_mutex->try_lock();
211 explicit operator bool() const noexcept {
221 const bool owns = m_owns;
222 m_mutex = other.m_mutex;
223 m_owns = other.m_owns;
224 other.m_mutex = held;
Owns at most one exclusive hold of a SharedMutex.
Definition exclusive_lock.hxx:62
ExclusiveLock(SharedMutex &mutex, DeferLock tag) noexcept
Associate mutex without locking it.
Definition exclusive_lock.hxx:86
ExclusiveLock(SharedMutex &mutex, AdoptLock tag) noexcept
Assume the calling thread already holds mutex exclusively.
Definition exclusive_lock.hxx:106
ExclusiveLock(ExclusiveLock &&other) noexcept
Take a lock.
Definition exclusive_lock.hxx:117
~ExclusiveLock() noexcept
Drop the exclusive hold if this lock owns it.
Definition exclusive_lock.hxx:126
ExclusiveLock & operator=(ExclusiveLock &&other) noexcept
Take a lock.
Definition exclusive_lock.hxx:138
ExclusiveLock(const ExclusiveLock &)=delete
ExclusiveLock() noexcept
Empty lock.
Definition exclusive_lock.hxx:67
SharedMutex * mutex() const noexcept
Associated mutex.
Definition exclusive_lock.hxx:195
SharedMutex * release() noexcept
Drop the association without unlocking.
Definition exclusive_lock.hxx:184
ExclusiveLock(SharedMutex &mutex)
Take the exclusive hold of mutex.
Definition exclusive_lock.hxx:75
void lock()
Take the exclusive hold of the associated mutex.
Definition exclusive_lock.hxx:155
void swap(ExclusiveLock &other) noexcept
Exchange two locks.
Definition exclusive_lock.hxx:219
ExclusiveLock(SharedMutex &mutex, TryToLock tag) noexcept
Try to take the exclusive hold of mutex.
Definition exclusive_lock.hxx:96
void unlock() noexcept
Drop the exclusive hold.
Definition exclusive_lock.hxx:175
ExclusiveLock & operator=(const ExclusiveLock &)=delete
bool owns_lock() const noexcept
Whether this lock owns the exclusive hold.
Definition exclusive_lock.hxx:203
bool try_lock() noexcept
Try to take the exclusive hold of the associated mutex.
Definition exclusive_lock.hxx:164
Non-recursive shared mutex.
Definition shared_mutex.hxx:60
Owned values that cross a DLL without the caller's CRT.
void swap(Binary &left, Binary &right) noexcept
Exchange two sequences.
Definition binary.hxx:760
Root namespace of the StormByte suite.
The calling thread already owns the mutex.
Definition memory_order.hxx:104
Do not lock the mutex in the UniqueLock constructor.
Definition memory_order.hxx:82
Try to lock the mutex in the UniqueLock constructor.
Definition memory_order.hxx:93
#define STORMBYTE_PUBLIC_TYPE
Definition visibility.h:57