oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Typedefs | Functions
Work Queue

Deferred work execution on a dedicated RTOS thread. More...

Typedefs

typedef void(* ove_work_fn) (ove_work_t work)
 Prototype for a work item handler function.
 

Functions

int ove_workqueue_init (ove_workqueue_t *wq, ove_workqueue_storage_t *storage, const char *name, ove_prio_t priority, size_t stack_size, void *stack)
 Initialise a work queue using caller-provided static storage.
 
void ove_workqueue_deinit (ove_workqueue_t wq)
 Deinitialise a statically-allocated work queue.
 
int ove_work_init_static (ove_work_t *work, ove_work_storage_t *storage, ove_work_fn handler)
 Initialise a work item using caller-provided static storage.
 
int ove_work_init (ove_work_t *work, ove_work_fn handler)
 Allocate and initialise a heap-backed work item.
 
void ove_work_free (ove_work_t work)
 Free a heap-allocated work item.
 
int ove_workqueue_create (ove_workqueue_t *wq, const char *name, ove_prio_t priority, size_t stack_size)
 Allocate a heap-backed work queue.
 
void ove_workqueue_destroy (ove_workqueue_t wq)
 Destroy a heap-allocated work queue.
 
int ove_work_submit (ove_workqueue_t wq, ove_work_t work)
 Submit a work item for immediate execution on the work queue.
 
int ove_work_submit_delayed (ove_workqueue_t wq, ove_work_t work, uint32_t delay_ms)
 Submit a work item for execution after a delay.
 
int ove_work_cancel (ove_work_t work)
 Cancel a pending work item before it executes.
 

Detailed Description

Deferred work execution on a dedicated RTOS thread.

A work queue owns a single thread that executes submitted work items in FIFO order. Work items may be submitted immediately or after a delay, and pending items may be cancelled before execution begins.

Two allocation strategies are supported for the queue itself:

Work items similarly have static (ove_work_init_static) and heap (ove_work_init / ove_work_free) variants.

Note
Requires CONFIG_OVE_WORKQUEUE.

Typedef Documentation

◆ ove_work_fn

typedef void(* ove_work_fn) (ove_work_t work)

Prototype for a work item handler function.

Called by the work queue thread when the work item is executed. The work handle may be used to reschedule or identify the item inside the handler.

Parameters
[in]workHandle of the work item being executed.

Function Documentation

◆ ove_workqueue_init()

int ove_workqueue_init ( ove_workqueue_t wq,
ove_workqueue_storage_t *  storage,
const char *  name,
ove_prio_t  priority,
size_t  stack_size,
void *  stack 
)

Initialise a work queue using caller-provided static storage.

Creates the underlying RTOS thread with the given name, priority, stack_size, and pre-allocated stack buffer. The queue begins dispatching items as soon as the first work item is submitted.

Parameters
[out]wqReceives the initialised work queue handle.
[in]storagePointer to statically-allocated work queue storage.
[in]nameHuman-readable name for the underlying thread.
[in]priorityThread priority for the work queue thread.
[in]stack_sizeSize of the thread stack in bytes.
[in]stackPointer to the pre-allocated stack buffer.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_WORKQUEUE.

◆ ove_workqueue_deinit()

void ove_workqueue_deinit ( ove_workqueue_t  wq)

Deinitialise a statically-allocated work queue.

Stops the underlying thread and releases all RTOS resources. Any work items still in the queue at deinit time are discarded without execution.

Parameters
[in]wqWork queue handle returned by ove_workqueue_init.
Note
Requires CONFIG_OVE_WORKQUEUE.

◆ ove_work_init_static()

int ove_work_init_static ( ove_work_t work,
ove_work_storage_t *  storage,
ove_work_fn  handler 
)

Initialise a work item using caller-provided static storage.

Associates the handler function with the work item. The item must be initialised before it can be submitted to a work queue.

Parameters
[out]workReceives the initialised work handle.
[in]storagePointer to statically-allocated work item storage.
[in]handlerFunction to call when the work item is executed.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_WORKQUEUE.

◆ ove_work_init()

int ove_work_init ( ove_work_t work,
ove_work_fn  handler 
)

Allocate and initialise a heap-backed work item.

Allocates the work item control structure from the heap and associates handler with it.

Parameters
[out]workReceives the created work handle.
[in]handlerFunction to call when the work item is executed.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_WORKQUEUE and that CONFIG_OVE_ZERO_HEAP is not set.

◆ ove_work_free()

void ove_work_free ( ove_work_t  work)

Free a heap-allocated work item.

Releases the memory allocated by ove_work_init. The item must not be pending in a work queue when this function is called; cancel it first with ove_work_cancel if necessary.

Parameters
[in]workWork handle returned by ove_work_init.
Note
Requires CONFIG_OVE_WORKQUEUE and that CONFIG_OVE_ZERO_HEAP is not set.

◆ ove_workqueue_create()

int ove_workqueue_create ( ove_workqueue_t wq,
const char *  name,
ove_prio_t  priority,
size_t  stack_size 
)

Allocate a heap-backed work queue.

Allocates the work queue and its thread from the heap and starts dispatching immediately.

Parameters
[out]wqReceives the created work queue handle.
[in]nameHuman-readable name for the underlying thread.
[in]priorityThread priority for the work queue thread.
[in]stack_sizeStack size in bytes for the work queue thread.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_WORKQUEUE and OVE_HEAP_WORKQUEUE.

◆ ove_workqueue_destroy()

void ove_workqueue_destroy ( ove_workqueue_t  wq)

Destroy a heap-allocated work queue.

Stops the underlying thread and frees all resources. Pending work items are discarded. Must only be called on handles from ove_workqueue_create.

Parameters
[in]wqWork queue handle returned by ove_workqueue_create.
Note
Requires CONFIG_OVE_WORKQUEUE and OVE_HEAP_WORKQUEUE.

◆ ove_work_submit()

int ove_work_submit ( ove_workqueue_t  wq,
ove_work_t  work 
)

Submit a work item for immediate execution on the work queue.

Enqueues work for execution on wq. If the item is already pending the call may fail or reset the pending state depending on the underlying implementation.

Parameters
[in]wqTarget work queue handle.
[in]workWork item handle to submit.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_work_submit_delayed()

int ove_work_submit_delayed ( ove_workqueue_t  wq,
ove_work_t  work,
uint32_t  delay_ms 
)

Submit a work item for execution after a delay.

Schedules work to run on wq after at least delay_ms milliseconds have elapsed. The item may be cancelled before the delay expires using ove_work_cancel.

Parameters
[in]wqTarget work queue handle.
[in]workWork item handle to schedule.
[in]delay_msMinimum delay before execution in milliseconds.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_work_cancel()

int ove_work_cancel ( ove_work_t  work)

Cancel a pending work item before it executes.

Attempts to remove work from the queue before its handler is called. Has no effect if the item is not pending or is already executing.

Parameters
[in]workWork item handle to cancel.
Returns
OVE_OK if the item was successfully cancelled, OVE_ERR_INVAL if the item was not pending, or another negative error code on failure.