RAII wrapper around an oveRTOS non-recursive mutex.
More...
#include <sync.hpp>
|
| | Mutex () |
| | Constructs and initialises the mutex.
|
| |
| | ~Mutex () |
| | Destroys the mutex, releasing the underlying kernel resource.
|
| |
|
| Mutex (const Mutex &)=delete |
| |
|
Mutex & | operator= (const Mutex &)=delete |
| |
| | Mutex (Mutex &&other) noexcept |
| | Move constructor — transfers ownership of the kernel handle.
|
| |
| Mutex & | operator= (Mutex &&other) noexcept |
| | Move-assignment operator — transfers ownership of the kernel handle.
|
| |
| int | lock (uint32_t timeout_ms=OVE_WAIT_FOREVER) |
| | Acquires the mutex, blocking until it is available or the timeout expires.
|
| |
| void | unlock () |
| | Releases the mutex.
|
| |
| bool | valid () const |
| | Returns true if the underlying kernel handle is non-null.
|
| |
| ove_mutex_t | handle () const |
| | Returns the raw oveRTOS mutex handle.
|
| |
RAII wrapper around an oveRTOS non-recursive mutex.
Constructs the underlying kernel mutex object on creation and destroys it on destruction. With CONFIG_OVE_ZERO_HEAP the mutex storage is held inline in the wrapper; move operations are therefore disabled in that configuration because the kernel may hold a pointer to the internal buffer.
- Note
- Not copyable. Move-only when heap allocation is enabled.
-
lock() is marked [[nodiscard]]; ignoring its return value risks deadlock.
◆ Mutex() [1/2]
Constructs and initialises the mutex.
Calls ove_mutex_init (zero-heap) or ove_mutex_create (heap). Asserts at startup if initialisation fails.
◆ ~Mutex()
Destroys the mutex, releasing the underlying kernel resource.
If the handle is null (e.g., after a move), the destructor is a no-op.
◆ Mutex() [2/2]
| ove::Mutex::Mutex |
( |
Mutex && |
other | ) |
|
|
inlinenoexcept |
Move constructor — transfers ownership of the kernel handle.
- Parameters
-
| other | The source mutex; its handle is set to null after the move. |
◆ operator=()
Move-assignment operator — transfers ownership of the kernel handle.
- Parameters
-
| other | The source mutex; its handle is set to null after the move. |
- Returns
- Reference to this object.
◆ lock()
| int ove::Mutex::lock |
( |
uint32_t |
timeout_ms = OVE_WAIT_FOREVER | ) |
|
|
inline |
Acquires the mutex, blocking until it is available or the timeout expires.
- Parameters
-
| [in] | timeout_ms | Maximum time to wait in milliseconds; use OVE_WAIT_FOREVER to block indefinitely. |
- Returns
OVE_OK on success, or a negative error code on timeout/failure.
◆ unlock()
| void ove::Mutex::unlock |
( |
| ) |
|
|
inline |
Releases the mutex.
Must be called from the same thread context that acquired the lock.
◆ valid()
| bool ove::Mutex::valid |
( |
| ) |
const |
|
inline |
Returns true if the underlying kernel handle is non-null.
- Returns
true when the mutex was successfully initialised.
◆ handle()
| ove_mutex_t ove::Mutex::handle |
( |
| ) |
const |
|
inline |
Returns the raw oveRTOS mutex handle.
- Returns
- The opaque
ove_mutex_t handle.
The documentation for this class was generated from the following file: