Trait scheduler::BaseScheduler
source · pub trait BaseScheduler {
type SchedItem;
// Required methods
fn init(&mut self);
fn add_task(&mut self, task: Self::SchedItem);
fn remove_task(&mut self, task: &Self::SchedItem) -> Option<Self::SchedItem>;
fn pick_next_task(&mut self) -> Option<Self::SchedItem>;
fn put_prev_task(&mut self, prev: Self::SchedItem, preempt: bool);
fn task_tick(&mut self, current: &Self::SchedItem) -> bool;
fn set_priority(&mut self, task: &Self::SchedItem, prio: isize) -> bool;
}
Expand description
The base scheduler trait that all schedulers should implement.
All tasks in the scheduler are considered runnable. If a task is go to sleep, it should be removed from the scheduler.
Required Associated Types§
Required Methods§
sourcefn remove_task(&mut self, task: &Self::SchedItem) -> Option<Self::SchedItem>
fn remove_task(&mut self, task: &Self::SchedItem) -> Option<Self::SchedItem>
Removes a task by its reference from the scheduler. Returns the owned removed task with ownership if it exists.
Safety
The caller should ensure that the task is in the scheduler, otherwise the behavior is undefined.
sourcefn pick_next_task(&mut self) -> Option<Self::SchedItem>
fn pick_next_task(&mut self) -> Option<Self::SchedItem>
Picks the next task to run, it will be removed from the scheduler.
Returns None
if there is not runnable task.
sourcefn put_prev_task(&mut self, prev: Self::SchedItem, preempt: bool)
fn put_prev_task(&mut self, prev: Self::SchedItem, preempt: bool)
Puts the previous task back to the scheduler. The previous task is usually placed at the end of the ready queue, making it less likely to be re-scheduled.
preempt
indicates whether the previous task is preempted by the next
task. In this case, the previous task may be placed at the front of the
ready queue.
sourcefn task_tick(&mut self, current: &Self::SchedItem) -> bool
fn task_tick(&mut self, current: &Self::SchedItem) -> bool
Advances the scheduler state at each timer tick. Returns true
if
re-scheduling is required.
current
is the current running task.
sourcefn set_priority(&mut self, task: &Self::SchedItem, prio: isize) -> bool
fn set_priority(&mut self, task: &Self::SchedItem, prio: isize) -> bool
set priority for a task