Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::interprocess::upgradable_lock< UpgradableMutex > Class Template Reference

upgradable_lock is meant to carry out the tasks for read-locking, unlocking, try-read-locking and timed-read-locking (recursive or not) for the Mutex. More...

#include <upgradable_lock.hpp>

Public Types

typedef UpgradableMutex mutex_type
 

Public Member Functions

 upgradable_lock ()
 Effects: Default constructs a upgradable_lock. More...
 
 upgradable_lock (mutex_type &m)
 
 upgradable_lock (mutex_type &m, defer_lock_type)
 Postconditions: owns() == false, and mutex() == &m. More...
 
 upgradable_lock (mutex_type &m, accept_ownership_type)
 Postconditions: owns() == true, and mutex() == &m. More...
 
 upgradable_lock (mutex_type &m, try_to_lock_type)
 Effects: m.try_lock_upgradable(). More...
 
 upgradable_lock (mutex_type &m, const boost::posix_time::ptime &abs_time)
 Effects: m.timed_lock_upgradable(abs_time) Postconditions: mutex() == &m. More...
 
 upgradable_lock (BOOST_RV_REF(upgradable_lock< mutex_type >) upgr)
 Effects: No effects on the underlying mutex. More...
 
template<class T >
 upgradable_lock (BOOST_RV_REF(scoped_lock< T >) scop, typename ipcdetail::enable_if< ipcdetail::is_same< T, UpgradableMutex > >::type *=0)
 Effects: If scop.owns(), m_.unlock_and_lock_upgradable(). More...
 
template<class T >
 upgradable_lock (BOOST_RV_REF(sharable_lock< T >) shar, try_to_lock_type, typename ipcdetail::enable_if< ipcdetail::is_same< T, UpgradableMutex > >::type *=0)
 Effects: If shar.owns() then calls try_unlock_sharable_and_lock_upgradable() on the referenced mutex. More...
 
 ~upgradable_lock ()
 Effects: if (owns()) m_->unlock_upgradable(). More...
 
upgradable_lockoperator= (BOOST_RV_REF(upgradable_lock) upgr)
 Effects: If owns(), then unlock_upgradable() is called on mutex(). More...
 
void lock ()
 Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception. More...
 
bool try_lock ()
 Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception. More...
 
bool timed_lock (const boost::posix_time::ptime &abs_time)
 Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception. More...
 
void unlock ()
 Effects: If mutex() == 0 or if not locked, throws a lock_exception() exception. More...
 
bool owns () const
 Effects: Returns true if this scoped_lock has acquired the referenced mutex. More...
 
 operator unspecified_bool_type () const
 Conversion to bool. More...
 
mutex_typemutex () const
 Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference. More...
 
mutex_typerelease ()
 Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference. More...
 
void swap (upgradable_lock< mutex_type > &other)
 Effects: Swaps state with moved lock. More...
 

Detailed Description

template<class UpgradableMutex>
class boost::interprocess::upgradable_lock< UpgradableMutex >

upgradable_lock is meant to carry out the tasks for read-locking, unlocking, try-read-locking and timed-read-locking (recursive or not) for the Mutex.

Additionally the upgradable_lock can transfer ownership to a scoped_lock using transfer_lock syntax. The Mutex need not supply all of the functionality. If the client of upgradable_lock<Mutex> does not use functionality which the Mutex does not supply, no harm is done. Mutex ownership can be shared among read_locks, and a single upgradable_lock. upgradable_lock does not support copy semantics. However upgradable_lock supports ownership transfer from a upgradable_locks or scoped_locks via transfer_lock syntax.

Member Typedef Documentation

template<class UpgradableMutex>
typedef UpgradableMutex boost::interprocess::upgradable_lock< UpgradableMutex >::mutex_type

Constructor & Destructor Documentation

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( )
inline

Effects: Default constructs a upgradable_lock.

Postconditions: owns() == false and mutex() == 0.

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( mutex_type m)
inlineexplicit
template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( mutex_type m,
defer_lock_type   
)
inline

Postconditions: owns() == false, and mutex() == &m.

