oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
workqueue.h
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
33#ifndef OVE_WORKQUEUE_H
34#define OVE_WORKQUEUE_H
35
36#include "ove/types.h"
37#include "ove/thread.h"
38#include "ove_config.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
53typedef void (*ove_work_fn)(ove_work_t work);
54
55#include "ove/storage.h"
56
57#ifdef CONFIG_OVE_WORKQUEUE
58
76 ove_workqueue_storage_t *storage,
77 const char *name, ove_prio_t priority,
78 size_t stack_size, void *stack);
79
90
104 ove_work_storage_t *storage,
105 ove_work_fn handler);
106
107#ifndef CONFIG_OVE_ZERO_HEAP
121
134#endif
135
149#ifdef OVE_HEAP_WORKQUEUE
150int ove_workqueue_create(ove_workqueue_t *wq, const char *name,
151 ove_prio_t priority, size_t stack_size);
152
163#elif !defined(__ZIG_CIMPORT__) /* !OVE_HEAP_WORKQUEUE — zero-heap mode */
164
165/* Unified macro — stack_size must be a compile-time constant. */
166#define ove_workqueue_create(pwq, name, priority, stack_size) \
167 ({ static ove_workqueue_storage_t _ove_stor_; \
168 static uint8_t _ove_stk_[(stack_size)]; \
169 ove_workqueue_init((pwq), &_ove_stor_, (name), (priority), \
170 (stack_size), _ove_stk_); })
171#define ove_workqueue_destroy(wq) ove_workqueue_deinit(wq)
172
173#endif /* OVE_HEAP_WORKQUEUE */
174
187
201 ove_work_t work, uint32_t delay_ms);
202
214
215#else /* !CONFIG_OVE_WORKQUEUE */
216
217static inline int ove_workqueue_create(ove_workqueue_t *wq, const char *n, ove_prio_t p, size_t s) { (void)wq; (void)n; (void)p; (void)s; return OVE_ERR_NOT_SUPPORTED; }
218static inline void ove_workqueue_destroy(ove_workqueue_t wq) { (void)wq; }
219static inline int ove_work_init(ove_work_t *w, ove_work_fn h) { (void)w; (void)h; return OVE_ERR_NOT_SUPPORTED; }
220static inline void ove_work_free(ove_work_t w) { (void)w; }
221static inline int ove_work_submit(ove_workqueue_t wq, ove_work_t w) { (void)wq; (void)w; return OVE_ERR_NOT_SUPPORTED; }
222static inline int ove_work_submit_delayed(ove_workqueue_t wq, ove_work_t w, uint32_t d) { (void)wq; (void)w; (void)d; return OVE_ERR_NOT_SUPPORTED; }
223static inline int ove_work_cancel(ove_work_t w) { (void)w; return OVE_ERR_NOT_SUPPORTED; }
224
225#endif /* CONFIG_OVE_WORKQUEUE */
226
227#ifdef __cplusplus
228}
229#endif
230
/* end of ove_workqueue group */
232
233#endif /* OVE_WORKQUEUE_H */
ove_prio_t
Portable thread-priority levels.
Definition thread.h:67
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_workqueue * ove_workqueue_t
Opaque handle for a work queue object.
Definition types.h:100
struct ove_work * ove_work_t
Opaque handle for a deferred work item.
Definition types.h:103
void ove_work_free(ove_work_t work)
Free a heap-allocated work item.
void ove_workqueue_destroy(ove_workqueue_t wq)
Destroy a heap-allocated work queue.
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.
int ove_work_init(ove_work_t *work, ove_work_fn handler)
Allocate and initialise a heap-backed work item.
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_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_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.
int ove_work_cancel(ove_work_t work)
Cancel a pending work item before it executes.
void(* ove_work_fn)(ove_work_t work)
Prototype for a work item handler function.
Definition workqueue.h:53
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.
void ove_workqueue_deinit(ove_workqueue_t wq)
Deinitialise a statically-allocated work queue.