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§

source

type SchedItem

Type of scheduled entities. Often a task struct.

Required Methods§

source

fn init(&mut self)

Initializes the scheduler.

source

fn add_task(&mut self, task: Self::SchedItem)

Adds a task to the scheduler.

source

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.

source

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.

source

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.

source

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.

source

fn set_priority(&mut self, task: &Self::SchedItem, prio: isize) -> bool

set priority for a task

Implementors§