dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Runtime::Task Class Referenceabstract

Polymorphic unit of work executed by the runtime (typically by ThreadPool). More...

#include <dfx-runtime/tasks/Task.hpp>

Inheritance diagram for dfx::Runtime::Task:
[legend]

Public Member Functions

 Task (int priority=0)
 Construct a task with a given scheduling priority.
 DISABLE_COPY_AND_MOVE (Task)
 Tasks are neither copyable nor movable.
virtual ~Task ()=default
 Polymorphic base requires a virtual destructor.
int priority () const noexcept
 Task scheduling priority.
virtual void run ()=0
 Execute the task.
template<DerivedFromTask T>
T & as ()
 Unchecked downcast to a concrete task type.
template<DerivedFromTask T>
T const & as () const
 Unchecked downcast to a concrete task type (const overload).

Detailed Description

Polymorphic unit of work executed by the runtime (typically by ThreadPool).

A Task represents a single executable work item that can be scheduled and executed asynchronously by runtime components such as ThreadPool (and, transitively, the Scheduler).

Tasks carry a priority used for scheduling decisions:

  • Higher value == higher priority.
  • The ThreadPool is expected to run higher-priority tasks sooner.
  • Tasks of equal priority are typically executed in FIFO order.

Tasks are:

  • move- and copy-disabled, to keep ownership explicit and stable once enqueued.
  • **owned via TaskPtr** (a std::unique_ptr<Task>), reinforcing single ownership.
Warning
Task run() method are invoke through the dfx::Utils::safeInvoke() function meaning that any exception will be logged and discarded. i.e. exceptions will not stop the worker thread or affect it in any way.

Constructor & Destructor Documentation

◆ Task()

dfx::Runtime::Task::Task ( int priority = 0)
inline

Construct a task with a given scheduling priority.

Higher value means higher priority (executed sooner).

Parameters
priorityScheduling priority for this task.

◆ ~Task()

virtual dfx::Runtime::Task::~Task ( )
virtualdefault

Polymorphic base requires a virtual destructor.

Member Function Documentation

◆ as() [1/2]

template<DerivedFromTask T>
T & dfx::Runtime::Task::as ( )
inline

Unchecked downcast to a concrete task type.

Template Parameters
TConcrete task type (must derive from Task).
Returns
Reference to *this as T.
Warning
This is an unchecked static_cast. Calling it with an incorrect type results in undefined behavior.

◆ as() [2/2]

template<DerivedFromTask T>
T const & dfx::Runtime::Task::as ( ) const
inline

Unchecked downcast to a concrete task type (const overload).

Template Parameters
TConcrete task type (must derive from Task).
Returns
Const reference to *this as T.
Warning
This is an unchecked static_cast. Calling it with an incorrect type results in undefined behavior.

◆ DISABLE_COPY_AND_MOVE()

dfx::Runtime::Task::DISABLE_COPY_AND_MOVE ( Task )

Tasks are neither copyable nor movable.

◆ priority()

int dfx::Runtime::Task::priority ( ) const
inlinenoexcept

Task scheduling priority.

Returns
Priority value where a higher value means higher priority.

◆ run()

virtual void dfx::Runtime::Task::run ( )
pure virtual

Execute the task.

Called by the runtime when the task is selected for execution. Implementations should keep execution time reasonable and avoid blocking indefinitely to prevent starving other work.

Implemented in dfx::Runtime::ASyncTask< Func >, and dfx::Runtime::NodeTask< Func >.


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