pub trait Scheduler {
// Required methods
fn next_to_run(&self) -> Option<Box<Thread>>;
fn push_to_queue(&self, th: Box<Thread>);
fn timer_tick(&self);
}Expand description
A trait for a thread scheduler.
The Scheduler trait defines the common functionality expected from a
thread scheduler. It provides an interface for managing threads, determining
which thread to run next, and handling periodic timer interrupts. A thread
scheduler is responsible for controlling the execution of threads in a
system. The scheduler determines when each thread is allowed to run, how to
handle context switching, and ensures fair allocation of CPU time among all
threads.
This trait can be implemented by different types of schedulers, such as Round Robin, Priority-based, or Multi-level Queue schedulers. Each implementation may have a unique strategy for selecting the next thread to run and handling thread management.
Required Methods§
Sourcefn next_to_run(&self) -> Option<Box<Thread>>
fn next_to_run(&self) -> Option<Box<Thread>>
Peek a next thread to run.
This method checks the queue and returns the next thread to run. If no
threads are available, it returns None.
§Returns
Returns an Option<Box<Thread>> containing the next thread to run or
None if no threads are available to execute.
Sourcefn push_to_queue(&self, th: Box<Thread>)
fn push_to_queue(&self, th: Box<Thread>)
Sourcefn timer_tick(&self)
fn timer_tick(&self)
Called on every timer interrupt (1ms).
This method is triggered by the timer interrupt (e.g., every 1ms) and allows the scheduler to manage time slices, perform context switching, or adjust thread priorities as needed.
Implementations§
Source§impl dyn Scheduler
impl dyn Scheduler
Sourcepub fn reschedule(&self)
pub fn reschedule(&self)
Reschedule the current thread.
Sourcepub(crate) unsafe fn park_thread(
&self,
th: &mut Thread,
) -> Result<ParkHandle, ()>
pub(crate) unsafe fn park_thread( &self, th: &mut Thread, ) -> Result<ParkHandle, ()>
Park a thread ‘th’ and return ParkHandle.