Zephyr C++ Toolkit
|
#include <Mutex.hpp>
Public Member Functions | |
Mutex () | |
Construct a new mutex. | |
~Mutex () | |
Destroy the mutex. | |
MutexLockGuard | lockGuard (k_timeout_t timeout) |
Get a lock guard for this mutex. | |
struct k_mutex * | getZephyrMutex () |
Get the underlying Zephyr mutex object. | |
Protected Attributes | |
struct k_mutex | m_zephyrMutex |
Mutex is a C++ wrapper around a Zephyr mutex.
The recommended way to lock a mutex is to use the lockGuard() function which returns a MutexLockGuard object. This will automatically unlock the mutex when the lock guard goes out of scope.
Just like with the Zephyr mutex, they are not designed for use in interrupts.
Below is an example of how to use the Mutex class:
zct::Mutex::Mutex | ( | ) |
Construct a new mutex.
The mutex starts of in an unlocked state. Use a MutexLockGuard to lock the mutex.
zct::Mutex::~Mutex | ( | ) |
Destroy the mutex.
struct k_mutex * zct::Mutex::getZephyrMutex | ( | ) |
Get the underlying Zephyr mutex object.
It is not recommended to use this function. Only use as an escape hatch if the provided C++ API is not sufficient.
MutexLockGuard zct::Mutex::lockGuard | ( | k_timeout_t | timeout | ) |
Get a lock guard for this mutex.
Note that this function may fail to lock the mutex. It is the callers responsibility to check if the lock was successful with didGetLock() after making this call.
timeout | The timeout for the lock. Pass K_FOREVER to wait indefinitely, or K_NO_WAIT to not wait at all. |
|
protected |
The underlying Zephyr mutex object. Get access to this by calling getZephyrMutex().