Frobby 0.10.0
Loading...
Searching...
No Matches
TaskEngine Class Reference

#include <TaskEngine.h>

Public Member Functions

void addTask (Task *task)
bool runNextTask ()
void runTasks ()
size_t getTotalTasksEver ()
void disposeAll ()

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.

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.

◆ disposeAll()

void TaskEngine::disposeAll ( )

Dispose of all pending tasks without running them.

◆ 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.

◆ 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.

◆ runTasks()

void TaskEngine::runTasks ( )

Runs all pending tasks.

If a task adds new tasks, those are run as well.


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