pub struct Scheduler {
    ready: ArrayDeque<usize, APPS>,
    threads: [Option<Thread>; 11],
    next_id: AtomicUsize,
    local: PerCPU<Local>,
}
Expand description

The scheduler plans the threads’ execution order and, from this, selects the next thread to be running.

The scheduler manages the ready queue, that is the list of threads that are ready to execute. The scheduler arranges threads in a FIFO order, that is, when a thread is set ready, it will be appended to the end of the queue, while threads to be executed are taken from the front of the queue.

Fields§

§ready: ArrayDeque<usize, APPS>

Ready queue

§threads: [Option<Thread>; 11]

Contains all threads

Note: the idle threads have the id and index of their corresponding CPU

§next_id: AtomicUsize

Next thread id

§local: PerCPU<Local>

Per-CPU data

Implementations§

source§

impl Scheduler

source

pub const fn new() -> Self

Construct the scheduler.

source

pub fn add(&mut self, thread: Thread) -> usize

Add and ready a new thread to the scheduler.

source

fn is_idle(thread: usize) -> bool

source

pub fn ready(&mut self, thread: usize)

Include a thread in scheduling decisions.

This method will register a thread for scheduling. It will be appended to the ready queue and dispatched once its time has come.

Note: New threads have to be added first with Scheduler::add.

source

pub fn active(&self) -> Option<usize>

source

pub fn thread(&self, thread: usize) -> Option<&Thread>

source

pub fn thread_mut(&mut self, thread: usize) -> Option<&mut Thread>

source

pub fn schedule(&mut self) -> !

Start the scheduling. This function does not return.

source

pub fn resume(&mut self, ready: bool)

Initiates a thread switch. This function returns then in the context of the next thread.

If ready, the currently running thread is added back to the ready list.

source

pub fn exit(&mut self) -> !

Terminates the currently running thread, directly continue with the next one.

source

pub fn kill(&mut self, thread: usize) -> bool

Terminates t, which might be running or waiting.

source

fn dispatch(&mut self, next: usize)

Updates the life pointer to next and issues a thread change from the old to the new life pointer.

source

fn next(&mut self) -> usize

Helper to retrieve next Thread.

source

pub extern "C" fn idle_action()

Action of the idle thread.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scheduler

§

impl Send for Scheduler

§

impl Sync for Scheduler

§

impl Unpin for Scheduler

§

impl !UnwindSafe for Scheduler

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.