|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Read/write-lock protected shared object wrapper. More...
#include <concurrency_utils.H>
Classes | |
| class | ReadLockedPtr |
| RAII guard for shared (read-only) access. More... | |
| class | WriteLockedPtr |
| RAII guard for exclusive (write) access. More... | |
Public Member Functions | |
| RwSynchronized ()=default | |
| Default-construct the protected value. | |
| RwSynchronized (const RwSynchronized &)=delete | |
| Deleted copy constructor. | |
| RwSynchronized & | operator= (const RwSynchronized &)=delete |
| Deleted copy assignment operator. | |
| RwSynchronized (RwSynchronized &&)=delete | |
| Deleted move constructor. | |
| RwSynchronized & | operator= (RwSynchronized &&)=delete |
| Deleted move assignment operator. | |
| RwSynchronized (const T &value) | |
Construct from a copy of value. | |
| RwSynchronized (T &&value) | |
Construct by moving from value. | |
| template<typename... Args> | |
| RwSynchronized (std::in_place_t, Args &&... args) | |
| Construct the protected value in-place. | |
| ReadLockedPtr | read () const |
| Acquire a shared lock and return a guard. | |
| WriteLockedPtr | write () |
| Acquire an exclusive lock and return a guard. | |
| template<typename F > | |
| decltype(auto) | with_read_lock (F &&f) const |
| Execute a callback with shared (read-only) access. | |
| template<typename F > | |
| decltype(auto) | with_write_lock (F &&f) |
| Execute a callback with exclusive (write) access. | |
Private Attributes | |
| SharedMutex | mutex_ |
| T | value_ |
Read/write-lock protected shared object wrapper.
RwSynchronized<T> encapsulates a value and a shared mutex, allowing multiple concurrent readers OR a single exclusive writer. All public member functions are thread-safe. Calls are not reentrant on the same object unless SharedMutex itself supports recursive acquisition.
Readers acquire a shared lock through read() / with_read_lock(). Writers acquire an exclusive lock through write() / with_write_lock().
| T | The type of the protected object. |
| SharedMutex | The shared mutex type (defaults to std::shared_mutex). |
Definition at line 905 of file concurrency_utils.H.
|
default |
Default-construct the protected value.
| Any | exception thrown by T's default constructor. |
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlineexplicit |
Construct from a copy of value.
| value | Initial value to copy into the wrapper. |
| Any | exception thrown while copying T. |
Definition at line 999 of file concurrency_utils.H.
|
inlineexplicit |
Construct by moving from value.
| value | Initial value to move into the wrapper. |
| Any | exception thrown while moving T. |
Definition at line 1006 of file concurrency_utils.H.
|
inlineexplicit |
Construct the protected value in-place.
| Args | Constructor argument types. |
| args | Arguments to pass to the constructor of T. |
Definition at line 1014 of file concurrency_utils.H.
|
delete |
Deleted copy assignment operator.
|
delete |
Deleted move assignment operator.
|
inline |
Acquire a shared lock and return a guard.
ReadLockedPtr that keeps a shared lock until destruction. | Any | exception thrown while locking SharedMutex. |
Definition at line 1022 of file concurrency_utils.H.
References Aleph::RwSynchronized< T, SharedMutex >::mutex_, and Aleph::RwSynchronized< T, SharedMutex >::value_.
Referenced by TEST().
|
inline |
Execute a callback with shared (read-only) access.
| F | Callback type. |
| f | The callback to execute. |
f. | Any | exception thrown while locking SharedMutex or by the callback itself. |
Definition at line 1051 of file concurrency_utils.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::RwSynchronized< T, SharedMutex >::mutex_, and Aleph::RwSynchronized< T, SharedMutex >::value_.
|
inline |
Execute a callback with exclusive (write) access.
| F | Callback type. |
| f | The callback to execute. |
f. | Any | exception thrown while locking SharedMutex or by the callback itself. |
Definition at line 1072 of file concurrency_utils.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::RwSynchronized< T, SharedMutex >::mutex_, and Aleph::RwSynchronized< T, SharedMutex >::value_.
|
inline |
Acquire an exclusive lock and return a guard.
WriteLockedPtr that keeps an exclusive lock until destruction. | Any | exception thrown while locking SharedMutex. |
Definition at line 1034 of file concurrency_utils.H.
References Aleph::RwSynchronized< T, SharedMutex >::mutex_, and Aleph::RwSynchronized< T, SharedMutex >::value_.
Referenced by TEST().
|
mutableprivate |
|
private |