pub struct Thread {
pub id: usize,
pub registers: Registers,
kernel_stack: &'static mut [u32],
pub exited: bool,
action: extern "C" fn(),
}
Expand description
The Thread is an object used by the scheduler.
Fields§
§id: usize
Thread id, each thread should have a different one
registers: Registers
Saved registers
kernel_stack: &'static mut [u32]
Kernel stack
exited: bool
If this thread has been killed
action: extern "C" fn()
Function pointer
Implementations§
source§impl Thread
impl Thread
sourcepub const fn new(action: extern "C" fn()) -> Self
pub const fn new(action: extern "C" fn()) -> Self
Creates a new thread with the given action.
If the user_stack
is null, it is set up with the action as entry point.
pub fn init(&mut self, kernel_stack: &'static mut [u32])
sourcepub fn kernel_stack(&self) -> *mut ()
pub fn kernel_stack(&self) -> *mut ()
Returns the top of the kernel stack pointer.
sourceextern "C" fn kernel_kickoff(action: extern "C" fn())
extern "C" fn kernel_kickoff(action: extern "C" fn())
Kickoff function that is called in kernel mode.
If the thread was configured with a user stack, user_kickoff
is called in user mode.
Otherwise the action
is executed directly in the kernel.
sourcepub fn resume(&mut self, next: &Self)
pub fn resume(&mut self, next: &Self)
Switches from the currently running thread to the next
one.
The values currently present in the callee-saved registers will be
stored in this threads context-structure, the corresponding values
belonging to next
thread will be loaded.
sourcepub fn go(&self)
pub fn go(&self)
Activates the first thread on this CPU.
Calling the method starts the first thread on the calling CPU. From then on, Thread::resume must be used all subsequent context switches.