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
impl Thread
pub fn new(thread: &mut rt_thread) -> &Thread
Sourcepub fn create<P>(
name: &str,
entry: ThreadEntry<P::MiddleState>,
parameter: P,
stack_size: u32,
priority: u8,
tick: u32,
) -> Option<Thread>where
P: CallbackParameter,
pub fn create<P>(
name: &str,
entry: ThreadEntry<P::MiddleState>,
parameter: P,
stack_size: u32,
priority: u8,
tick: u32,
) -> Option<Thread>where
P: CallbackParameter,
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
pub fn create_closure<F>( name: &str, entry: F, stack_size: u32, priority: u8, tick: u32, ) -> Option<Thread>
Sourcepub fn current() -> Option<Thread>
pub fn current() -> Option<Thread>
This function will return self thread object
@return the self thread object
Sourcepub unsafe fn find(name: &str) -> Option<Thread>
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.
pub fn find_locked(name: &str) -> Option<ThreadLocked>
pub fn is_existed(name: &str) -> bool
Sourcepub fn startup(&mut self) -> Result<()>
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
Sourcepub unsafe fn delete(self) -> Result<()>
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.
Sourcepub fn yield0() -> Result<()>
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
Sourcepub fn delay(tick: rt_tick_t) -> Result<()>
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
Sourcepub fn mdelay(ms: i32) -> Result<()>
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