oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
ove::Thread< StackSize > Class Template Reference

RAII wrapper around an oveRTOS thread (task). More...

#include <thread.hpp>

Public Member Functions

template<typename F >
requires (StackSize > 0) && ThreadEntry<F>
 Thread (F entry, void *ctx, ove_prio_t prio, const char *name)
 Constructs and starts the thread.
 
 ~Thread ()
 Destroys the thread wrapper, terminating and releasing the kernel thread.
 
 Thread (const Thread &)=delete
 
Threadoperator= (const Thread &)=delete
 
 Thread (Thread &&other) noexcept
 Move constructor — transfers ownership of the kernel handle.
 
Threadoperator= (Thread &&other) noexcept
 Move-assignment operator — transfers ownership of the kernel handle.
 
void set_priority (ove_prio_t prio)
 Changes the priority of the thread at runtime.
 
void suspend ()
 Suspends execution of the thread.
 
void resume ()
 Resumes a previously suspended thread.
 
ove_thread_state_t get_state () const
 Returns the current execution state of the thread.
 
size_t get_stack_usage () const
 Returns the number of bytes used by the thread's stack so far.
 
int get_runtime_stats (struct ove_thread_stats *stats) const
 Retrieves runtime statistics for the thread.
 
bool valid () const
 Returns true if the underlying kernel handle is non-null.
 
ove_thread_t handle () const
 Returns the raw oveRTOS thread handle.
 

Static Public Member Functions

static void sleep_ms (uint32_t ms)
 Suspends the calling thread for the specified duration.
 
static void yield ()
 Yields the calling thread's remaining time slice to the scheduler.
 
static ove_thread_t self ()
 Returns the oveRTOS handle of the currently executing thread.
 

Detailed Description

template<size_t StackSize = 0>
class ove::Thread< StackSize >

RAII wrapper around an oveRTOS thread (task).

Creates and starts a thread on construction. The thread is destroyed and the underlying kernel resource is released on destruction.

In zero-heap mode (CONFIG_OVE_ZERO_HEAP) the stack is stored as a member array, so StackSize must be greater than zero and move operations are disabled. On heap-enabled builds a non-zero StackSize is still required because it is passed to the kernel at construction time.

Template Parameters
StackSizeStack size in bytes for the thread (must be > 0).
Note
Not copyable. Move-only when heap allocation is enabled.

Constructor & Destructor Documentation

◆ Thread() [1/2]

template<size_t StackSize = 0>
template<typename F >
requires (StackSize > 0) && ThreadEntry<F>
ove::Thread< StackSize >::Thread ( entry,
void *  ctx,
ove_prio_t  prio,
const char *  name 
)
inline

Constructs and starts the thread.

Only participates in overload resolution when StackSize > 0 and the entry function satisfies ThreadEntry.

Template Parameters
FEntry function type satisfying ThreadEntry.
Parameters
[in]entryFunction pointer (or compatible callable) to use as the thread entry point, with signature void fn(void*).
[in]ctxOpaque pointer passed as the argument to entry.
[in]prioThread priority as an ove_prio_t value.
[in]nameHuman-readable name for the thread (for debugging).

Asserts at startup if thread creation fails.

◆ Thread() [2/2]

template<size_t StackSize = 0>
ove::Thread< StackSize >::Thread ( Thread< StackSize > &&  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=()

template<size_t StackSize = 0>
Thread & ove::Thread< StackSize >::operator= ( Thread< StackSize > &&  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.

◆ set_priority()

template<size_t StackSize = 0>
void ove::Thread< StackSize >::set_priority ( ove_prio_t  prio)
inline

Changes the priority of the thread at runtime.

Parameters
[in]prioNew priority value.

◆ suspend()

template<size_t StackSize = 0>
void ove::Thread< StackSize >::suspend ( )
inline

Suspends execution of the thread.

The thread will not be scheduled until resume() is called.

◆ get_state()

template<size_t StackSize = 0>
ove_thread_state_t ove::Thread< StackSize >::get_state ( ) const
inline

Returns the current execution state of the thread.

Returns
An ove_thread_state_t value representing the thread state.

◆ get_stack_usage()

template<size_t StackSize = 0>
size_t ove::Thread< StackSize >::get_stack_usage ( ) const
inline

Returns the number of bytes used by the thread's stack so far.

Returns
Peak stack usage in bytes.

◆ get_runtime_stats()

template<size_t StackSize = 0>
int ove::Thread< StackSize >::get_runtime_stats ( struct ove_thread_stats *  stats) const
inline

Retrieves runtime statistics for the thread.

Parameters
[out]statsPointer to a struct that receives the statistics.
Returns
OVE_OK on success, or a negative error code.

◆ valid()

template<size_t StackSize = 0>
bool ove::Thread< StackSize >::valid ( ) const
inline

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

Returns
true when the thread was successfully created.

◆ handle()

template<size_t StackSize = 0>
ove_thread_t ove::Thread< StackSize >::handle ( ) const
inline

Returns the raw oveRTOS thread handle.

Returns
The opaque ove_thread_t handle.

◆ sleep_ms()

template<size_t StackSize = 0>
static void ove::Thread< StackSize >::sleep_ms ( uint32_t  ms)
inlinestatic

Suspends the calling thread for the specified duration.

Parameters
[in]msSleep duration in milliseconds.

◆ self()

template<size_t StackSize = 0>
static ove_thread_t ove::Thread< StackSize >::self ( )
inlinestatic

Returns the oveRTOS handle of the currently executing thread.

Returns
The opaque ove_thread_t handle of the calling thread.

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