RMM API 2.0.0
Loading...
Searching...
No Matches
OptionalLock Class Reference

A RAII wrapper for an optional std::mutex. This class provides a way to lock a mutex only if a valid pointer is provided. If the pointer is null, the lock and unlock operations do nothing, allowing for flexible locking strategies where a mutex may or may not exist. More...

#include <OptionalLock.h>

Public Member Functions

 OptionalLock (std::mutex *m)
 Constructs the lock and automatically locks the mutex if it exists.
 
 ~OptionalLock ()
 Destructor that automatically unlocks the mutex if it exists.
 
void unlock ()
 Manually unlocks the mutex if it is not null.
 
void lock ()
 Manually locks the mutex if it is not null.
 

Detailed Description

A RAII wrapper for an optional std::mutex. This class provides a way to lock a mutex only if a valid pointer is provided. If the pointer is null, the lock and unlock operations do nothing, allowing for flexible locking strategies where a mutex may or may not exist.

Constructor & Destructor Documentation

◆ OptionalLock()

OptionalLock::OptionalLock ( std::mutex * m)
inline

Constructs the lock and automatically locks the mutex if it exists.

Parameters
mPointer to the std::mutex to manage. Can be nullptr.

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