fairness
v1.0.0
A collection of advanced syncronization mechanisms.
|
The class unique_lock is a general-purpose mutex ownership wrapper allowing deferred locking, time-constrained attempts at locking, recursive locking, transfer of lock ownership, and use with condition variables.
The class unique_lock is movable, but not copyable – it meets the requirements of MoveConstructible and MoveAssignable but not of CopyConstructible or CopyAssignable.
The class unique_lock meets the BasicLockable requirements. If Lockable meets the Lockable requirements, unique_lock also meets the Lockable requirements (ex.: can be used in boost::fairness::lock); if Lockable meets the TimedLockable requirements, unique_lock also meets the TimedLockable requirements.
More...
#include <unique_lock.hpp>
Public Member Functions | |
void | lock (Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY) |
Locks the associated mutex. Effectively calls mutex()->lock() . | |
Priority_t | lock_priority () const noexcept |
TODO. | |
Lockable * | mutex () const noexcept |
operator bool () const noexcept | |
Checks whether *this owns a locked mutex or not. Effectively calls owns_lock(). | |
operator Priority_t () const noexcept | |
TODO. | |
unique_lock & | operator= (const unique_lock &)=delete |
unique_lock & | operator= (unique_lock &&other) noexcept |
bool | owns_lock () const noexcept |
Checks whether *this owns a locked mutex or not. | |
Lockable * | release () noexcept |
Breaks the association of the associated mutex, if any, and *this . No locks are unlocked. If *this held ownership of the associated mutex prior to the call, the caller is now responsible to unlock the mutex. | |
void | swap (unique_lock &other) noexcept |
Exchanges the internal states of the lock objects. | |
bool | try_lock (Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY) |
Tries to lock (i.e., takes ownership of) the associated mutex without blocking. Effectively calls mutex()->try_lock(). std::system_error is thrown if there is no associated mutex or if the mutex is already locked. | |
template<typename Rep , typename Period > | |
bool | try_lock_for (const std::chrono::duration< Rep, Period > &rtime, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY) |
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified rtime has elapsed or the lock is acquired, whichever comes first. On successful lock acquisition returns true , otherwise returns false .Effectively calls mutex()->try_lock_for(rtime) . This function may block for longer than rtime due to scheduling or resource contention delays. The standard recommends that a steady clock is used to measure the duration. If an implementation uses a system clock instead, the wait time may also be sensitive to clock adjustments. std::system_error is thrown if there is no associated mutex or if the mutex is already locked by this std::unique_lock. | |
template<typename Clock , typename Duration > | |
bool | try_lock_until (const std::chrono::time_point< Clock, Duration > &atime, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY) |
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified atime has been reached or the lock is acquired, whichever comes first. On successful lock acquisition returns true , otherwise returns false . May block for longer than atime until has been reached. Effectively calls mutex()->try_lock_until(atime) . std::system_error is thrown if there is no associated mutex or if the mutex is already locked by the same thread. Clock must meet the Clock requirements. The program is ill-formed if std::chrono::is_clock_v<Clock> is false . | |
unique_lock () noexcept | |
Construct a new unique lock object. | |
unique_lock (const unique_lock &)=delete | |
template<typename Rep , typename Period > | |
unique_lock (Lockable &m, const std::chrono::duration< Rep, Period > &rtime, Priority_t p=BOOST_FAIRNESS_MINIMUM_PRIORITY) | |
Construct a new unique lock object. | |
template<typename Clock , typename Duration > | |
unique_lock (Lockable &m, const std::chrono::time_point< Clock, Duration > &atime, Priority_t p=BOOST_FAIRNESS_MINIMUM_PRIORITY) | |
Construct a new unique lock object. | |
unique_lock (Lockable &m, defer_lock_t) noexcept | |
Construct a new unique lock object. | |
unique_lock (Lockable &m, Priority_t const p, adopt_lock_t) noexcept | |
Construct a new unique lock object. | |
unique_lock (Lockable &m, Priority_t const p, try_to_lock_t) | |
Construct a new unique lock object. | |
unique_lock (Lockable &m, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY) | |
Construct a new unique lock object. | |
unique_lock (Lockable &m, try_to_lock_t) | |
Construct a new unique lock object. | |
unique_lock (unique_lock &&other) noexcept | |
Construct a new unique lock object. | |
void | unlock () |
Unlocks (i.e., releases ownership of) the associated mutex and releases ownership. std::system_error is thrown if there is no associated mutex or if the mutex is not locked. | |
~unique_lock () | |
Destroy the unique lock object. | |
The class unique_lock is a general-purpose mutex ownership wrapper allowing deferred locking, time-constrained attempts at locking, recursive locking, transfer of lock ownership, and use with condition variables.
The class unique_lock is movable, but not copyable – it meets the requirements of MoveConstructible and MoveAssignable but not of CopyConstructible or CopyAssignable.
The class unique_lock meets the BasicLockable requirements. If Lockable meets the Lockable requirements, unique_lock also meets the Lockable requirements (ex.: can be used in boost::fairness::lock); if Lockable meets the TimedLockable requirements, unique_lock also meets the TimedLockable requirements.
Lockable | : the type of the mutex to lock. The type must meet the BasicLockable requirements. |
|
inlinenoexcept |
Construct a new unique lock object.
|
inlineexplicit |
Construct a new unique lock object.
m | |
p |
|
inlinenoexcept |
Construct a new unique lock object.
m |
|
inline |
Construct a new unique lock object.
m | |
p |
|
inline |
Construct a new unique lock object.
m |
|
inlinenoexcept |
Construct a new unique lock object.
m | |
p |
|
inline |
Construct a new unique lock object.
Clock | |
Duration |
m | |
atime | |
p |
|
inline |
Construct a new unique lock object.
Rep | |
Period |
m | |
rtime | |
p |
|
inline |
Destroy the unique lock object.
|
delete |
|
inlinenoexcept |
Construct a new unique lock object.
other |
|
inline |
Locks the associated mutex. Effectively calls mutex()->lock()
.
p | : the priority of the mutex. |
mutex()->lock()
;
|
inlinenoexcept |
TODO.
|
inlinenoexcept |
|
inlineexplicitnoexcept |
Checks whether *this
owns a locked mutex or not. Effectively calls owns_lock().
none. |
*this
has an associated mutex and has acquired ownership of it.
|
inlineexplicitnoexcept |
TODO.
|
delete |
|
inlinenoexcept |
other |
|
inlinenoexcept |
Checks whether *this
owns a locked mutex or not.
none. |
*this
has an associated mutex and has acquired ownership of it.
|
inlinenoexcept |
Breaks the association of the associated mutex, if any, and *this
.
No locks are unlocked. If *this
held ownership of the associated mutex prior to the call, the caller is now responsible to unlock the mutex.
none. |
|
inlinenoexcept |
Exchanges the internal states of the lock objects.
other | : the lock to swap the state with. |
|
inline |
Tries to lock (i.e., takes ownership of) the associated mutex without blocking. Effectively calls mutex()->try_lock().
std::system_error is thrown if there is no associated mutex or if the mutex is already locked.
p | : the current priority. |
true
if the ownership of the mutex has been acquired successfully. false
otherwise.mutex()->lock()
(Mutex types do not throw in try_lock, but a custom Lockable might);
|
inline |
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified rtime has elapsed or the lock is acquired, whichever comes first. On successful lock acquisition returns true
, otherwise returns false
.Effectively calls mutex()->try_lock_for(rtime)
.
This function may block for longer than rtime due to scheduling or resource contention delays.
The standard recommends that a steady clock is used to measure the duration. If an implementation uses a system clock instead, the wait time may also be sensitive to clock adjustments.
std::system_error is thrown if there is no associated mutex or if the mutex is already locked by this std::unique_lock.
Clock | TODO |
Duration | TODO |
rtime | : maximum duration to block for |
p | : the current priority. |
true
: if the ownership of the mutex has been acquired successfully. false
: otherwise. mutex()->try_lock_for(rtime)
;
|
inline |
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified atime has been reached or the lock is acquired, whichever comes first. On successful lock acquisition returns true
, otherwise returns false
. May block for longer than atime until has been reached.
Effectively calls mutex()->try_lock_until(atime)
.
std::system_error is thrown if there is no associated mutex or if the mutex is already locked by the same thread.
Clock must meet the Clock requirements. The program is ill-formed if std::chrono::is_clock_v<Clock> is false
.
Clock | TODO |
Duration | TODO |
atime | : maximum time point to block until |
p | : the current priority. |
true
: if the ownership of the mutex has been acquired successfully. false
: otherwise. mutex()->try_lock_until(atime)
;
|
inline |
Unlocks (i.e., releases ownership of) the associated mutex and releases ownership.
std::system_error is thrown if there is no associated mutex or if the mutex is not locked.
none. |
mutex()->unlock()
;