oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
ove::stop_source Class Reference

Writable counterpart to stop_token. std::stop_source analog. More...

#include <thread.hpp>

Public Member Functions

constexpr stop_source (ove_thread_t h) noexcept
 
bool request_stop () noexcept
 Set the stop flag on the associated thread.
 
bool stop_requested () const noexcept
 
bool stop_possible () const noexcept
 
 operator bool () const noexcept
 Convertible to bool reflecting stop_requested. See stop_token::operator bool.
 
stop_token get_token () const noexcept
 
ove_thread_t handle () const noexcept
 

Friends

constexpr bool operator== (const stop_source &, const stop_source &) noexcept=default
 

Detailed Description

Writable counterpart to stop_token. std::stop_source analog.

Use to issue cooperative stop requests on a thread without holding the owning Thread wrapper. Pair with stop_token for read-only observers; together they mirror std::stop_source / std::stop_token from C++20.

Default-constructed is empty — equivalent to std::stop_source(std::nostopstate). Bind to a thread either via Thread::get_stop_source or by explicit construction from an ove_thread_t handle (advanced use).

ove::Thread<4096> worker(cooperative_worker, OVE_PRIO_NORMAL, "w");
ove::stop_source src = worker.get_stop_source();
// Pass `src` to helpers that need write-only stop capability.
src.request_stop(); // returns true the first time, false after.
RAII wrapper around an oveRTOS thread (task).
Definition thread.hpp:343
Writable counterpart to stop_token. std::stop_source analog.
Definition thread.hpp:128
bool request_stop() noexcept
Set the stop flag on the associated thread.
Definition thread.hpp:144

Lifetime: the underlying stop state lives in the kernel thread's TCB. A stop_source remains usable until that thread terminates; use after that is undefined (matches std::stop_source after the associated state is destroyed).

Trivially copyable; pass by value freely. Distinct from std::stop_source in that there is no shared reference count — the kernel owns the single stop slot per thread.

Member Function Documentation

◆ request_stop()

bool ove::stop_source::request_stop ( )
inlinenoexcept

Set the stop flag on the associated thread.

Returns
true if this call set the flag (it was previously unset AND a stop state exists). Returns false on a default-constructed source or on repeat calls. Matches std::stop_source::request_stop semantics.

Safe from any context (ISR, other thread, the thread itself).

◆ stop_requested()

bool ove::stop_source::stop_requested ( ) const
inlinenoexcept
Returns
true if the stop flag is set on the associated thread.

◆ stop_possible()

bool ove::stop_source::stop_possible ( ) const
inlinenoexcept
Returns
true if this source references a real thread (not default-constructed).

◆ get_token()

stop_token ove::stop_source::get_token ( ) const
inlinenoexcept
Returns
A stop_token observing the same stop state.

◆ handle()

ove_thread_t ove::stop_source::handle ( ) const
inlinenoexcept
Returns
The raw ove_thread_t handle (may be null).

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