Base module

TaskRunner

[Runner]({#ref classicy_1_1Runner #}) for tasks that inherit the [Task]({#ref classicy_1_1Task #}) interface.

TaskRunner

#include <icy/task.h>

Inherits: Runnable Subclassed by: Scheduler

Runner for tasks that inherit the [Task](icy-Task.html#task) interface.

The [TaskRunner](#taskrunner) continually loops through each task in the task list calling the task's [run()](#run-6) method.

The [TaskRunner](#taskrunner) is powered by an abstract [Runner](icy-Runner.html#runner) instance, which means that tasks can be executed in a thread or event loop context.

Public Attributes

ReturnNameDescription
NullSignalIdleFires after completing an iteration of all tasks.
NullSignalShutdownSignals when the [TaskRunner](#taskrunner) is shutting down.

Idle

NullSignal Idle

Fires after completing an iteration of all tasks.


Shutdown

NullSignal Shutdown

Signals when the [TaskRunner](#taskrunner) is shutting down.

Public Methods

ReturnNameDescription
TaskRunner#### Parameters
TaskRunnerDeleted constructor.
TaskRunnerDeleted constructor.
boolstart virtualStarts a task, adding it if it doesn't exist.
boolcancel virtualCancels a task.
booldestroy virtualQueues a task for destruction.
boolexists virtual constReturns whether a task exists.
Task *get virtual constReturns the task pointer matching the given ID, or nullptr if no task exists.
voidsetRunner virtualSet the asynchronous context for packet processing. This may be a Thread or another derivative of Async. Must be set before the stream is activated.
const char *className virtual const inline

TaskRunner

TaskRunner(std::shared_ptr< Runner > runner)

Parameters

  • runner Async runner to drive task execution; defaults to a new [Thread](icy-Thread.html#thread).

TaskRunner

TaskRunner(const TaskRunner &) = delete

Deleted constructor.


TaskRunner

TaskRunner(TaskRunner &&) = delete

Deleted constructor.


start

virtual

virtual bool start(Task * task)

Starts a task, adding it if it doesn't exist.


cancel

virtual

virtual bool cancel(Task * task)

Cancels a task.

The task reference will be managed by the TaskRunner until the task is destroyed.


destroy

virtual

virtual bool destroy(Task * task)

Queues a task for destruction.


exists

virtual const

virtual bool exists(Task * task) const

Returns whether a task exists.


get

virtual const

virtual Task * get(uint32_t id) const

Returns the task pointer matching the given ID, or nullptr if no task exists.


setRunner

virtual

virtual void setRunner(std::shared_ptr< Runner > runner)

Set the asynchronous context for packet processing. This may be a Thread or another derivative of Async. Must be set before the stream is activated.


className

virtual const inline

virtual inline const char * className() const

Public Static Methods

ReturnNameDescription
TaskRunner &getDefault staticReturns the default [TaskRunner](#taskrunner) singleton, although TaskRunner instances may be initialized individually. The default runner should be kept for short running tasks such as timers in order to maintain performance.

getDefault

static

static TaskRunner & getDefault()

Returns the default [TaskRunner](#taskrunner) singleton, although TaskRunner instances may be initialized individually. The default runner should be kept for short running tasks such as timers in order to maintain performance.

Protected Attributes

ReturnNameDescription
std::mutex_mutex
std::shared_ptr< Runner >_runner
TaskList_tasks

_mutex

std::mutex _mutex

_runner

std::shared_ptr< Runner > _runner

_tasks

TaskList _tasks

Protected Methods

ReturnNameDescription
voidrun virtualCalled by the async context to run the next task.
booladd virtualAdds a task to the runner.
boolremove virtualRemoves a task from the runner.
Task *next virtual constReturns the next task to be run.
voidclear virtualDestroys and clears all manages tasks.
voidonAdd virtualCalled after a task is added.
voidonStart virtualCalled after a task is started.
voidonCancel virtualCalled after a task is cancelled.
voidonRemove virtualCalled after a task is removed.
voidonRun virtualCalled after a task has run.

run

virtual

virtual void run()

Called by the async context to run the next task.


add

virtual

virtual bool add(Task * task)

Adds a task to the runner.


remove

virtual

virtual bool remove(Task * task)

Removes a task from the runner.


next

virtual const

virtual Task * next() const

Returns the next task to be run.


clear

virtual

virtual void clear()

Destroys and clears all manages tasks.


onAdd

virtual

virtual void onAdd(Task * task)

Called after a task is added.


onStart

virtual

virtual void onStart(Task * task)

Called after a task is started.


onCancel

virtual

virtual void onCancel(Task * task)

Called after a task is cancelled.


onRemove

virtual

virtual void onRemove(Task * task)

Called after a task is removed.


onRun

virtual

virtual void onRun(Task * task)

Called after a task has run.