The Thread is an object used by the scheduler.
More...
#include <thread.h>
|
volatile bool | kill_flag |
| Marker for a dying thread.
|
|
|
Context | context |
| Context of the thread, used for saving and restoring the register values when context switching.
|
|
The Thread is an object used by the scheduler.
◆ Thread()
Thread::Thread |
( |
void * |
tos | ) |
|
|
explicit |
Constructor Initializes the context using prepareContext with the given stack space.
- Parameters
-
tos | the top of stack, highest address of some memory block that should be used as stack (remember stacks grow to the lower addresses on x86). |
◆ action()
virtual void Thread::action |
( |
| ) |
|
|
pure virtual |
Method that contains the thread's program code.
Derived classes are meant to override this method to provide meaningful code to be run in this thread.
Implemented in KeyboardApplication, Application, and IdleThread.
◆ getWaitingroom()
Returns the Waitingroom in which the thread is currently waiting.
Returns 0 in case the thread does not waiting in any Waitingroom, that is, the thread is either running, in the ready list, already terminated or not yet registered at the scheduler.
- Returns
- Pointer to a Waitingroom in which the thread is waiting, or
nullptr
.
◆ go()
Activates the first thread on this CPU.
Calling the method starts the first thread on the calling CPU. From then on, Thread::resume() must be used all subsequent context switches.
◆ kickoff()
void Thread::kickoff |
( |
Thread * |
object | ) |
|
|
staticprotected |
Function to start a thread.
For the first activation of a thread, we need a "return address" pointing to a function that will take care of calling C++ virtual methods. For this purpose, we use this kickoff()
function.
Activating kickoff
The context initialization via prepareContext() not only initializes the Stack for the first thread change, but also pushes the address of kickoff()
as return address to the stack. Consequently, the first execution of context_switch() will start execution by returning to the beginning of kickoff()
.
This kickoff()
function simply calls the action() method on the thread passed as parameter and, thus, resolves the virtual C++ method.
- Note
- As this function is never actually called, but only executed by returning from the co-routine's initial stack, it may never return. Otherwise garbage values from the stack will be interpreted as return address and the system might crash.
- Parameters
-
◆ resume()
void Thread::resume |
( |
Thread * |
next | ) |
|
Switches from the currently running thread to the next
one.
The values currently present in the callee-saved registers will be stored in this threads context-structure, the corresponding values belonging to next
thread will be loaded.
- Parameters
-
next | Pointer to the next thread. |
◆ setWaitingroom()
Marks the thread as waiting for an event in Waitingroom w
.
- Parameters
-
The documentation for this class was generated from the following files: