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

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

#include <sharable_lock.hpp>

Public Types

typedef SharableMutex mutex_type
 

Public Member Functions

 sharable_lock ()
 Effects: Default constructs a sharable_lock. More...
 
 sharable_lock (mutex_type &m)
 Effects: m.lock_sharable(). More...
 
 sharable_lock (mutex_type &m, defer_lock_type)
 Postconditions: owns() == false, and mutex() == &m. More...
 
 sharable_lock (mutex_type &m, accept_ownership_type)
 Postconditions: owns() == true, and mutex() == &m. More...
 
 sharable_lock (mutex_type &m, try_to_lock_type)
 Effects: m.try_lock_sharable() Postconditions: mutex() == &m. More...
 
 sharable_lock (mutex_type &m, const boost::posix_time::ptime &abs_time)
 Effects: m.timed_lock_sharable(abs_time) Postconditions: mutex() == &m. More...
 
 sharable_lock (BOOST_RV_REF(sharable_lock< mutex_type >) upgr)
 Postconditions: mutex() == upgr.mutex(). More...
 
template<class T >
sharable_lock (BOOST_RV_REF(upgradable_lock< T >) upgr, typename ipcdetail::enable_if< ipcdetail::is_same< T, SharableMutex > >::type *=0)
 Effects: If upgr.owns() then calls unlock_upgradable_and_lock_sharable() on the referenced mutex. More...
 
template<class T >
 sharable_lock (BOOST_RV_REF(scoped_lock< T >) scop, typename ipcdetail::enable_if< ipcdetail::is_same< T, SharableMutex > >::type *=0)
 Effects: If scop.owns() then calls unlock_and_lock_sharable() on the referenced mutex. More...
 
 ~sharable_lock ()
 Effects: if (owns()) mp_mutex->unlock_sharable(). More...
 
sharable_lockoperator= (BOOST_RV_REF(sharable_lock< mutex_type >) upgr)
 Effects: If owns() before the call, then unlock_sharable() is called on mutex(). More...
 
void lock ()
 Effects: If mutex() == 0 or already locked, throws a lock_exception() exception. More...
 
bool try_lock ()
 Effects: If mutex() == 0 or already locked, throws a lock_exception() exception. More...
 
bool timed_lock (const boost::posix_time::ptime &abs_time)
 Effects: If mutex() == 0 or already locked, throws a lock_exception() exception. More...
 
void unlock ()
 Effects: If mutex() == 0 or 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 (sharable_lock< mutex_type > &other)
 Effects: Swaps state with moved lock. More...
 

Detailed Description

template<class SharableMutex>
class boost::interprocess::sharable_lock< SharableMutex >

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

The Mutex need not supply all of this functionality. If the client of sharable_lock<Mutex> does not use functionality which the Mutex does not supply, no harm is done. Mutex ownership can be shared among sharable_locks, and a single upgradable_lock. sharable_lock does not support copy semantics. But sharable_lock supports ownership transfer from an sharable_lock, upgradable_lock and scoped_lock via transfer_lock syntax.

Member Typedef Documentation

template<class SharableMutex>
typedef SharableMutex boost::interprocess::sharable_lock< SharableMutex >::mutex_type

Constructor & Destructor Documentation

template<class SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::sharable_lock ( )
inline

Effects: Default constructs a sharable_lock.

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

template<class SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::sharable_lock ( mutex_type m)
inlineexplicit

Effects: m.lock_sharable().

Postconditions: owns() == true and mutex() == &m. Notes: The constructor will take sharable-ownership of the mutex. If another thread already owns the mutex with exclusive ownership (scoped_lock), this thread will block until the mutex is released. If another thread owns the mutex with sharable or upgradable ownership, then no blocking will occur. Whether or not this constructor handles recursive locking depends upon the mutex.

template<class SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::sharable_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 SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::sharable_lock ( mutex_type m,
accept_ownership_type   
)
inline

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

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

template<class SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::sharable_lock ( mutex_type m,
try_to_lock_type   
)
inline

Effects: m.try_lock_sharable() Postconditions: mutex() == &m.

owns() == the return value of the m.try_lock_sharable() executed within the constructor. Notes: The constructor will take sharable-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_sharable, this constructor will fail at compile time if instantiated, but otherwise have no effect.

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

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

owns() == the return value of the m.timed_lock_sharable() executed within the constructor. Notes: The constructor will take sharable-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_sharable, this constructor will fail at compile time if instantiated, but otherwise have no effect.

template<class SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::sharable_lock ( BOOST_RV_REF(sharable_lock< mutex_type >)  upgr)
inline

Postconditions: mutex() == upgr.mutex().

owns() == the value of upgr.owns() before the construction. upgr.owns() == false after the construction. Notes: If the upgr sharable_lock owns the mutex, ownership is moved to this sharable_lock with no blocking. If the upgr sharable_lock does not own the mutex, then neither will this sharable_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);". This constructor does not alter the state of the mutex, only potentially who owns it.

template<class SharableMutex>
template<class T >
* boost::interprocess::sharable_lock< SharableMutex >::sharable_lock ( BOOST_RV_REF(upgradable_lock< T >)  upgr,
typename ipcdetail::enable_if< ipcdetail::is_same< T, SharableMutex > >::type = 0 
)
inline

Effects: If upgr.owns() then calls unlock_upgradable_and_lock_sharable() on the referenced mutex.

Postconditions: mutex() == the value upgr.mutex() had before the construction. upgr.mutex() == 0 owns() == the value of upgr.owns() before construction. upgr.owns() == false after the construction. Notes: If upgr is locked, this constructor will lock this sharable_lock while unlocking upgr. Only a moved sharable_lock's will match this signature. An non-moved upgradable_lock can be moved with the expression: "boost::move(lock);".

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

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

Effects: If scop.owns() then calls unlock_and_lock_sharable() on the referenced mutex.

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 a sharable-ownership of this sharable_lock. Only a moved scoped_lock's will match this signature. An non-moved scoped_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 SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::~sharable_lock ( )
inline

Effects: if (owns()) mp_mutex->unlock_sharable().

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

Member Function Documentation

template<class SharableMutex>
void boost::interprocess::sharable_lock< SharableMutex >::lock ( )
inline

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

Calls lock_sharable() 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 SharableMutex>
mutex_type* boost::interprocess::sharable_lock< SharableMutex >::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::upgradable_lock< UpgradableMutex >::upgradable_lock().

template<class SharableMutex>
boost::interprocess::sharable_lock< SharableMutex >::operator unspecified_bool_type ( ) const
inline

Conversion to bool.

Returns owns().

template<class SharableMutex>
sharable_lock& boost::interprocess::sharable_lock< SharableMutex >::operator= ( BOOST_RV_REF(sharable_lock< mutex_type >)  upgr)
inline

Effects: If owns() before the call, then unlock_sharable() 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 lock count will be decremented by one.

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

template<class SharableMutex>
bool boost::interprocess::sharable_lock< SharableMutex >::owns ( ) const
inline
template<class SharableMutex>
mutex_type* boost::interprocess::sharable_lock< SharableMutex >::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::upgradable_lock< UpgradableMutex >::upgradable_lock().

template<class SharableMutex>
void boost::interprocess::sharable_lock< SharableMutex >::swap ( sharable_lock< mutex_type > &  other)
inline

Effects: Swaps state with moved lock.

Throws: Nothing.

References boost::swap.

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

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

Calls timed_lock_sharable(abs_time) on the referenced mutex. Postconditions: owns() == the value returned from mutex()->timed_lock_sharable(elps_time). Notes: The sharable_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 interval. If the mutex_type does not support timed_lock_sharable(), this function will fail at compile time if instantiated, but otherwise have no effect.

template<class SharableMutex>
bool boost::interprocess::sharable_lock< SharableMutex >::try_lock ( )
inline

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

Calls try_lock_sharable() on the referenced mutex. Postconditions: owns() == the value returned from mutex()->try_lock_sharable(). Notes: The sharable_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_sharable(), this function will fail at compile time if instantiated, but otherwise have no effect.

template<class SharableMutex>
void boost::interprocess::sharable_lock< SharableMutex >::unlock ( )
inline

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

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

Referenced by boost::interprocess::sharable_lock< SharableMutex >::operator=().


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