zpp
Zephyr C++20 Framework
lock_guard.hpp
Go to the documentation of this file.
1 
7 #ifndef ZPP_INCLUDE_ZPP_LOCK_GUARD_HPP
8 #define ZPP_INCLUDE_ZPP_LOCK_GUARD_HPP
9 
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/__assert.h>
12 
13 #include <chrono>
14 
15 namespace zpp {
16 
22 template<typename T_Mutex>
23 class lock_guard {
24 public:
30  explicit lock_guard(T_Mutex& lock) noexcept
31  : m_lock(lock)
32  {
33  auto res = m_lock.lock();
34  __ASSERT_NO_MSG(res != false);
35  }
36 
41  {
42  auto res = m_lock.unlock();
43  __ASSERT_NO_MSG(res != false);
44  }
45 private:
46  T_Mutex& m_lock;
47 public:
48  lock_guard() = delete;
49  lock_guard(lock_guard&&) = delete;
50  lock_guard(const lock_guard&) = delete;
52  lock_guard& operator=(const lock_guard&) = delete;
53 };
54 
55 } // namespace zpp
56 
57 #endif // ZPP_INCLUDE_ZPP_LOCK_GUARD_HPP
lock_guard using zpp::mutex as a lock.
Definition: lock_guard.hpp:23
lock_guard & operator=(const lock_guard &)=delete
lock_guard & operator=(lock_guard &&)=delete
lock_guard(T_Mutex &lock) noexcept
Try locking the mutex waiting forever.
Definition: lock_guard.hpp:30
lock_guard()=delete
lock_guard(const lock_guard &)=delete
~lock_guard()
unlock the mutex.
Definition: lock_guard.hpp:40
lock_guard(lock_guard &&)=delete