|
| template<typename LHSType, typename RHSType, std::enable_if_t< std::disjunction_v< std::is_same< LHSType, Guarded >, std::is_same< RHSType, Guarded > >, bool > = true> |
| bool | operator== (const LHSType &lhs, const RHSType &rhs) noexcept |
| template<typename LHSType, typename RHSType, std::enable_if_t< std::disjunction_v< std::is_same< LHSType, Guarded >, std::is_same< RHSType, Guarded > >, bool > = true> |
| bool | operator!= (const LHSType &lhs, const RHSType &rhs) noexcept |
template<typename T, typename MutexType = std::mutex>
struct sen::Guarded< T, MutexType >
Guarded is a lightweight wrapper class that can be used to protect an objet of type T from concurrent modification. The wrapper only allows access/reads/modifications of the underlying value while holding a lock but does not require the user to hold the lock himself.
Example:
struct MyClass
{
void add(int val)
{
protectedInt += val;
}
};
Guarded is a lightweight wrapper class that can be used to protect an objet of type T from concurrent...
Definition mutex_utils.h:49
- Note
- Guarded cannot guarantee that no lock-order inversion occurs, so even with the wrapper the developer still needs to ensure that concurrent reads/writes do not access different wrappers or other mutexes in different orders.
Furthermore, keep in mind that the best concurrent code is the one that is designed in a way to work without locked values.
- Template Parameters
-
| T | the type of the underlying protected value |
| MutexType | the type of the mutex that should be used |