CsLibGuarded
1.4.2
|
#include <CsLibGuarded/cs_lr_guarded.h>
Public Member Functions | |
template<typename... Us> | |
lr_guarded (Us &&... data) | |
template<typename Func> | |
void | modify (Func &&f) |
shared_handle | lock_shared () const |
shared_handle | try_lock_shared () const |
template<class Duration> | |
shared_handle | try_lock_shared_for (const Duration &duration) const |
template<class TimePoint> | |
shared_handle | try_lock_shared_until (const TimePoint &timepoint) const |
This templated class wraps an object and allows only one thread at a time to modify the protected object.
This class will use std::mutex for the internal locking mechanism by default. Other classes which are useful for the mutex type are std::recursive_mutex, std::timed_mutex, and std::recursive_timed_mutex.
The handle returned by the various lock methods is moveable and copyable.
Internally this class operates by maintaining two copies of the data and applying the same modifications to each copy in turn. Therefore the lr_guarded object will consume twice as much memory as one T plus a small amount of overhead.
The T class must be copy constructible and copy assignable.
Definition at line 51 of file cs_lr_guarded.h.
libguarded::lr_guarded< T, Mutex >::lr_guarded | ( | Us &&... | data | ) |
Construct an lr_guarded object. This constructor will accept any number of parameters, all of which are forwarded to the constructor of T.
Definition at line 64 of file cs_lr_guarded.h.
|
nodiscard |
Acquire a shared_handle to the protected object. Always succeeds without blocking.
Definition at line 84 of file cs_lr_guarded.h.
void libguarded::lr_guarded< T, Mutex >::modify | ( | Func && | f | ) |
Modify the data by passing a functor. The functor must take exactly one argument of type T&. The functor will be called twice, once for each copy of the data. It must make the same modification for both invocations.
If the first invocation of the functor throws an exception, the modification will be rolled back by copying from the unchanged copy. If the second invocation throws, the modification will be completed by copying from the changed copy. In either case if the copy constructor throws, the data is left in an indeterminate state.
Definition at line 79 of file cs_lr_guarded.h.
|
nodiscard |
Acquire a shared_handle to the protected object. Always succeeds without blocking.
Definition at line 89 of file cs_lr_guarded.h.
|
nodiscard |
Acquire a shared_handle to the protected object. Always succeeds without blocking.
Definition at line 95 of file cs_lr_guarded.h.
|
nodiscard |
Acquire a shared_handle to the protected object. Always succeeds without blocking.
Definition at line 101 of file cs_lr_guarded.h.