Struct scheduler::RRScheduler

source ·
pub struct RRScheduler<T, const MAX_TIME_SLICE: usize> { /* private fields */ }
Expand description

A simple Round-Robin (RR) preemptive scheduler.

It’s very similar to the FifoScheduler, but every task has a time slice counter that is decremented each time a timer tick occurs. When the current task’s time slice counter reaches zero, the task is preempted and needs to be rescheduled.

Unlike FifoScheduler, it uses VecDeque as the ready queue. So it may take O(n) time to remove a task from the ready queue.

Implementations§

source§

impl<T, const S: usize> RRScheduler<T, S>

source

pub const fn new() -> Self

Creates a new empty RRScheduler.

source

pub fn scheduler_name() -> &'static str

get the name of scheduler

Trait Implementations§

source§

impl<T, const S: usize> BaseScheduler for RRScheduler<T, S>

§

type SchedItem = Arc<RRTask<T, S>>

Type of scheduled entities. Often a task struct.
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. Read more
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. Read more
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. Read more
source§

fn set_priority(&mut self, _task: &Self::SchedItem, _prio: isize) -> bool

set priority for a task

Auto Trait Implementations§

§

impl<T, const MAX_TIME_SLICE: usize> RefUnwindSafe for RRScheduler<T, MAX_TIME_SLICE>
where T: RefUnwindSafe,

§

impl<T, const MAX_TIME_SLICE: usize> Send for RRScheduler<T, MAX_TIME_SLICE>
where T: Sync + Send,

§

impl<T, const MAX_TIME_SLICE: usize> Sync for RRScheduler<T, MAX_TIME_SLICE>
where T: Sync + Send,

§

impl<T, const MAX_TIME_SLICE: usize> Unpin for RRScheduler<T, MAX_TIME_SLICE>

§

impl<T, const MAX_TIME_SLICE: usize> UnwindSafe for RRScheduler<T, MAX_TIME_SLICE>
where T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.