Home
Base module

TaskRunner

Runner for tasks that inherit the Task interface.

TaskRunner

#include <icy/task.h>
class TaskRunner

Defined in src/base/include/icy/task.h:93

Inherits: Runnable Subclassed by: Scheduler

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

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

The [TaskRunner](#taskrunner-1) 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.

List of all members

NameKindOwner
IdlevariableDeclared here
ShutdownvariableDeclared here
TaskRunnerfunctionDeclared here
~TaskRunnerfunctionDeclared here
TaskRunnerfunctionDeclared here
operator=functionDeclared here
TaskRunnerfunctionDeclared here
operator=functionDeclared here
startfunctionDeclared here
cancelfunctionDeclared here
destroyfunctionDeclared here
existsfunctionDeclared here
getfunctionDeclared here
setRunnerfunctionDeclared here
classNamefunctionDeclared here
getDefaultfunctionDeclared here
_mutexvariableDeclared here
_runnervariableDeclared here
_tasksvariableDeclared here
runfunctionDeclared here
addfunctionDeclared here
removefunctionDeclared here
nextfunctionDeclared here
clearfunctionDeclared here
onAddfunctionDeclared here
onStartfunctionDeclared here
onCancelfunctionDeclared here
onRemovefunctionDeclared here
onRunfunctionDeclared here
RunnablefunctionInherited from Runnable
~RunnablefunctionInherited from Runnable
runfunctionInherited from Runnable
cancelfunctionInherited from Runnable
cancelledfunctionInherited from Runnable
exitvariableInherited from Runnable

Inherited from Runnable

KindNameDescription
functionRunnable inline
function~Runnable virtualDefaulted destructor.
functionrun virtualThe run method will be called by the asynchronous context.
functioncancel virtual inlineCancel the current task. The run() method should return ASAP.
functioncancelled virtual const inlineReturns true when the task has been cancelled.
variableexit

Public Attributes

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

Idle

NullSignal Idle

Defined in src/base/include/icy/task.h:138

Fires after completing an iteration of all tasks.


Shutdown

NullSignal Shutdown

Defined in src/base/include/icy/task.h:141

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

Public Methods

ReturnNameDescription
TaskRunner
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 = nullptr)

Defined in src/base/include/icy/task.h:97

Parameters

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

TaskRunner

TaskRunner(const TaskRunner &) = delete

Defined in src/base/include/icy/task.h:100

Deleted constructor.


TaskRunner

TaskRunner(TaskRunner &&) = delete

Defined in src/base/include/icy/task.h:102

Deleted constructor.


start

virtual

virtual bool start(Task * task)

Defined in src/base/include/icy/task.h:106

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


cancel

virtual

virtual bool cancel(Task * task)

Defined in src/base/include/icy/task.h:114

Cancels a task.

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


destroy

virtual

virtual bool destroy(Task * task)

Defined in src/base/include/icy/task.h:117

Queues a task for destruction.


exists

virtual const

virtual bool exists(Task * task) const

Defined in src/base/include/icy/task.h:120

Returns whether a task exists.


get

virtual const

virtual Task * get(uint32_t id) const

Defined in src/base/include/icy/task.h:124

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


setRunner

virtual

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

Defined in src/base/include/icy/task.h:129

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

Defined in src/base/include/icy/task.h:143

Public Static Methods

ReturnNameDescription
TaskRunner &getDefault staticReturns the default [TaskRunner](#taskrunner-1) 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()

Defined in src/base/include/icy/task.h:135

Returns the default [TaskRunner](#taskrunner-1) 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

Defined in src/base/include/icy/task.h:179


_runner

std::shared_ptr< Runner > _runner

Defined in src/base/include/icy/task.h:180


_tasks

TaskList _tasks

Defined in src/base/include/icy/task.h:181

Protected Methods

ReturnNameDescription
voidrun virtual overrideCalled 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 override

virtual void run() override

Defined in src/base/include/icy/task.h:147

Called by the async context to run the next task.

Reimplements

add

virtual

virtual bool add(Task * task)

Defined in src/base/include/icy/task.h:150

Adds a task to the runner.


remove

virtual

virtual bool remove(Task * task)

Defined in src/base/include/icy/task.h:153

Removes a task from the runner.


next

virtual const

virtual Task * next() const

Defined in src/base/include/icy/task.h:156

Returns the next task to be run.


clear

virtual

virtual void clear()

Defined in src/base/include/icy/task.h:159

Destroys and clears all manages tasks.

Reimplemented by

onAdd

virtual

virtual void onAdd(Task * task)

Defined in src/base/include/icy/task.h:162

Called after a task is added.


onStart

virtual

virtual void onStart(Task * task)

Defined in src/base/include/icy/task.h:165

Called after a task is started.


onCancel

virtual

virtual void onCancel(Task * task)

Defined in src/base/include/icy/task.h:168

Called after a task is cancelled.


onRemove

virtual

virtual void onRemove(Task * task)

Defined in src/base/include/icy/task.h:171

Called after a task is removed.


onRun

virtual

virtual void onRun(Task * task)

Defined in src/base/include/icy/task.h:174

Called after a task has run.