fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
boost::fairness::unique_lock< Lockable > Class Template Reference

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_lockoperator= (const unique_lock &)=delete
 
unique_lockoperator= (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.
 

Detailed Description

template<typename Lockable>
class boost::fairness::unique_lock< Lockable >

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.

Template Parameters
Lockable: the type of the mutex to lock. The type must meet the BasicLockable requirements.

Constructor & Destructor Documentation

◆ unique_lock() [1/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( )
inlinenoexcept

Construct a new unique lock object.

◆ unique_lock() [2/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
Priority_t const  p = BOOST_FAIRNESS_MINIMUM_PRIORITY 
)
inlineexplicit

Construct a new unique lock object.

Parameters
m
p

◆ unique_lock() [3/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
defer_lock_t   
)
inlinenoexcept

Construct a new unique lock object.

Parameters
m

◆ unique_lock() [4/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
Priority_t const  p,
try_to_lock_t   
)
inline

Construct a new unique lock object.

Parameters
m
p

◆ unique_lock() [5/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
try_to_lock_t   
)
inline

Construct a new unique lock object.

Parameters
m

◆ unique_lock() [6/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
Priority_t const  p,
adopt_lock_t   
)
inlinenoexcept

Construct a new unique lock object.

Parameters
m
p

◆ unique_lock() [7/10]

template<typename Lockable >
template<typename Clock , typename Duration >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
const std::chrono::time_point< Clock, Duration > &  atime,
Priority_t  p = BOOST_FAIRNESS_MINIMUM_PRIORITY 
)
inline

Construct a new unique lock object.

Template Parameters
Clock
Duration
Parameters
m
atime
p

◆ unique_lock() [8/10]

template<typename Lockable >
template<typename Rep , typename Period >
boost::fairness::unique_lock< Lockable >::unique_lock ( Lockable &  m,
const std::chrono::duration< Rep, Period > &  rtime,
Priority_t  p = BOOST_FAIRNESS_MINIMUM_PRIORITY 
)
inline

Construct a new unique lock object.

Template Parameters
Rep
Period
Parameters
m
rtime
p

◆ ~unique_lock()

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::~unique_lock ( )
inline

Destroy the unique lock object.

◆ unique_lock() [9/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( const unique_lock< Lockable > &  )
delete

◆ unique_lock() [10/10]

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::unique_lock ( unique_lock< Lockable > &&  other)
inlinenoexcept

Construct a new unique lock object.

Parameters
other

Member Function Documentation

◆ lock()

template<typename Lockable >
void boost::fairness::unique_lock< Lockable >::lock ( Priority_t const  p = BOOST_FAIRNESS_MINIMUM_PRIORITY)
inline

Locks the associated mutex. Effectively calls mutex()->lock().

Parameters
p: the priority of the mutex.
Returns
none.
Exceptions

◆ lock_priority()

template<typename Lockable >
Priority_t boost::fairness::unique_lock< Lockable >::lock_priority ( ) const
inlinenoexcept

TODO.

Returns
Priority_t

◆ mutex()

template<typename Lockable >
Lockable * boost::fairness::unique_lock< Lockable >::mutex ( ) const
inlinenoexcept
Returns
Lockable*

◆ operator bool()

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::operator bool ( ) const
inlineexplicitnoexcept

Checks whether *this owns a locked mutex or not. Effectively calls owns_lock().

Parameters
none.
Returns
true : if *this has an associated mutex and has acquired ownership of it.
false : otherwise.

◆ operator Priority_t()

template<typename Lockable >
boost::fairness::unique_lock< Lockable >::operator Priority_t ( ) const
inlineexplicitnoexcept

TODO.

Returns
Priority_t

◆ operator=() [1/2]

template<typename Lockable >
unique_lock & boost::fairness::unique_lock< Lockable >::operator= ( const unique_lock< Lockable > &  )
delete

◆ operator=() [2/2]

template<typename Lockable >
unique_lock & boost::fairness::unique_lock< Lockable >::operator= ( unique_lock< Lockable > &&  other)
inlinenoexcept
Parameters
other
Returns
unique_lock&

◆ owns_lock()

template<typename Lockable >
bool boost::fairness::unique_lock< Lockable >::owns_lock ( ) const
inlinenoexcept

Checks whether *this owns a locked mutex or not.

Parameters
none.
Returns
true : if *this has an associated mutex and has acquired ownership of it.
false : otherwise.

◆ release()

template<typename Lockable >
Lockable * boost::fairness::unique_lock< Lockable >::release ( )
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.

Parameters
none.
Returns
Lockable* : pointer to the associated mutex or a null pointer if there was no associated mutex.

◆ swap()

template<typename Lockable >
void boost::fairness::unique_lock< Lockable >::swap ( unique_lock< Lockable > &  other)
inlinenoexcept

Exchanges the internal states of the lock objects.

Parameters
other: the lock to swap the state with.
Returns
none.

◆ try_lock()

template<typename Lockable >
bool boost::fairness::unique_lock< Lockable >::try_lock ( Priority_t const  p = BOOST_FAIRNESS_MINIMUM_PRIORITY)
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.

Parameters
p: the current priority.
Returns
true if the ownership of the mutex has been acquired successfully.
false otherwise.
Exceptions

◆ try_lock_for()

template<typename Lockable >
template<typename Rep , typename Period >
bool boost::fairness::unique_lock< Lockable >::try_lock_for ( const std::chrono::duration< Rep, Period > &  rtime,
Priority_t const  p = BOOST_FAIRNESS_MINIMUM_PRIORITY 
)
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.

Template Parameters
ClockTODO
DurationTODO
Parameters
rtime: maximum duration to block for
p: the current priority.
Returns
true : if the ownership of the mutex has been acquired successfully.
false : otherwise.
Exceptions

◆ try_lock_until()

template<typename Lockable >
template<typename Clock , typename Duration >
bool boost::fairness::unique_lock< Lockable >::try_lock_until ( const std::chrono::time_point< Clock, Duration > &  atime,
Priority_t const  p = BOOST_FAIRNESS_MINIMUM_PRIORITY 
)
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.

Template Parameters
ClockTODO
DurationTODO
Parameters
atime: maximum time point to block until
p: the current priority.
Returns
true : if the ownership of the mutex has been acquired successfully.
false : otherwise.
Exceptions

◆ unlock()

template<typename Lockable >
void boost::fairness::unique_lock< Lockable >::unlock ( )
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.

Parameters
none.
Returns
none.
Exceptions

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