dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Runtime::NodeTask< Func > Class Template Reference

Task wrapper that executes a callable under a node lock and only if the node is still alive. More...

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

Inheritance diagram for dfx::Runtime::NodeTask< Func >:
[legend]
Collaboration diagram for dfx::Runtime::NodeTask< Func >:
[legend]

Public Member Functions

 NodeTask (Func func, Core::NodeWPtr node, int priority=0)
 Construct a node-bound task.
void run () override
 Execute the callable if the node is still alive, under the node lock.
Public Member Functions inherited from dfx::Runtime::Task
 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.
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

template<typename Func>
requires std::invocable<Func, Core::NodePtr>
class dfx::Runtime::NodeTask< Func >

Task wrapper that executes a callable under a node lock and only if the node is still alive.

Template Parameters
FuncCallable type stored by value. Must be invocable as Func(Core::NodePtr) and the return value is ignored.

NodeTask is a concrete Task implementation used to execute work in a node-aware way.

It exists to support the runtime scheduling model where:

  • external event sources (FD readiness, timers, control messages, …) are detected elsewhere,
  • work is dispatched onto a ThreadPool,
  • the work must ultimately run against a specific node without concurrent re-entry.

Compared to a generic task (e.g. ASyncTask), NodeTask adds two guarantees:

  • Node lifetime check: it stores the node as a Core::NodeWPtr and locks it at execution time. If the node has been destroyed (or is otherwise unreachable), the task becomes a no-op.
  • Node serialization: it takes the node lock (std::lock_guard lock(*node);) before invoking the callable, ensuring that at most one worker thread executes inside that node at any given time.

This makes NodeTask the natural "dispatch unit" used by runtime components such as the dfx::Runtime::Scheduler / dfx::Runtime::Api::NodeReactor integration: they can enqueue node-bound work safely, even with many worker threads.

Constructor & Destructor Documentation

◆ NodeTask()

template<typename Func>
dfx::Runtime::NodeTask< Func >::NodeTask ( Func func,
Core::NodeWPtr node,
int priority = 0 )
inline

Construct a node-bound task.

The node is stored as a weak pointer and is validated at execution time.

Parameters
funcCallable executed when the task runs (under the node lock).
nodeWeak reference to the target node.
priorityScheduling priority for this task (see Task::priority()).

Member Function Documentation

◆ run()

template<typename Func>
void dfx::Runtime::NodeTask< Func >::run ( )
inlineoverridevirtual

Execute the callable if the node is still alive, under the node lock.

  • Locks the weak pointer.
  • If the node no longer exists, returns immediately.
  • Otherwise locks the node (serialization) and invokes the callable with the strong node pointer.

Note that since the node lock is a recursive one, it is perfectly safe and valid for the same thread to re-enter the node through an inline call.

Implements dfx::Runtime::Task.


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