Notes: The constructor will not take ownership of the mutex. There is no effect required on the referenced mutex.

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( mutex_type m,
accept_ownership_type   
)
inline

Postconditions: owns() == true, and mutex() == &m.

Notes: The constructor will suppose that the mutex is already upgradable locked. There is no effect required on the referenced mutex.

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( mutex_type m,
try_to_lock_type   
)
inline

Effects: m.try_lock_upgradable().

Postconditions: mutex() == &m. owns() == the return value of the m.try_lock_upgradable() executed within the constructor. Notes: The constructor will take upgradable-ownership of the mutex if it can do so without waiting. Whether or not this constructor handles recursive locking depends upon the mutex. If the mutex_type does not support try_lock_upgradable, this constructor will fail at compile time if instantiated, but otherwise have no effect.

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( mutex_type m,
const boost::posix_time::ptime abs_time 
)
inline

Effects: m.timed_lock_upgradable(abs_time) Postconditions: mutex() == &m.

owns() == the return value of the m.timed_lock_upgradable() executed within the constructor. Notes: The constructor will take upgradable-ownership of the mutex if it can do so within the time specified. Whether or not this constructor handles recursive locking depends upon the mutex. If the mutex_type does not support timed_lock_upgradable, this constructor will fail at compile time if instantiated, but otherwise have no effect.

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( BOOST_RV_REF(upgradable_lock< mutex_type >)  upgr)
inline

Effects: No effects on the underlying mutex.

Postconditions: mutex() == the value upgr.mutex() had before the construction. upgr.mutex() == 0. owns() == upgr.owns() before the construction. upgr.owns() == false. Notes: If upgr is locked, this constructor will lock this upgradable_lock while unlocking upgr. If upgr is unlocked, then this upgradable_lock will be unlocked as well. Only a moved upgradable_lock's will match this signature. An non-moved upgradable_lock can be moved with the expression: "boost::move(lock);". This constructor does not alter the state of the mutex, only potentially who owns it.

template<class UpgradableMutex>
template<class T >
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( BOOST_RV_REF(scoped_lock< T >)  scop,
typename ipcdetail::enable_if< ipcdetail::is_same< T, UpgradableMutex > >::type = 0 
)
inline

Effects: If scop.owns(), m_.unlock_and_lock_upgradable().

Postconditions: mutex() == the value scop.mutex() had before the construction. scop.mutex() == 0. owns() == scop.owns() before the constructor. After the construction, scop.owns() == false. Notes: If scop is locked, this constructor will transfer the exclusive-ownership to an upgradable-ownership of this upgradable_lock. Only a moved sharable_lock's will match this signature. An non-moved sharable_lock can be moved with the expression: "boost::move(lock);".

References boost::interprocess::scoped_lock< Mutex >::mutex(), boost::interprocess::scoped_lock< Mutex >::owns(), and boost::interprocess::scoped_lock< Mutex >::release().

template<class UpgradableMutex>
template<class T >
boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock ( BOOST_RV_REF(sharable_lock< T >)  shar,
try_to_lock_type  ,
typename ipcdetail::enable_if< ipcdetail::is_same< T, UpgradableMutex > >::type = 0 
)
inline

Effects: If shar.owns() then calls try_unlock_sharable_and_lock_upgradable() on the referenced mutex.

a)if try_unlock_sharable_and_lock_upgradable() returns true then mutex() obtains the value from shar.release() and owns() is set to true. b)if try_unlock_sharable_and_lock_upgradable() returns false then shar is unaffected and this upgradable_lock construction has the same effects as a default construction. c)Else shar.owns() is false. mutex() obtains the value from shar.release() and owns() is set to false. Notes: This construction will not block. It will try to obtain mutex ownership from shar immediately, while changing the lock type from a "read lock" to an "upgradable lock". If the "read lock" isn't held in the first place, the mutex merely changes type to an unlocked "upgradable lock". If the "read lock" is held, then mutex transfer occurs only if it can do so in a non-blocking manner.

References boost::interprocess::sharable_lock< SharableMutex >::mutex(), boost::interprocess::sharable_lock< SharableMutex >::owns(), and boost::interprocess::sharable_lock< SharableMutex >::release().

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::~upgradable_lock ( )
inline

