StuBS
Loading...
Searching...
No Matches
Scheduler Class Reference

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

#include <scheduler.h>

Collaboration diagram for Scheduler:

Public Member Functions

void schedule ()
 Start scheduling.
 
void ready (Thread *that)
 Include a thread in scheduling decisions.
 
void exit ()
 (Self-)termination of the calling thread.
 
void kill (Thread *that)
 Kills the passed thread.
 
void resume (bool ready=true)
 Issue a thread change.
 
Threadactive ()
 return the active thread from the dispatcher
 
bool isActive (const Thread *thread, unsigned int *cpu=nullptr)
 Check if thread is currently active.
 
bool isEmpty () const
 Checks whether the ready queue is empty.
 
void setIdle (IdleThread *that)
 Set the idle thread for the executing CPU.
 
bool isIdle (int cpu)
 Check wether the specified CPU core is idle.
 

Private Member Functions

ThreadgetNext ()
 Helper to retrieve next Thread.
 

Private Attributes

Dispatcher dispatcher
 a Dispatcher object, providing the low level context switching routines.
 
Queue< Threadreadylist
 List of threads, ready to be run.
 
IdleThreadidleThread [Core::MAX]
 Idle thread.
 

Detailed Description

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

The scheduler manages the ready queue (a private Queue object), 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.

Member Function Documentation

◆ exit()

void Scheduler::exit ( )

(Self-)termination of the calling thread.

This method can be used by a thread to exit itself. The calling thread will not be appended to the ready queue; a reschedule will be issued.

◆ getNext()

Thread * Scheduler::getNext ( )
private

Helper to retrieve next Thread.

Returns
pointer of next thread

◆ isActive()

bool Scheduler::isActive ( const Thread * thread,
unsigned int * cpu = nullptr )

Check if thread is currently active.

Parameters
threadPointer to the thread in question
getCpuIdIf not null, the core that the thread is running on, if applicable
Returns
true if currently running, false otherwise

◆ isIdle()

bool Scheduler::isIdle ( int cpu)

Check wether the specified CPU core is idle.

Parameters
cpuCPU core to check

◆ kill()

void Scheduler::kill ( Thread * that)

Kills the passed thread.

This method is used to kill the Thread that. For OOStuBS, it is sufficient to remove that from the ready queue and, thereby, exclude the thread from scheduling. For MPStuBS, a simple removal is not sufficient, as the thread might currently be running on another CPU core. In this case, the thread needs to be marked as dying (a flag checked by resume prior to enqueuing into the ready queue)

and the executing CPU core needs to be notified.

Note: The thread should be able to kill itself.

◆ ready()

void Scheduler::ready ( Thread * that)

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.

Parameters
thatThread to be scheduled

◆ resume()

void Scheduler::resume ( bool ready = true)

Issue a thread change.

This method issues the change of the currently active thread without requiring the calling thread to be aware of the other threads. Scheduling decisions, i.e. which thread will be run next, are made by the scheduler itself with the knowledge of the currently ready threads. The currently active thread is appended to the end of the queue; the first thread in the queue will be activated (to implement the FIFO policy).

Parameters
readyIf false, the currently active thread will not be enqueued for scheduling again.

◆ schedule()

void Scheduler::schedule ( )

Start scheduling.

This method starts the scheduling by removing the first thread from the ready queue and activating it. MPStuBS needs to call this method once for every CPU core to dispatch the first thread.

◆ setIdle()

void Scheduler::setIdle ( IdleThread * that)

Set the idle thread for the executing CPU.

Parameters
[in]thatthe idle thread to use for the executing CPU

The documentation for this class was generated from the following files: