StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::UniqueLock Class Reference

Owns at most one Mutex. More...

#include <StormByte/safe/unique_lock.hxx>

Public Member Functions

 UniqueLock () noexcept
 Empty lock.
 UniqueLock (Mutex &mutex)
 Lock mutex.
 UniqueLock (Mutex &mutex, DeferLock tag) noexcept
 Associate mutex without locking it.
 UniqueLock (Mutex &mutex, TryToLock tag) noexcept
 Try to lock mutex.
 UniqueLock (Mutex &mutex, AdoptLock tag) noexcept
 Assume the calling thread already owns mutex.
 UniqueLock (const UniqueLock &)=delete
 UniqueLock (UniqueLock &&other) noexcept
 Take a lock.
 ~UniqueLock () noexcept
 Unlock if this lock owns the mutex.
UniqueLock & operator= (const UniqueLock &)=delete
UniqueLock & operator= (UniqueLock &&other) noexcept
 Take a lock.
void lock ()
 Acquire the associated mutex.
bool try_lock () noexcept
 Try to acquire the associated mutex.
void unlock () noexcept
 Release ownership.
Mutex * release () noexcept
 Drop the association without unlocking.
Mutex * mutex () const noexcept
 Associated mutex.
bool owns_lock () const noexcept
 Whether this lock owns the mutex.
 operator bool () const noexcept
 Whether this lock owns the mutex.
void swap (UniqueLock &other) noexcept
 Exchange two locks.

Friends

class ConditionVariable

Detailed Description

Owns at most one Mutex.

The wait primitive drops and retakes it.

Header-only. The object is a pointer and an ownership flag. It does not contain a standard lock.

Constructor & Destructor Documentation

◆ UniqueLock() [1/7]

StormByte::Safe::UniqueLock::UniqueLock ( )
inlinenoexcept

Empty lock.

Owns nothing.

◆ UniqueLock() [2/7]

StormByte::Safe::UniqueLock::UniqueLock ( Mutex & mutex)
inlineexplicit

Lock mutex.

Parameters
mutexMutex to acquire.
Exceptions
OperationErrorThe mutex lock translated a foreign failure.

◆ UniqueLock() [3/7]

StormByte::Safe::UniqueLock::UniqueLock ( Mutex & mutex,
DeferLock tag )
inlinenoexcept

Associate mutex without locking it.

Parameters
mutexMutex to lock later.
tagDeferred-lock tag.

◆ UniqueLock() [4/7]

StormByte::Safe::UniqueLock::UniqueLock ( Mutex & mutex,
TryToLock tag )
inlinenoexcept

Try to lock mutex.

Parameters
mutexMutex to try.
tagTry-lock tag.

◆ UniqueLock() [5/7]

StormByte::Safe::UniqueLock::UniqueLock ( Mutex & mutex,
AdoptLock tag )
inlinenoexcept

Assume the calling thread already owns mutex.

Parameters
mutexMutex already owned by this thread.
tagAdopt tag.

◆ UniqueLock() [6/7]

StormByte::Safe::UniqueLock::UniqueLock ( const UniqueLock & )
delete

◆ UniqueLock() [7/7]

StormByte::Safe::UniqueLock::UniqueLock ( UniqueLock && other)
inlinenoexcept

Take a lock.

other owns nothing afterwards.

Parameters
otherSource.

◆ ~UniqueLock()

StormByte::Safe::UniqueLock::~UniqueLock ( )
inlinenoexcept

Unlock if this lock owns the mutex.

Member Function Documentation

◆ lock()

void StormByte::Safe::UniqueLock::lock ( )
inline

Acquire the associated mutex.

Precondition
A mutex is associated and this lock does not own it.
Exceptions
OperationErrorThe mutex lock translated a foreign failure.

◆ mutex()

Mutex * StormByte::Safe::UniqueLock::mutex ( ) const
inlinenoexcept

Associated mutex.

Returns
The mutex, or null.

◆ operator bool()

StormByte::Safe::UniqueLock::operator bool ( ) const
inlineexplicitnoexcept

Whether this lock owns the mutex.

Returns
Ownership flag.

◆ operator=() [1/2]

UniqueLock & StormByte::Safe::UniqueLock::operator= ( const UniqueLock & )
delete

◆ operator=() [2/2]

UniqueLock & StormByte::Safe::UniqueLock::operator= ( UniqueLock && other)
inlinenoexcept

Take a lock.

Unlocks the previous mutex when owned.

Parameters
otherSource. Left not owning.
Returns
This lock.

◆ owns_lock()

bool StormByte::Safe::UniqueLock::owns_lock ( ) const
inlinenoexcept

Whether this lock owns the mutex.

Returns
Ownership flag.

◆ release()

Mutex * StormByte::Safe::UniqueLock::release ( )
inlinenoexcept

Drop the association without unlocking.

Returns
The previous mutex, or null.

◆ swap()

void StormByte::Safe::UniqueLock::swap ( UniqueLock & other)
inlinenoexcept

Exchange two locks.

Parameters
otherOther lock.

◆ try_lock()

bool StormByte::Safe::UniqueLock::try_lock ( )
inlinenoexcept

Try to acquire the associated mutex.

Returns
Whether this lock now owns it. False when no mutex is associated.

◆ unlock()

void StormByte::Safe::UniqueLock::unlock ( )
inlinenoexcept

Release ownership.

Precondition
This lock owns the mutex.

◆ ConditionVariable

friend class ConditionVariable
friend

The documentation for this class was generated from the following file: