Skip to main content

Thread

Struct Thread 

Source
pub struct Thread { /* private fields */ }
Expand description

Non-owning handle to an RTOS thread.

Returned by Thread::current and JoinHandle::thread. Dropping a Thread does not destroy the underlying RTOS thread — use JoinHandle for that. Carries the read-only and signal-only operations (get_state, suspend/resume, request_stop, …).

Implementations§

Source§

impl Thread

Source

pub fn sleep_ms(ms: u32)

Sleep the current thread for ms milliseconds.

Source

pub fn yield_now()

Yield the current thread’s time slice.

Source

pub fn current() -> Self

Get a non-owning handle to the currently running thread.

Source

pub fn builder() -> Builder

Begin spawning a new thread. Returns a fluent Builder.

let h = Thread::builder()
    .name(c"worker")
    .priority(Priority::Normal)
    .stack_size(4096)
    .spawn(|tok| { while !tok.is_stopped() { /* work */ } })?;
Source

pub fn suspend(&self)

Suspend this thread.

Source

pub fn resume(&self)

Resume this thread.

Source

pub fn set_priority(&self, prio: Priority)

Set this thread’s priority.

Source

pub fn get_stack_usage(&self) -> usize

Get current stack usage in bytes.

Source

pub fn get_state(&self) -> ThreadState

Get the thread’s current state.

Source

pub fn get_runtime_stats(&self) -> Result<ThreadStats>

Get runtime statistics (CPU time and utilization) for this thread.

§Errors

Returns an error if the RTOS does not support runtime statistics or the thread handle is invalid.

Source

pub fn request_stop(&self)

Request the thread to stop cooperatively.

Sets the per-thread atomic cancellation flag. The worker must poll StopToken::is_stopped (via the token it received at spawn time) for this to have any effect — the substrate does NOT force-terminate. Safe from any context (ISR, other thread, the thread itself). Idempotent; the flag is sticky.

Source

pub fn stop_token(&self) -> StopToken

Get a StopToken referencing this thread’s cancellation flag.

Source

pub fn stop_requested(&self) -> bool

true if Thread::request_stop has been called on this thread.

Source

pub fn raw_handle(&self) -> ove_thread_t

Raw handle accessor for advanced use.

Trait Implementations§

Source§

impl Clone for Thread

Source§

fn clone(&self) -> Thread

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Thread

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Thread

Source§

impl Send for Thread

Source§

impl Sync for Thread

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.