Effects: if (owns()) m_->unlock_upgradable().

Notes: The destructor behavior ensures that the mutex lock is not leaked.

Member Function Documentation

template<class UpgradableMutex>
void boost::interprocess::upgradable_lock< UpgradableMutex >::lock ( void  )
inline

Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception.

Calls lock_upgradable() on the referenced mutex. Postconditions: owns() == true. Notes: The sharable_lock changes from a state of not owning the mutex, to owning the mutex, blocking if necessary.

template<class UpgradableMutex>
mutex_type* boost::interprocess::upgradable_lock< UpgradableMutex >::mutex ( ) const
inline

Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference.

Referenced by boost::interprocess::scoped_lock< Mutex >::scoped_lock(), and boost::interprocess::sharable_lock< SharableMutex >::sharable_lock().

template<class UpgradableMutex>
boost::interprocess::upgradable_lock< UpgradableMutex >::operator unspecified_bool_type ( ) const
inline

Conversion to bool.

Returns owns().

template<class UpgradableMutex>
upgradable_lock& boost::interprocess::upgradable_lock< UpgradableMutex >::operator= ( BOOST_RV_REF(upgradable_lock< UpgradableMutex >)  upgr)
inline

Effects: If owns(), then unlock_upgradable() is called on mutex().

*this gets the state of upgr and upgr gets set to a default constructed state. Notes: With a recursive mutex it is possible that both this and upgr own the mutex before the assignment. In this case, this will own the mutex after the assignment (and upgr will not), but the mutex's upgradable lock count will be decremented by one.

References boost::interprocess::upgradable_lock< UpgradableMutex >::owns(), and boost::interprocess::upgradable_lock< UpgradableMutex >::unlock().

template<class UpgradableMutex>
bool boost::interprocess::upgradable_lock< UpgradableMutex >::owns ( ) const
inline
template<class UpgradableMutex>
mutex_type* boost::interprocess::upgradable_lock< UpgradableMutex >::release ( )
inline

Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference.

Postconditions: mutex() == 0 and owns() == false.

Referenced by boost::interprocess::scoped_lock< Mutex >::scoped_lock(), and boost::interprocess::sharable_lock< SharableMutex >::sharable_lock().

template<class UpgradableMutex>
void boost::interprocess::upgradable_lock< UpgradableMutex >::swap ( upgradable_lock< mutex_type > &  other)
inline

Effects: Swaps state with moved lock.

Throws: Nothing.

References boost::swap.

template<class UpgradableMutex>
bool boost::interprocess::upgradable_lock< UpgradableMutex >::timed_lock ( const boost::posix_time::ptime abs_time)
inline

Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception.

Calls timed_lock_upgradable(abs_time) on the referenced mutex. Postconditions: owns() == the value returned from mutex()->timed_lock_upgradable(abs_time). Notes: The upgradable_lock changes from a state of not owning the mutex, to owning the mutex, but only if it can obtain ownership within the specified time. If the mutex_type does not support timed_lock_upgradable(abs_time), this function will fail at compile time if instantiated, but otherwise have no effect.

template<class UpgradableMutex>
bool boost::interprocess::upgradable_lock< UpgradableMutex >::try_lock ( void  )
inline

Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception.

Calls try_lock_upgradable() on the referenced mutex. Postconditions: owns() == the value returned from mutex()->try_lock_upgradable(). Notes: The upgradable_lock changes from a state of not owning the mutex, to owning the mutex, but only if blocking was not required. If the mutex_type does not support try_lock_upgradable(), this function will fail at compile time if instantiated, but otherwise have no effect.

template<class UpgradableMutex>
void boost::interprocess::upgradable_lock< UpgradableMutex >::unlock ( void  )
inline

Effects: If mutex() == 0 or if not locked, throws a lock_exception() exception.

Calls unlock_upgradable() on the referenced mutex. Postconditions: owns() == false. Notes: The upgradable_lock changes from a state of owning the mutex, to not owning the mutex.

Referenced by boost::interprocess::upgradable_lock< UpgradableMutex >::operator=().


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