TaskRunner
Task interface.TaskRunner
#include <icy/task.h>class TaskRunnerDefined in src/base/include/icy/task.h:93
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
| Name | Kind | Owner |
|---|---|---|
Idle | variable | Declared here |
Shutdown | variable | Declared here |
TaskRunner | function | Declared here |
~TaskRunner | function | Declared here |
TaskRunner | function | Declared here |
operator= | function | Declared here |
TaskRunner | function | Declared here |
operator= | function | Declared here |
start | function | Declared here |
cancel | function | Declared here |
destroy | function | Declared here |
exists | function | Declared here |
get | function | Declared here |
setRunner | function | Declared here |
className | function | Declared here |
getDefault | function | Declared here |
_mutex | variable | Declared here |
_runner | variable | Declared here |
_tasks | variable | Declared here |
run | function | Declared here |
add | function | Declared here |
remove | function | Declared here |
next | function | Declared here |
clear | function | Declared here |
onAdd | function | Declared here |
onStart | function | Declared here |
onCancel | function | Declared here |
onRemove | function | Declared here |
onRun | function | Declared here |
Runnable | function | Inherited from Runnable |
~Runnable | function | Inherited from Runnable |
run | function | Inherited from Runnable |
cancel | function | Inherited from Runnable |
cancelled | function | Inherited from Runnable |
exit | variable | Inherited from Runnable |
Inherited from Runnable
| Kind | Name | Description |
|---|---|---|
function | Runnable inline | |
function | ~Runnable virtual | Defaulted destructor. |
function | run virtual | The run method will be called by the asynchronous context. |
function | cancel virtual inline | Cancel the current task. The run() method should return ASAP. |
function | cancelled virtual const inline | Returns true when the task has been cancelled. |
variable | exit |
Public Attributes
| Return | Name | Description |
|---|---|---|
NullSignal | Idle | Fires after completing an iteration of all tasks. |
NullSignal | Shutdown | Signals when the [TaskRunner](#taskrunner-1) is shutting down. |
Idle
NullSignal IdleDefined in src/base/include/icy/task.h:138
Fires after completing an iteration of all tasks.
Shutdown
NullSignal ShutdownDefined in src/base/include/icy/task.h:141
Signals when the [TaskRunner](#taskrunner-1) is shutting down.
Public Methods
| Return | Name | Description |
|---|---|---|
TaskRunner | ||
TaskRunner | Deleted constructor. | |
TaskRunner | Deleted constructor. | |
bool | start virtual | Starts a task, adding it if it doesn't exist. |
bool | cancel virtual | Cancels a task. |
bool | destroy virtual | Queues a task for destruction. |
bool | exists virtual const | Returns whether a task exists. |
Task * | get virtual const | Returns the task pointer matching the given ID, or nullptr if no task exists. |
void | setRunner virtual | 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. |
const char * | className virtual const inline |
TaskRunner
TaskRunner(std::shared_ptr< Runner > runner = nullptr)Defined in src/base/include/icy/task.h:97
Parameters
runnerAsync runner to drive task execution; defaults to a new[Thread](icy-Thread.html#thread-1).
TaskRunner
TaskRunner(const TaskRunner &) = deleteDefined in src/base/include/icy/task.h:100
Deleted constructor.
TaskRunner
TaskRunner(TaskRunner &&) = deleteDefined 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) constDefined in src/base/include/icy/task.h:120
Returns whether a task exists.
get
virtual const
virtual Task * get(uint32_t id) constDefined 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() constDefined in src/base/include/icy/task.h:143
Public Static Methods
| Return | Name | Description |
|---|---|---|
TaskRunner & | getDefault static | 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. |
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
_mutex
std::mutex _mutexDefined in src/base/include/icy/task.h:179
_runner
std::shared_ptr< Runner > _runnerDefined in src/base/include/icy/task.h:180
_tasks
TaskList _tasksDefined in src/base/include/icy/task.h:181
Protected Methods
| Return | Name | Description |
|---|---|---|
void | run virtual override | Called by the async context to run the next task. |
bool | add virtual | Adds a task to the runner. |
bool | remove virtual | Removes a task from the runner. |
Task * | next virtual const | Returns the next task to be run. |
void | clear virtual | Destroys and clears all manages tasks. |
void | onAdd virtual | Called after a task is added. |
void | onStart virtual | Called after a task is started. |
void | onCancel virtual | Called after a task is cancelled. |
void | onRemove virtual | Called after a task is removed. |
void | onRun virtual | Called after a task has run. |
run
virtual override
virtual void run() overrideDefined 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() constDefined 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.
