Class Coroutine

Class Coroutine

Placement in the overall structure

Module
thread
Base classes
None
Derived classes
Entrant
Time of creation
Task 4
Files
coroutine.h coroutine.cc

Description

The Coroutine class represents the abstraction of a coroutine. It enables processor release to another coroutine and provides memory (through the toc struct) to save the contents of the non-volatile registers until the next activation. In addition, it takes care of the initialization of these register values so that execution starts at the right place and with the right stack when they are first activated.

Public methods

Coroutine (void* tos);
In the coroutine constructor, the register values are initialized so that the stack pointer initially points to tos and on first activation execution begins with the kickoff function.
void go ();
This method is used for the first activation of the first coroutine in the system. Therefore no register values must be saved here.
void resume (Coroutine& next);
This method triggers a coroutine switch. The current contents of the non-volatile registers are saved in the toc element and replaced by the values of next (the toc element of the next coroutine).
virtual void action () = 0;
The method action represents the actual job of the coroutine. However, since not all coroutines in the system should do the same, action can only be defined in a specialized class (e.g. in Application).