Frobby
0.9.5
|
TaskEngine handles a list of tasks that are to be carried out. More...
#include <TaskEngine.h>
Public Member Functions | |
TaskEngine () | |
~TaskEngine () | |
void | addTask (Task *task) |
Add a task at the head of the list of pending tasks. More... | |
bool | runNextTask () |
Run the most recently added task that has not been run yet. More... | |
void | runTasks () |
Runs all pending tasks. More... | |
size_t | getTotalTasksEver () |
Returns the number of times addTask has been successfully called. More... | |
Private Member Functions | |
void | dispose (Task *task) |
Private Attributes | |
size_t | _totalTasksEver |
This is used for statistics so that it is not a disaster if this overflows for very long-running computations. More... | |
vector< Task * > | _tasks |
TaskEngine handles a list of tasks that are to be carried out.
Pending tasks are run in last-in-first-out order. TaskEngine passes itself to tasks that are run so that tasks can schedule more tasks.
Using TaskEngine is an alternative to using recursion to schedule sub-computations. TaskEngine does what the stack would do in a recursive computation. An advantage of TaskEngine over recursion is that stack overflow does not occur. The maximum number of pending tasks is limited only by the size of the memory.
TaskEngine is also the first step towards an implementation where sub-computations can be run in parallel. At that time TaskEngine will need support for specifying dependencies among tasks.
Definition at line 40 of file TaskEngine.h.
TaskEngine::TaskEngine | ( | ) |
Definition at line 24 of file TaskEngine.cpp.
TaskEngine::~TaskEngine | ( | ) |
Definition at line 28 of file TaskEngine.cpp.
void TaskEngine::addTask | ( | Task * | task | ) |
Add a task at the head of the list of pending tasks.
TaskEngine guarantees to call either run() or dispose() on the task at some point. It is allowed to add the same task several times, though then run() or dispose() will be called as many times as the task has been added.
Definition at line 35 of file TaskEngine.cpp.
|
private |
Definition at line 70 of file TaskEngine.cpp.
size_t TaskEngine::getTotalTasksEver | ( | ) |
Returns the number of times addTask has been successfully called.
This value may overflow if it becomes too large to contain in a size_t.
Definition at line 66 of file TaskEngine.cpp.
bool TaskEngine::runNextTask | ( | ) |
Run the most recently added task that has not been run yet.
Returns true if a task has been run. Returns false if there are no pending tasks.
Definition at line 50 of file TaskEngine.cpp.
void TaskEngine::runTasks | ( | ) |
Runs all pending tasks.
If a task adds new tasks, those are run as well.
Definition at line 61 of file TaskEngine.cpp.
|
private |
Definition at line 80 of file TaskEngine.h.
|
private |
This is used for statistics so that it is not a disaster if this overflows for very long-running computations.
Definition at line 78 of file TaskEngine.h.