StuBS
|
The dispatcher dispatches threads and puts the scheduler's decisions into action. More...
#include <dispatcher.h>
Public Member Functions | |
Dispatcher () | |
constructor | |
Thread * | active () |
Returns the thread currently running on the CPU core calling this method. | |
bool | isActive (const Thread *thread, unsigned *cpu=nullptr) |
Check if thread is currently active. | |
void | go (Thread *first) |
This method stores first as life pointer for this CPU core and triggers the execution of first. Only to be used for the first thread running on a CPU. | |
void | dispatch (Thread *next) |
Updates the life pointer to next and issues a thread change from the old to the new life pointer. | |
Private Member Functions | |
void | setActive (Thread *thread) |
set the currently active thread | |
The dispatcher dispatches threads and puts the scheduler's decisions into action.
The dispatcher manages the life pointer that refers to the currently active thread and performs the actual switching of processes. For single-core systems, a single life pointer is sufficient, as only a single thread can be active at any one time. On multi-core systems, every CPU core needs its own life pointer.
Dispatcher::Dispatcher | ( | ) |
constructor
Initialize life pointer with nullptr to indicate that nothing is (yet) being executed on the respective CPU.
|
inline |
Returns the thread currently running on the CPU core calling this method.
void Dispatcher::dispatch | ( | Thread * | next | ) |
Updates the life pointer to next and issues a thread change from the old to the new life pointer.
next | Next thread to be executed. |
void Dispatcher::go | ( | Thread * | first | ) |
This method stores first as life pointer for this CPU core and triggers the execution of first. Only to be used for the first thread running on a CPU.
first | First thread to be executed on this CPU core. |
|
inline |
Check if thread is currently active.
thread | Pointer to the thread in question |
cpu | will receive the core number if cpu pointer is not nullptr and the thread is currently active |
true
if currently running, false otherwise
|
inlineprivate |
set the currently active thread
thread | active Thread |