rstubs::threading::scheduler

Struct Scheduler

source
pub struct Scheduler {
    ready: ArrayDeque<usize, APPS>,
    threads: [Option<Thread>; 11],
    next_id: AtomicUsize,
    local: UnsafeCell<[Local; 1]>,
}
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: UnsafeCell<[Local; 1]>

Per-CPU data

Implementations§

source§

impl Scheduler

source

pub const fn new() -> Self

Construct the scheduler.

source

fn local(&self) -> &mut Local

Access local data for the current CPU.

source

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

Add and ready a new thread to the scheduler.

source

pub const 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>

Returns the thread that currently runs on this CPU.

source

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

Returns the CPU where the thread is currently running.

source

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

Returns a reference to the thread with the given id.

source

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

Returns a reference to the thread with the given id.

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 on another CPU.

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 !Freeze for Scheduler

§

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

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
§

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

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

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.

source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

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

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.