Lely core libraries  1.9.2
mutex.hpp
Go to the documentation of this file.
1 
22 #ifndef LELY_COAPP_DETAIL_MUTEX_H_
23 #define LELY_COAPP_DETAIL_MUTEX_H_
24 
25 #include <lely/coapp/coapp.hpp>
26 
27 #include <mutex>
28 
29 namespace lely {
30 
31 namespace canopen {
32 
33 namespace detail {
34 
42 template <class Mutex>
43 class UnlockGuard {
44  public:
49  typedef Mutex MutexType;
50 
55  explicit UnlockGuard(MutexType& m) : m_(m) { m_.unlock(); }
56 
61  UnlockGuard(MutexType& m, ::std::adopt_lock_t) : m_(m) {}
62 
63  UnlockGuard(const UnlockGuard&) = delete;
64 
65  UnlockGuard& operator=(const UnlockGuard&) = delete;
66 
71  ~UnlockGuard() { m_.lock(); }
72 
73  private:
74  MutexType& m_;
75 };
76 
77 } // namespace detail
78 
79 } // namespace canopen
80 
81 } // namespace lely
82 
83 #endif // LELY_COAPP_DETAIL_MUTEX_H_
This is the public header file of the C++ CANopen application library.
~UnlockGuard()
Acquires ownership of m and calls m.lock(), where m is the mutex passed to the constructor.
Definition: mutex.hpp:71
Mutex MutexType
The type of the mutex to unlock.
Definition: mutex.hpp:49
UnlockGuard(MutexType &m)
Releases ownership of m and calls m.unlock().
Definition: mutex.hpp:55
UnlockGuard(MutexType &m, ::std::adopt_lock_t)
Releases ownership of m without attempting to unlock it.
Definition: mutex.hpp:61
A mutex wrapper that provides a convenient RAII-style mechanism for releasing a mutex for the duratio...
Definition: mutex.hpp:43
Global namespace for the Lely Industries N.V. libraries.
Definition: buf.hpp:32