mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
mrs_lib::Lockable< LockedVarT, MutexT > Class Template Reference

Convenience class for safe and expressive management of mutexed variables. More...

#include <lockable.h>

Public Member Functions

 Lockable (const LockedVarT &init_val)
 
 Lockable (const LockedVarT &&init_val)
 
LockedVarT & unsafe_access ()
 
void set_mutexed (const LockedVarT &val)
 
LockedVarT get_mutexed ()
 
MutexT & mutex ()
 

Detailed Description

template<typename LockedVarT, typename MutexT = std::mutex>
class mrs_lib::Lockable< LockedVarT, MutexT >

Convenience class for safe and expressive management of mutexed variables.

In the typical use-case, instantiate this class with a struct holding all variables that you want locked together.

To access these variables, unlock the object with the specialized RAII-style object Unlocker (see below in this file) - similar to how you'd use an std::scoped_lock. Or you can use the familiar set_mutexed() and get_mutexed() methods.


The documentation for this class was generated from the following file: