16#include <ove/thread.h>
37template <
size_t StackSize = 0>
56 Thread(F entry,
void *ctx, ove_prio_t prio,
const char *name)
59 struct ove_thread_desc desc = {};
64 desc.stack_size = StackSize;
65#ifdef CONFIG_OVE_ZERO_HEAP
66 static_assert(StackSize > 0,
67 "StackSize must be > 0 in zero-heap mode");
69 int err = ove_thread_init(&handle_, &storage_, &desc);
71 int err = ove_thread_create_(&handle_, &desc);
73 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
81#ifdef CONFIG_OVE_ZERO_HEAP
82 ove_thread_deinit(handle_);
84 ove_thread_destroy(handle_);
91#ifdef CONFIG_OVE_ZERO_HEAP
100 other.handle_ =
nullptr;
109 if (
this != &other) {
110 if (handle_) ove_thread_destroy(handle_);
111 handle_ = other.handle_;
112 other.handle_ =
nullptr;
123 ove_thread_set_priority(handle_, prio);
132 ove_thread_suspend(handle_);
139 ove_thread_resume(handle_);
147 return ove_thread_get_state(handle_);
155 return ove_thread_get_stack_usage(handle_);
164 return ove_thread_get_runtime_stats(handle_, stats);
171 bool valid()
const {
return handle_ !=
nullptr; }
177 ove_thread_t
handle()
const {
return handle_; }
184 ove_thread_sleep_ms(ms);
199 return ove_thread_get_self();
203 ove_thread_t handle_ =
nullptr;
204#ifdef CONFIG_OVE_ZERO_HEAP
205 ove_thread_storage_t storage_ = {};
206 OVE_THREAD_STACK_MEMBER_(stack_,
207 StackSize > 0 ? StackSize : 1);
230 struct ove_mem_stats ms{};
231 int ret = ove_sys_get_mem_stats(&ms);
233 stats.
total = ms.total;
234 stats.
free = ms.free;
235 stats.
used = ms.used;
249 ove_thread_state_t
state{OVE_THREAD_STATE_UNKNOWN};
262 size_t *count =
nullptr) {
263 struct ove_thread_info buf[16];
265 int ret = ove_thread_list(buf, max < 16 ? max : 16, &n);
267 for (
size_t i = 0; i < n && i < max; i++) {
268 out[i].
name = buf[i].name;
269 out[i].
state = buf[i].state;
273 if (count) *count = n;
RAII wrapper around an oveRTOS thread (task).
Definition thread.hpp:38
void set_priority(ove_prio_t prio)
Changes the priority of the thread at runtime.
Definition thread.hpp:122
Thread & operator=(Thread &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition thread.hpp:108
Thread(F entry, void *ctx, ove_prio_t prio, const char *name)
Constructs and starts the thread.
Definition thread.hpp:56
ove_thread_t handle() const
Returns the raw oveRTOS thread handle.
Definition thread.hpp:177
~Thread()
Destroys the thread wrapper, terminating and releasing the kernel thread.
Definition thread.hpp:79
void resume()
Resumes a previously suspended thread.
Definition thread.hpp:138
int get_runtime_stats(struct ove_thread_stats *stats) const
Retrieves runtime statistics for the thread.
Definition thread.hpp:163
Thread(Thread &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition thread.hpp:99
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition thread.hpp:171
ove_thread_state_t get_state() const
Returns the current execution state of the thread.
Definition thread.hpp:146
static ove_thread_t self()
Returns the oveRTOS handle of the currently executing thread.
Definition thread.hpp:198
size_t get_stack_usage() const
Returns the number of bytes used by the thread's stack so far.
Definition thread.hpp:154
void suspend()
Suspends execution of the thread.
Definition thread.hpp:131
static void yield()
Yields the calling thread's remaining time slice to the scheduler.
Definition thread.hpp:190
static void sleep_ms(uint32_t ms)
Suspends the calling thread for the specified duration.
Definition thread.hpp:183
Concept satisfied by any callable convertible to void(*)(void*).
Definition types.hpp:54
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
int get_mem_stats(MemStats &stats)
Query system heap statistics.
Definition thread.hpp:229
int thread_list(ThreadInfo *out, size_t max, size_t *count=nullptr)
List all threads in the system.
Definition thread.hpp:261
System heap statistics snapshot.
Definition thread.hpp:217
size_t used
Definition thread.hpp:220
size_t total
Definition thread.hpp:218
size_t peak_used
Definition thread.hpp:221
size_t free
Definition thread.hpp:219
Snapshot of a single thread.
Definition thread.hpp:247
const char * name
Thread name.
Definition thread.hpp:248
size_t stack_used
Peak stack usage in bytes.
Definition thread.hpp:251
ove_thread_state_t state
Current state.
Definition thread.hpp:249
int priority
Scheduling priority.
Definition thread.hpp:250
Common type definitions and concepts for the C++ wrapper layer.