RMM API 2.0.0
Loading...
Searching...
No Matches
OptionalLock.h
1#pragma once
2#include <mutex>
3
11 public:
16 OptionalLock(std::mutex* m) : mutex_(m) {
17 if (mutex_) mutex_->lock();
18 }
19
23 if (mutex_) mutex_->unlock();
24 }
25
28 void unlock() {
29 if (mutex_) mutex_->unlock();
30 }
31
34 void lock() {
35 if (mutex_) mutex_->lock();
36 }
37
38 private:
39 std::mutex* mutex_;
40};
void unlock()
Manually unlocks the mutex if it is not null.
Definition OptionalLock.h:28
~OptionalLock()
Destructor that automatically unlocks the mutex if it exists.
Definition OptionalLock.h:22
void lock()
Manually locks the mutex if it is not null.
Definition OptionalLock.h:34
OptionalLock(std::mutex *m)
Constructs the lock and automatically locks the mutex if it exists.
Definition OptionalLock.h:16