oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ove::Mutex Class Reference

RAII wrapper around an oveRTOS non-recursive mutex. More...

#include <sync.hpp>

Public Member Functions

 Mutex ()
 Constructs and initialises the mutex.
 
 ~Mutex ()
 Destroys the mutex, releasing the underlying kernel resource.
 
 Mutex (const Mutex &)=delete
 
Mutexoperator= (const Mutex &)=delete
 
 Mutex (Mutex &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Mutexoperator= (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Mutex() [1/2]

ove::Mutex::Mutex ( )
inline

Constructs and initialises the mutex.

Calls ove_mutex_init (zero-heap) or ove_mutex_create (heap). Asserts at startup if initialisation fails.

◆ ~Mutex()

ove::Mutex::~Mutex ( )
inline

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
otherThe source mutex; its handle is set to null after the move.

Member Function Documentation

◆ operator=()

Mutex & ove::Mutex::operator= ( Mutex &&  other)
inlinenoexcept

Move-assignment operator — transfers ownership of the kernel handle.

Parameters
otherThe 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_msMaximum 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: