Zephyr C++ Toolkit
Loading...
Searching...
No Matches
Mutex.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <zephyr/kernel.h>
4#include <tl/expected.hpp>
5
6namespace zct {
7
8// Forward declarations
9class Mutex;
10
15public:
16
18
19 // Prevent copying and moving
24
30 bool didGetLock() const;
31
32 // Allow Mutex to construct MutexLockGuard objects
33 friend class Mutex;
34
35protected:
39 MutexLockGuard(Mutex& mutex, k_timeout_t timeout, int& mutexRc);
40
45
46 bool m_didGetLock = false;
47};
48
61class Mutex {
62public:
68 Mutex();
69
73 ~Mutex();
74
83 MutexLockGuard lockGuard(k_timeout_t timeout);
84
93 struct k_mutex* getZephyrMutex();
94protected:
95
99 struct k_mutex m_zephyrMutex;
100};
101
102} // namespace zct
Definition Mutex.hpp:14
bool m_didGetLock
Definition Mutex.hpp:46
MutexLockGuard & operator=(const MutexLockGuard &)=delete
Mutex & m_mutex
Definition Mutex.hpp:44
MutexLockGuard & operator=(MutexLockGuard &&)=delete
bool didGetLock() const
Check if the mutex was successfully locked with this lock guard.
Definition Mutex.cpp:40
~MutexLockGuard()
Definition Mutex.cpp:27
MutexLockGuard(MutexLockGuard &&)
MutexLockGuard(const MutexLockGuard &)=delete
Definition Mutex.hpp:61
~Mutex()
Destroy the mutex.
Definition Mutex.cpp:55
struct k_mutex * getZephyrMutex()
Get the underlying Zephyr mutex object.
Definition Mutex.cpp:67
struct k_mutex m_zephyrMutex
Definition Mutex.hpp:99
Mutex()
Construct a new mutex.
Definition Mutex.cpp:49
MutexLockGuard lockGuard(k_timeout_t timeout)
Get a lock guard for this mutex.
Definition Mutex.cpp:59
Definition Mutex.hpp:6