cloaks a value type and the mutex used to protect it together. More...
#include <synchronized_value.hpp>
Public Types | |
typedef T | value_type |
typedef Lockable | mutex_type |
Public Member Functions | |
synchronized_value () | |
Default constructor. More... | |
synchronized_value (T const &other) | |
Constructor from copy constructible value. More... | |
synchronized_value (BOOST_THREAD_RV_REF(T) other) | |
Move Constructor. More... | |
synchronized_value (synchronized_value const &rhs) | |
Constructor from value type. More... | |
synchronized_value (BOOST_THREAD_RV_REF(synchronized_value) other) | |
Move Constructor from movable value type. More... | |
synchronized_value & | operator= (synchronized_value const &rhs) |
Assignment operator. More... | |
synchronized_value & | operator= (value_type const &val) |
Assignment operator from a T const&. More... | |
T | get () const |
Explicit conversion to value type. More... | |
operator T () const | |
Explicit conversion to value type. More... | |
T const & | value () const |
value type getter. More... | |
mutex_type const & | mutex () const |
mutex getter. More... | |
void | swap (synchronized_value &rhs) |
Swap. More... | |
void | swap (value_type &rhs) |
Swap with the underlying value type. More... | |
strict_lock_ptr< T, Lockable > | operator-> () |
Essentially calling a method obj->foo(x, y, z) calls the method foo(x, y, z) inside a critical section as long-lived as the call itself. More... | |
const_strict_lock_ptr< T, Lockable > | operator-> () const |
If the synchronized_value object involved is const-qualified, then you'll only be able to call const methods through operator->. More... | |
template<typename F > | |
boost::result_of< F(value_type &)> ::type | operator() (BOOST_THREAD_RV_REF(F) fct) |
Call function on a locked block. More... | |
template<typename F > | |
boost::result_of< F(value_type const &)>::type | operator() (BOOST_THREAD_RV_REF(F) fct) const |
strict_lock_ptr< T, Lockable > | synchronize () |
The synchronize() factory make easier to lock on a scope. More... | |
const_strict_lock_ptr< T, Lockable > | synchronize () const |
unique_lock_ptr< T, Lockable > | unique_synchronize () |
const_unique_lock_ptr< T, Lockable > | unique_synchronize () const |
unique_lock_ptr< T, Lockable > | unique_synchronize (defer_lock_t tag) |
const_unique_lock_ptr< T, Lockable > | unique_synchronize (defer_lock_t tag) const |
unique_lock_ptr< T, Lockable > | defer_synchronize () BOOST_NOEXCEPT |
const_unique_lock_ptr< T, Lockable > | defer_synchronize () const BOOST_NOEXCEPT |
unique_lock_ptr< T, Lockable > | try_to_synchronize () BOOST_NOEXCEPT |
const_unique_lock_ptr< T, Lockable > | try_to_synchronize () const BOOST_NOEXCEPT |
unique_lock_ptr< T, Lockable > | adopt_synchronize () BOOST_NOEXCEPT |
const_unique_lock_ptr< T, Lockable > | adopt_synchronize () const BOOST_NOEXCEPT |
deref_value | operator* () |
const_deref_value | operator* () const |
template<typename OStream > | |
void | save (OStream &os) const |
T is OutputStreamable saves the value type on the output stream os . More... | |
template<typename IStream > | |
void | load (IStream &is) const |
T is InputStreamable loads the value type from the input stream is . More... | |
bool | operator== (synchronized_value const &rhs) const |
T is EqualityComparable More... | |
bool | operator< (synchronized_value const &rhs) const |
T is LessThanComparable More... | |
bool | operator> (synchronized_value const &rhs) const |
T is GreaterThanComparable More... | |
bool | operator<= (synchronized_value const &rhs) const |
bool | operator>= (synchronized_value const &rhs) const |
bool | operator== (value_type const &rhs) const |
bool | operator!= (value_type const &rhs) const |
bool | operator< (value_type const &rhs) const |
bool | operator<= (value_type const &rhs) const |
bool | operator> (value_type const &rhs) const |
bool | operator>= (value_type const &rhs) const |
Friends | |
template<typename... SV> | |
std::tuple< typename synchronized_value_strict_lock_ptr < SV >::type...> | synchronize (SV &...sv) |
cloaks a value type and the mutex used to protect it together.
T | the value type. |
Lockable | the mutex type protecting the value type. |
typedef Lockable boost::synchronized_value< T, Lockable >::mutex_type |
typedef T boost::synchronized_value< T, Lockable >::value_type |
|
inline |
Default constructor.
: T is DefaultConstructible
|
inline |
Constructor from copy constructible value.
Requires: T is CopyConstructible
|
inline |
Move Constructor.
Requires: T is CopyMovable
|
inline |
Constructor from value type.
Requires: T is DefaultConstructible and Assignable Effects: Assigns the value on a scope protected by the mutex of the rhs. The mutex is not copied.
|
inline |
Move Constructor from movable value type.
References boost::move().
|
inline |
References boost::adopt_lock.
|
inline |
References boost::adopt_lock.
|
inline |
References boost::defer_lock.
|
inline |
References boost::defer_lock.
|
inline |
Explicit conversion to value type.
Requires: T is CopyConstructible Return: A copy of the protected value obtained on a scope protected by the mutex.
|
inline |
T is InputStreamable loads the value type from the input stream is
.
Referenced by boost::operator>>().
|
inline |
mutex getter.
Return: A constant reference to the protecting mutex.
Note: Not thread safe
|
inlineexplicit |
Explicit conversion to value type.
Requires: T is CopyConstructible Return: A copy of the protected value obtained on a scope protected by the mutex.
|
inline |
|
inline |
Call function on a locked block.
fct(value_) is well formed.
Example void fun(synchronized_value<vector<int>> & v) { v ( [](vector<int>> & vec) { vec.push_back(42); assert(vec.back() == 42); } ); }
|
inline |
|
inline |
|
inline |
|
inline |
Essentially calling a method obj->foo(x, y, z) calls the method foo(x, y, z) inside a critical section as long-lived as the call itself.
|
inline |
If the synchronized_value object involved is const-qualified, then you'll only be able to call const methods through operator->.
So, for example, vec->push_back("xyz") won't work if vec were const-qualified. The locking mechanism capitalizes on the assumption that const methods don't modify their underlying data.
|
inline |
T is LessThanComparable
References boost::defer_lock, and boost::lock().
|
inline |
|
inline |
References boost::defer_lock, and boost::lock().
|
inline |
|
inline |
Assignment operator.
Effects: Copies the underlying value on a scope protected by the two mutexes. The mutex is not copied. The locks are acquired using lock, so deadlock is avoided. For example, there is no problem if one thread assigns a = b and the other assigns b = a.
Return: *this
References boost::defer_lock, and boost::lock().
|
inline |
Assignment operator from a T const&.
Effects: The operator copies the value on a scope protected by the mutex. Return: *this
References boost::phoenix::val().
|
inline |
T is EqualityComparable
References boost::defer_lock, and boost::lock().
|
inline |
|
inline |
T is GreaterThanComparable
References boost::defer_lock, and boost::lock().
|
inline |
|
inline |
References boost::defer_lock, and boost::lock().
|
inline |
|
inline |
T is OutputStreamable saves the value type on the output stream os
.
Referenced by boost::operator<<().
|
inline |
Swap.
Effects: Swaps the data. Again, locks are acquired using lock(). The mutexes are not swapped. A swap method accepts a T& and swaps the data inside a critical section. This is by far the preferred method of changing the guarded datum wholesale because it keeps the lock only for a short time, thus lowering the pressure on the mutex.
References boost::defer_lock, boost::lock(), and boost::swap.
Referenced by boost::swap().
|
inline |
Swap with the underlying value type.
Effects: Swaps the data on a scope protected by the mutex.
References boost::swap.
|
inline |
The synchronize() factory make easier to lock on a scope.
As discussed, operator-> can only lock over the duration of a call, so it is insufficient for complex operations. With synchronize() you get to lock the object in a scoped and to directly access the object inside that scope.
Example void fun(synchronized_value<vector<int>> & v) { auto&& vec=v.synchronize(); vec.push_back(42); assert(vec.back() == 42); }
|
inline |
|
inline |
References boost::try_to_lock.
|
inline |
References boost::try_to_lock.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
value type getter.
Return: A constant reference to the protected value.
Note: Not thread safe
|
friend |