|
header_utils
|
A class that stores an object to which access is protected via a mutexlike; all operations are thread-safe unless specified otherwise. More...
#include <threading.h>
Public Types | |
| using | object_type |
| using | reference |
| using | const_reference |
| using | mutex_type |
Public Member Functions | |
| T | get () const |
| Returns a copy of the object. | |
| T | take () |
| Takes the value of the object via move. | |
| template<typename U> | |
| T | exchange (U &&u) |
| Exchanges the value of the object with u and returns the old value. | |
| template<typename FUNC> | |
| auto | read_only_access (FUNC &&func) const |
| Calls func with a const reference to the object which can be safely accessed; only available if the mutex is a shared mutex. | |
| template<typename U = T> | |
| void | set (U &&value) |
| Sets a new value for the object. | |
| template<typename FUNC> | |
| auto | mutate_in_place (FUNC &&func) |
| Calls func with a reference to the object which can be safely mutated. | |
| template<typename FUNC> | |
| void | mutate_by_copy (FUNC &&func) |
| Calls func with a reference to a copy of the object, but not under the protection of the mutex. | |
| mutex_type const & | mutex () const |
Static Public Attributes | |
| static constexpr bool | is_shared |
| static constexpr bool | is_timed |
Protected Attributes | |
| T | m_value |
| mutex_type | m_mutex |
A class that stores an object to which access is protected via a mutexlike; all operations are thread-safe unless specified otherwise.
Definition at line 93 of file threading.h.
| using ghassanpl::protected_object< T, MUTEX_TYPE >::const_reference |
Definition at line 100 of file threading.h.
| using ghassanpl::protected_object< T, MUTEX_TYPE >::mutex_type |
Definition at line 101 of file threading.h.
| using ghassanpl::protected_object< T, MUTEX_TYPE >::object_type |
Definition at line 98 of file threading.h.
| using ghassanpl::protected_object< T, MUTEX_TYPE >::reference |
Definition at line 99 of file threading.h.
|
inline |
Exchanges the value of the object with u and returns the old value.
Definition at line 119 of file threading.h.
|
inline |
Returns a copy of the object.
Definition at line 106 of file threading.h.
|
inline |
Calls func with a reference to a copy of the object, but not under the protection of the mutex.
You can modify this copy safely. After func returns, the mutated copy will be set as the new value.
Definition at line 151 of file threading.h.
|
inline |
Calls func with a reference to the object which can be safely mutated.
Definition at line 142 of file threading.h.
|
inline |
Definition at line 159 of file threading.h.
|
inline |
Calls func with a const reference to the object which can be safely accessed; only available if the mutex is a shared mutex.
Definition at line 127 of file threading.h.
|
inline |
Sets a new value for the object.
Definition at line 135 of file threading.h.
|
inline |
Takes the value of the object via move.
Definition at line 112 of file threading.h.
|
staticconstexpr |
Definition at line 102 of file threading.h.
|
staticconstexpr |
Definition at line 103 of file threading.h.
|
mutableprotected |
Definition at line 164 of file threading.h.
|
protected |
Definition at line 163 of file threading.h.