The jss::update_guard<>
class template provides scoped access to the wrapped object inside an instance
of the jss::synchronized_value
class template.
The type of object being accessed is specified by template parameter T
. The internal mutex of the jss::synchronized_value<>
instance is locked in the jss::update_guard<>
constructor and unlocked in the destructor. This provides a simple means
of locking the mutex for a block of code so that multiple operations can
be performed on the wrapped object whilst ensuring that the mutex is unlocked
when the block is left, whether that is by running off the end, by the
use of a control flow statement such as break
or return
, or by throwing
an exception.
Access to the wrapped object can be obtained through the use of the pointer
dereference operators on the jss::update_guard<>
instance.
Instances of jss::update_guard<>
are neither MoveConstructible
,
CopyConstructible
or CopyAssignable
.
template <class T> class update_guard { public: explicit update_guard(jss::synchronized_value<T>& sv); ~update_guard(); T& operator*(); T* operator->(); update_guard(update_guard const& ) = delete; update_guard& operator=(update_guard const& ) = delete; };
#include <jss/synchronized_value.hpp>