Lely core libraries 2.3.4
mutex.hpp
Go to the documentation of this file.
1
22#ifndef LELY_UTIL_MUTEX_H_
23#define LELY_UTIL_MUTEX_H_
24
25#include <lely/features.h>
26
27#include <mutex>
28
29namespace lely {
30
31namespace util {
32
35 public:
40 virtual void lock() = 0;
41
43 virtual void unlock() = 0;
44
45 protected:
46 ~BasicLockable() = default;
47};
48
56template <class Mutex>
58 public:
64
69 explicit UnlockGuard(MutexType& m) : m_(m) { m_.unlock(); }
70
75 UnlockGuard(MutexType& m, ::std::adopt_lock_t) : m_(m) {}
76
77 UnlockGuard(const UnlockGuard&) = delete;
78
79 UnlockGuard& operator=(const UnlockGuard&) = delete;
80
85 ~UnlockGuard() { m_.lock(); }
86
87 private:
88 MutexType& m_;
89};
90
91} // namespace util
92
93} // namespace lely
94
95#endif // LELY_UTIL_MUTEX_H_
A CANopen value.
Definition val.hpp:42
An abstract interface conforming to the BasicLockable concept.
Definition mutex.hpp:34
virtual void lock()=0
Blocks until a lock can be obtained for the current execution agent (thread, process,...
virtual void unlock()=0
Releases the lock held by the execution agent. Throws no exceptions.
A mutex wrapper that provides a convenient RAII-style mechanism for releasing a mutex for the duratio...
Definition mutex.hpp:57
Mutex MutexType
The type of the mutex to unlock.
Definition mutex.hpp:63
UnlockGuard(MutexType &m)
Releases ownership of m and calls m.unlock().
Definition mutex.hpp:69
~UnlockGuard()
Acquires ownership of m and calls m.lock(), where m is the mutex passed to the constructor.
Definition mutex.hpp:85
UnlockGuard(MutexType &m, ::std::adopt_lock_t)
Releases ownership of m without attempting to unlock it.
Definition mutex.hpp:75
This header file is part of the Lely libraries; it contains the compiler feature definitions.