16#ifdef CONFIG_OVE_WORKQUEUE
18#include <ove/workqueue.h>
44template <
size_t StackSize = 0>
58 requires (StackSize > 0)
60#ifdef CONFIG_OVE_ZERO_HEAP
61 static_assert(StackSize > 0,
62 "StackSize must be > 0 in zero-heap mode");
63 int err = ove_workqueue_init(&handle_, &storage_, name,
64 prio, StackSize, stack_);
66 int err = ove_workqueue_create(&handle_, name, prio,
69 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
77#ifdef CONFIG_OVE_ZERO_HEAP
78 ove_workqueue_deinit(handle_);
80 ove_workqueue_destroy(handle_);
87#ifdef CONFIG_OVE_ZERO_HEAP
96 other.handle_ =
nullptr;
105 if (
this != &other) {
106 if (handle_) ove_workqueue_destroy(handle_);
107 handle_ = other.handle_;
108 other.handle_ =
nullptr;
118 bool valid()
const {
return handle_ !=
nullptr; }
124 ove_workqueue_t
handle()
const {
return handle_; }
127 ove_workqueue_t handle_ =
nullptr;
128#ifdef CONFIG_OVE_ZERO_HEAP
129 ove_workqueue_storage_t storage_ = {};
130 OVE_THREAD_STACK_MEMBER_(stack_,
131 StackSize > 0 ? StackSize : 1);
154 template <
typename F>
156#ifdef CONFIG_OVE_ZERO_HEAP
157 int err = ove_work_init_static(&handle_, &storage_,
160 int err = ove_work_init(&handle_, handler);
162 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
169 if (!handle_)
return;
170#ifndef CONFIG_OVE_ZERO_HEAP
171 ove_work_free(handle_);
176 Work &operator=(
const Work &) =
delete;
178#ifdef CONFIG_OVE_ZERO_HEAP
186 Work(
Work &&other) noexcept : handle_(other.handle_) {
187 other.handle_ =
nullptr;
196 if (
this != &other) {
197 if (handle_) ove_work_free(handle_);
198 handle_ = other.handle_;
199 other.handle_ =
nullptr;
213 return ove_work_submit(wq.
handle(), handle_);
226 return ove_work_submit_delayed(wq.
handle(), handle_,
238 return ove_work_cancel(handle_);
245 bool valid()
const {
return handle_ !=
nullptr; }
251 ove_work_t
handle()
const {
return handle_; }
254 ove_work_t handle_ =
nullptr;
255#ifdef CONFIG_OVE_ZERO_HEAP
256 ove_work_storage_t storage_ = {};
RAII wrapper representing a single deferred work item.
Definition workqueue.hpp:145
int submit_delayed(Workqueue< S > &wq, uint32_t delay_ms)
Submits the work item to a workqueue with a delay.
Definition workqueue.hpp:224
int cancel()
Attempts to cancel a pending work item.
Definition workqueue.hpp:237
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition workqueue.hpp:245
Work(Work &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition workqueue.hpp:186
Work & operator=(Work &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition workqueue.hpp:195
int submit(Workqueue< S > &wq)
Submits the work item to a workqueue for immediate execution.
Definition workqueue.hpp:212
Work(F handler)
Constructs a work item with the given handler function.
Definition workqueue.hpp:155
ove_work_t handle() const
Returns the raw oveRTOS work handle.
Definition workqueue.hpp:251
~Work()
Destroys the work item, freeing its kernel resource (heap mode).
Definition workqueue.hpp:168
RAII wrapper around an oveRTOS workqueue (dedicated worker thread).
Definition workqueue.hpp:45
Workqueue(Workqueue &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition workqueue.hpp:95
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition workqueue.hpp:118
Workqueue(const char *name, ove_prio_t prio)
Constructs and starts the workqueue.
Definition workqueue.hpp:57
ove_workqueue_t handle() const
Returns the raw oveRTOS workqueue handle.
Definition workqueue.hpp:124
~Workqueue()
Destroys the workqueue and terminates the worker thread.
Definition workqueue.hpp:75
Workqueue & operator=(Workqueue &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition workqueue.hpp:104
Concept satisfied by any callable convertible to ove_work_fn.
Definition workqueue.hpp:31
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.