TaskEngine Class Reference

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.
bool | runNextTask ()
| Run the most recently added task that has not been run yet.
void | runTasks ()
| Runs all pending tasks.
size_t | getTotalTasksEver ()
| Returns the number of times addTask has been successfully called.

## 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.
vector< Task * > | _tasks

## Detailed Description

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.

## Constructor & Destructor Documentation

## TaskEngine()

TaskEngine::TaskEngine | ( |  | ) |

Definition at line 24 of file TaskEngine.cpp.

## ~TaskEngine()

TaskEngine::~TaskEngine | ( |  | ) |

Definition at line 28 of file TaskEngine.cpp.

## Member Function Documentation

## addTask()

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.

## dispose()

void TaskEngine::dispose | ( | Task * | task | ) |

private

Definition at line 70 of file TaskEngine.cpp.

## getTotalTasksEver()

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.

## runNextTask()

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.

## runTasks()

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.

## Member Data Documentation

## _tasks

vector<Task*> TaskEngine::_tasks

private

Definition at line 80 of file TaskEngine.h.

## _totalTasksEver

size_t TaskEngine::_totalTasksEver

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.

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

- src/TaskEngine.h
- src/TaskEngine.cpp