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

RAII wrapper around an oveRTOS counting semaphore. More...

#include <sync.hpp>

Public Member Functions

 Semaphore (unsigned int initial=0, unsigned int max=1)
 Constructs and initialises the semaphore.
 
 ~Semaphore ()
 Destroys the semaphore, releasing the underlying kernel resource.
 
 Semaphore (const Semaphore &)=delete
 
Semaphoreoperator= (const Semaphore &)=delete
 
 Semaphore (Semaphore &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Semaphoreoperator= (Semaphore &&other) noexcept
 Move-assignment operator — transfers ownership of the kernel handle.
 
int take (uint32_t timeout_ms=OVE_WAIT_FOREVER)
 Decrements the semaphore count, blocking if the count is zero.
 
void give ()
 Increments the semaphore count, unblocking a waiting task if any.
 
bool valid () const
 Returns true if the underlying kernel handle is non-null.
 
ove_sem_t handle () const
 Returns the raw oveRTOS semaphore handle.
 

Detailed Description

RAII wrapper around an oveRTOS counting semaphore.

A counting semaphore with a configurable initial count and maximum count. Commonly used as a binary semaphore (initial = 0, max = 1) for signalling between tasks or from an ISR.

With CONFIG_OVE_ZERO_HEAP the semaphore storage is held inline and move operations are disabled.

Note
Not copyable. Move-only when heap allocation is enabled.
take() is marked [[nodiscard]]; the return value indicates whether the semaphore was actually decremented.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

ove::Semaphore::Semaphore ( unsigned int  initial = 0,
unsigned int  max = 1 
)
inlineexplicit

Constructs and initialises the semaphore.

Parameters
[in]initialInitial count value (default: 0).
[in]maxMaximum count value (default: 1, binary semaphore).

Asserts at startup if initialisation fails.

◆ Semaphore() [2/2]

ove::Semaphore::Semaphore ( Semaphore &&  other)
inlinenoexcept

Move constructor — transfers ownership of the kernel handle.

Parameters
otherThe source; its handle is set to null after the move.

Member Function Documentation

◆ operator=()

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

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

Parameters
otherThe source; its handle is set to null after the move.
Returns
Reference to this object.

◆ take()

int ove::Semaphore::take ( uint32_t  timeout_ms = OVE_WAIT_FOREVER)
inline

Decrements the semaphore count, blocking if the count is zero.

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.

◆ give()

void ove::Semaphore::give ( )
inline

Increments the semaphore count, unblocking a waiting task if any.

Safe to call from both task and ISR context.

◆ valid()

bool ove::Semaphore::valid ( ) const
inline

Returns true if the underlying kernel handle is non-null.

Returns
true when the semaphore was successfully initialised.

◆ handle()

ove_sem_t ove::Semaphore::handle ( ) const
inline

Returns the raw oveRTOS semaphore handle.

Returns
The opaque ove_sem_t handle.

The documentation for this class was generated from the following file: