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
impl Scheduler
pub const fn is_idle(thread: usize) -> bool
sourcepub fn ready(&mut self, thread: usize)
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.
sourcepub fn is_active(&self, thread: usize) -> Option<usize>
pub fn is_active(&self, thread: usize) -> Option<usize>
Returns the CPU where the thread is currently running.
sourcepub fn thread(&self, thread: usize) -> Option<&Thread>
pub fn thread(&self, thread: usize) -> Option<&Thread>
Returns a reference to the thread with the given id.
sourcepub fn thread_mut(&mut self, thread: usize) -> Option<&mut Thread>
pub fn thread_mut(&mut self, thread: usize) -> Option<&mut Thread>
Returns a reference to the thread with the given id.
sourcepub fn resume(&mut self, ready: bool)
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.
sourcepub fn exit(&mut self) -> !
pub fn exit(&mut self) -> !
Terminates the currently running thread, directly continue with the next one.
sourcepub fn kill(&mut self, thread: usize) -> bool
pub fn kill(&mut self, thread: usize) -> bool
Terminates t
, which might be running on another CPU.
sourcefn dispatch(&mut self, next: usize)
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.
sourcepub extern "C" fn idle_action() -> !
pub extern "C" fn idle_action() -> !
Action of the idle thread.