Struct Thread

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

All methods use immutable self since the safety is guaranteed by rt-thread internal

TODO: thread cleanup and unwind

https://blog.rust-lang.org/inside-rust/2020/02/27/ffi-unwind-design-meeting.html

TODO: thread control

Implementations§

Source§

impl Thread

Source

pub fn new(thread: &mut rt_thread) -> &Thread

Source

pub fn create<P>( name: &str, entry: ThreadEntry<P::MiddleState>, parameter: P, stack_size: u32, priority: u8, tick: u32, ) -> Option<Thread>

This function will create a thread object and allocate thread object memory and stack.

@param name the name of thread, which shall be unique @param entry the entry function of thread @param parameter the parameter of thread enter function @param stack_size the size of thread stack @param priority the priority of thread @param tick the time slice if there are same priority thread

@return the created thread object

Source

pub fn create_closure<F>( name: &str, entry: F, stack_size: u32, priority: u8, tick: u32, ) -> Option<Thread>
where F: FnOnce() + Send + 'static,

Source

pub fn current() -> Option<Thread>

This function will return self thread object

@return the self thread object

Source

pub unsafe fn find(name: &str) -> Option<Thread>

This function will find the specified thread.

@param name the name of thread finding

@return the found thread

@note please don’t invoke this function in interrupt status.

§Safety

The thread returned is shared and could be potenially deleted by other thread later.

Source

pub fn find_locked(name: &str) -> Option<ThreadLocked>

Source

pub fn is_existed(name: &str) -> bool

Source

pub fn startup(&mut self) -> Result<()>

This function will start a thread and put it to system ready queue

@param thread the thread to be started

@return the operation status, RT_EOK on OK, -RT_ERROR on error

Source

pub unsafe fn delete(self) -> Result<()>

This function will delete a thread. The thread object will be removed from thread queue and deleted from system object management in the idle thread.

@param thread the thread to be deleted

@return the operation status, RT_EOK on OK, -RT_ERROR on error

§Wanring:

Rust thread has no cleanup function and is not able to unwind. Directly stopping a Rust thread may lead to resoucre leak.

Source

pub fn yield0() -> Result<()>

This function will let current thread yield processor, and scheduler will choose a highest thread to run. After yield processor, the current thread is still in READY state.

@return RT_EOK

Source

pub fn delay(tick: rt_tick_t) -> Result<()>

This function will let current thread delay for some ticks.

@param tick the delay ticks

@return RT_EOK

Source

pub fn mdelay(ms: i32) -> Result<()>

This function will let current thread delay for some milliseconds.

@param ms the delay ms time

@return RT_EOK

Source

pub fn suspend(&mut self) -> Result<()>

This function will suspend the specified thread.

@return the operation status, RT_EOK on OK, -RT_ERROR on error

@note if suspend self thread, after this function call, the rt_schedule() must be invoked.

Source

pub fn resume(&mut self) -> Result<()>

This function will resume a thread and put it to system ready queue.

@param thread the thread to be resumed

@return the operation status, RT_EOK on OK, -RT_ERROR on error

Trait Implementations§

Source§

impl Debug for Thread

Source§

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

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

impl Object for Thread

Source§

impl Send 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> 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, 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.