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

RAII wrapper representing a single deferred work item. More...

#include <workqueue.hpp>

Public Member Functions

template<typename F >
requires WorkHandler<F>
 Work (F handler)
 Constructs a work item with the given handler function.
 
 ~Work ()
 Destroys the work item, freeing its kernel resource (heap mode).
 
 Work (const Work &)=delete
 
Workoperator= (const Work &)=delete
 
 Work (Work &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Workoperator= (Work &&other) noexcept
 Move-assignment operator — transfers ownership of the kernel handle.
 
template<size_t S>
int submit (Workqueue< S > &wq)
 Submits the work item to a workqueue for immediate execution.
 
template<size_t S>
int submit_delayed (Workqueue< S > &wq, uint32_t delay_ms)
 Submits the work item to a workqueue with a delay.
 
int cancel ()
 Attempts to cancel a pending work item.
 
bool valid () const
 Returns true if the underlying kernel handle is non-null.
 
ove_work_t handle () const
 Returns the raw oveRTOS work handle.
 

Detailed Description

RAII wrapper representing a single deferred work item.

A Work item encapsulates a handler function and can be submitted to a Workqueue for asynchronous or delayed execution. The same Work object must not be submitted while it is already pending or running.

Note
Not copyable. Move-only when heap allocation is enabled.

Constructor & Destructor Documentation

◆ Work() [1/2]

template<typename F >
requires WorkHandler<F>
ove::Work::Work ( handler)
inlineexplicit

Constructs a work item with the given handler function.

Template Parameters
FHandler type satisfying WorkHandler.
Parameters
[in]handlerFunction pointer called when the work item is executed.

Asserts at startup if initialisation fails.

◆ Work() [2/2]

ove::Work::Work ( Work &&  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=()

Work & ove::Work::operator= ( Work &&  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.

◆ submit()

template<size_t S>
int ove::Work::submit ( Workqueue< S > &  wq)
inline

Submits the work item to a workqueue for immediate execution.

Template Parameters
SStack size of the target workqueue.
Parameters
[in]wqThe workqueue to submit this work item to.
Returns
OVE_OK on success, or a negative error code.

◆ submit_delayed()

template<size_t S>
int ove::Work::submit_delayed ( Workqueue< S > &  wq,
uint32_t  delay_ms 
)
inline

Submits the work item to a workqueue with a delay.

Template Parameters
SStack size of the target workqueue.
Parameters
[in]wqThe workqueue to submit this work item to.
[in]delay_msDelay in milliseconds before the item is executed.
Returns
OVE_OK on success, or a negative error code.

◆ cancel()

int ove::Work::cancel ( )
inline

Attempts to cancel a pending work item.

If the item is already running, cancellation may not be possible.

Returns
OVE_OK if cancelled, or a negative error code.

◆ valid()

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

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

Returns
true when the work item was successfully initialised.

◆ handle()

ove_work_t ove::Work::handle ( ) const
inline

Returns the raw oveRTOS work handle.

Returns
The opaque ove_work_t handle.

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