scoped_lock is meant to carry out the tasks for locking, unlocking, try-locking and timed-locking (recursive or not) for the Mutex. More...
#include <scoped_lock.hpp>
Public Types | |
typedef Mutex | mutex_type |
Public Member Functions | |
scoped_lock () | |
Effects: Default constructs a scoped_lock. More... | |
scoped_lock (mutex_type &m) | |
Effects: m.lock(). More... | |
scoped_lock (mutex_type &m, defer_lock_type) | |
Postconditions: owns() == false, and mutex() == &m. More... | |
scoped_lock (mutex_type &m, accept_ownership_type) | |
Postconditions: owns() == true, and mutex() == &m. More... | |
scoped_lock (mutex_type &m, try_to_lock_type) | |
Effects: m.try_lock(). More... | |
scoped_lock (mutex_type &m, const boost::posix_time::ptime &abs_time) | |
Effects: m.timed_lock(abs_time). More... | |
scoped_lock (BOOST_RV_REF(scoped_lock) scop) | |
Postconditions: mutex() == the value scop.mutex() had before the constructor executes. More... | |
template<class T > | |
scoped_lock (BOOST_RV_REF(upgradable_lock< T >) upgr, typename ipcdetail::enable_if< ipcdetail::is_same< T, Mutex > >::type *=0) | |
Effects: If upgr.owns() then calls unlock_upgradable_and_lock() on the referenced mutex. More... | |
template<class T > | |
scoped_lock (BOOST_RV_REF(upgradable_lock< T >) upgr, try_to_lock_type, typename ipcdetail::enable_if< ipcdetail::is_same< T, Mutex > >::type *=0) | |
Effects: If upgr.owns() then calls try_unlock_upgradable_and_lock() on the referenced mutex: a)if try_unlock_upgradable_and_lock() returns true then mutex() obtains the value from upgr.release() and owns() is set to true. More... | |
template<class T > | |
scoped_lock (BOOST_RV_REF(upgradable_lock< T >) upgr, boost::posix_time::ptime &abs_time, typename ipcdetail::enable_if< ipcdetail::is_same< T, Mutex > >::type *=0) | |
Effects: If upgr.owns() then calls timed_unlock_upgradable_and_lock(abs_time) on the referenced mutex: a)if timed_unlock_upgradable_and_lock(abs_time) returns true then mutex() obtains the value from upgr.release() and owns() is set to true. More... | |
template<class T > | |
scoped_lock (BOOST_RV_REF(sharable_lock< T >) shar, try_to_lock_type, typename ipcdetail::enable_if< ipcdetail::is_same< T, Mutex > >::type *=0) | |
Effects: If shar.owns() then calls try_unlock_sharable_and_lock() on the referenced mutex. More... | |
* | ~scoped_lock () |
Effects: if (owns()) mp_mutex->unlock(). More... | |
scoped_lock & | operator= (BOOST_RV_REF(scoped_lock) scop) |
Effects: If owns() before the call, then unlock() 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_type * | mutex () const |
Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference. More... | |
mutex_type * | release () |
Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference. More... | |
void | swap (scoped_lock< mutex_type > &other) |
Effects: Swaps state with moved lock. More... | |
scoped_lock is meant to carry out the tasks for locking, unlocking, try-locking and timed-locking (recursive or not) for the Mutex.
The Mutex need not supply all of this functionality. If the client of scoped_lock<Mutex> does not use functionality which the Mutex does not supply, no harm is done. Mutex ownership transfer is supported through the syntax of move semantics. Ownership transfer is allowed both by construction and assignment. The scoped_lock does not support copy semantics. A compile time error results if copy construction or copy assignment is attempted. Mutex ownership can also be moved from an upgradable_lock and sharable_lock via constructor. In this role, scoped_lock shares the same functionality as a write_lock.
typedef Mutex boost::interprocess::scoped_lock< Mutex >::mutex_type |
|
inline |
Effects: Default constructs a scoped_lock.
|
inlineexplicit |
Effects: m.lock().
Postconditions: owns() == true and mutex() == &m. Notes: The constructor will take ownership of the mutex. If another thread already owns the mutex, this thread will block until the mutex is released. Whether or not this constructor handles recursive locking depends upon the mutex.
|
inline |
|
inline |
|
inline |
Effects: m.try_lock().
Postconditions: mutex() == &m. owns() == the return value of the m.try_lock() executed within the constructor. Notes: The constructor will take 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, this constructor will fail at compile time if instantiated, but otherwise have no effect.
|
inline |
Effects: m.timed_lock(abs_time).
Postconditions: mutex() == &m. owns() == the return value of the m.timed_lock(abs_time) executed within the constructor. Notes: The constructor will take ownership of the mutex if it can do it until abs_time is reached. Whether or not this constructor handles recursive locking depends upon the mutex. If the mutex_type does not support try_lock, this constructor will fail at compile time if instantiated, but otherwise have no effect.
|
inline |
Postconditions: mutex() == the value scop.mutex() had before the constructor executes.
s1.mutex() == 0. owns() == the value of scop.owns() before the constructor executes. scop.owns(). Notes: If the scop scoped_lock owns the mutex, ownership is moved to thisscoped_lock with no blocking. If the scop scoped_lock does not own the mutex, then neither will this scoped_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);". This constructor does not alter the state of the mutex, only potentially who owns it.
|
inlineexplicit |
Effects: If upgr.owns() then calls unlock_upgradable_and_lock() on the referenced mutex.
upgr.release() is called. Postconditions: mutex() == the value upgr.mutex() had before the construction. upgr.mutex() == 0. owns() == upgr.owns() before the construction. upgr.owns() == false after the construction. Notes: If upgr is locked, this constructor will lock this scoped_lock while unlocking upgr. If upgr is unlocked, then this scoped_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 may block if other threads hold a sharable_lock on this mutex (sharable_lock's can share ownership with an upgradable_lock).
References boost::interprocess::upgradable_lock< UpgradableMutex >::mutex(), boost::interprocess::upgradable_lock< UpgradableMutex >::owns(), and boost::interprocess::upgradable_lock< UpgradableMutex >::release().
|
inline |
Effects: If upgr.owns() then calls try_unlock_upgradable_and_lock() on the referenced mutex: a)if try_unlock_upgradable_and_lock() returns true then mutex() obtains the value from upgr.release() and owns() is set to true.
b)if try_unlock_upgradable_and_lock() returns false then upgr is unaffected and this scoped_lock construction as the same effects as a default construction. c)Else upgr.owns() is false. mutex() obtains the value from upgr.release() and owns() is set to false Notes: This construction will not block. It will try to obtain mutex ownership from upgr immediately, while changing the lock type from a "read lock" to a "write lock". If the "read lock" isn't held in the first place, the mutex merely changes type to an unlocked "write 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::upgradable_lock< UpgradableMutex >::mutex(), boost::interprocess::upgradable_lock< UpgradableMutex >::owns(), and boost::interprocess::upgradable_lock< UpgradableMutex >::release().
|
inline |
Effects: If upgr.owns() then calls timed_unlock_upgradable_and_lock(abs_time) on the referenced mutex: a)if timed_unlock_upgradable_and_lock(abs_time) returns true then mutex() obtains the value from upgr.release() and owns() is set to true.
b)if timed_unlock_upgradable_and_lock(abs_time) returns false then upgr is unaffected and this scoped_lock construction as the same effects as a default construction. c)Else upgr.owns() is false. mutex() obtains the value from upgr.release() and owns() is set to false Notes: This construction will not block. It will try to obtain mutex ownership from upgr immediately, while changing the lock type from a "read lock" to a "write lock". If the "read lock" isn't held in the first place, the mutex merely changes type to an unlocked "write 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::upgradable_lock< UpgradableMutex >::mutex(), boost::interprocess::upgradable_lock< UpgradableMutex >::owns(), and boost::interprocess::upgradable_lock< UpgradableMutex >::release().
|
inline |
Effects: If shar.owns() then calls try_unlock_sharable_and_lock() on the referenced mutex.
a)if try_unlock_sharable_and_lock() returns true then mutex() obtains the value from shar.release() and owns() is set to true. b)if try_unlock_sharable_and_lock() returns false then shar is unaffected and this scoped_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 a "write lock". If the "read lock" isn't held in the first place, the mutex merely changes type to an unlocked "write 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().
|
inline |
|
inline |
Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception.
Calls lock() on the referenced mutex. Postconditions: owns() == true. Notes: The scoped_lock changes from a state of not owning the mutex, to owning the mutex, blocking if necessary.
|
inline |
Effects: Returns a pointer to the referenced mutex, or 0 if there is no mutex to reference.
Referenced by boost::interprocess::sharable_lock< SharableMutex >::sharable_lock(), and boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock().
|
inline |
Conversion to bool.
Returns owns().
|
inline |
Effects: If owns() before the call, then unlock() is called on mutex().
*this gets the state of scop and scop gets set to a default constructed state. Notes: With a recursive mutex it is possible that both this and scop own the same mutex before the assignment. In this case, this will own the mutex after the assignment (and scop will not), but the mutex's lock count will be decremented by one.
References boost::interprocess::scoped_lock< Mutex >::owns(), and boost::interprocess::scoped_lock< Mutex >::unlock().
|
inline |
Effects: Returns true if this scoped_lock has acquired the referenced mutex.
Referenced by boost::interprocess::scoped_lock< Mutex >::operator=(), boost::interprocess::sharable_lock< SharableMutex >::sharable_lock(), boost::interprocess::interprocess_upgradable_mutex::timed_lock(), boost::interprocess::interprocess_sharable_mutex::timed_lock(), boost::interprocess::interprocess_upgradable_mutex::timed_lock_sharable(), boost::interprocess::interprocess_sharable_mutex::timed_lock_sharable(), boost::interprocess::interprocess_upgradable_mutex::timed_lock_upgradable(), boost::interprocess::interprocess_upgradable_mutex::timed_unlock_upgradable_and_lock(), boost::interprocess::interprocess_upgradable_mutex::try_lock(), boost::interprocess::interprocess_sharable_mutex::try_lock(), boost::interprocess::interprocess_upgradable_mutex::try_lock_sharable(), boost::interprocess::interprocess_sharable_mutex::try_lock_sharable(), boost::interprocess::interprocess_upgradable_mutex::try_lock_upgradable(), boost::interprocess::interprocess_upgradable_mutex::try_unlock_sharable_and_lock(), boost::interprocess::interprocess_upgradable_mutex::try_unlock_sharable_and_lock_upgradable(), boost::interprocess::interprocess_upgradable_mutex::try_unlock_upgradable_and_lock(), and boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock().
|
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::sharable_lock< SharableMutex >::sharable_lock(), and boost::interprocess::upgradable_lock< UpgradableMutex >::upgradable_lock().
|
inline |
|
inline |
Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception.
Calls timed_lock(abs_time) on the referenced mutex. Postconditions: owns() == the value returned from mutex()-> timed_lock(abs_time). Notes: The scoped_lock changes from a state of not owning the mutex, to owning the mutex, but only if it can obtain ownership by the specified time. If the mutex_type does not support timed_lock (), this function will fail at compile time if instantiated, but otherwise have no effect.
|
inline |
Effects: If mutex() == 0 or if already locked, throws a lock_exception() exception.
Calls try_lock() on the referenced mutex. Postconditions: owns() == the value returned from mutex()->try_lock(). Notes: The scoped_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(), this function will fail at compile time if instantiated, but otherwise have no effect.
|
inline |
Effects: If mutex() == 0 or if not locked, throws a lock_exception() exception.
Calls unlock() on the referenced mutex. Postconditions: owns() == false. Notes: The scoped_lock changes from a state of owning the mutex, to not owning the mutex.
Referenced by boost::interprocess::scoped_lock< Mutex >::operator=().