PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/Util/FancyLock.hpp Source File

PCB Environment 2

Loading...
Searching...
No Matches
FancyLock.hpp
1#ifndef GYM_PCB_UTIL_FANCYLOCK_H
2#define GYM_PCB_UTIL_FANCYLOCK_H
3
4#include <mutex>
5
6// I really want to be able to write WITH_LOCK(...) { }
7
8 struct fancy_lock_guard
9{
10 fancy_lock_guard(std::mutex &mutex) : _lock(mutex) { }
11 std::lock_guard<std::mutex> _lock;
12 operator bool() const { return true; }
13};
14
15#define WITH_LOCKGUARD(m) if (auto __lock = fancy_lock_guard(m))
16
17#endif // GYM_PCB_UTIL_FANCYLOCK_H