![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
Runtime scheduler and execution bridge between graph delivery, node execution, and FD events. More...
#include <dfx-runtime/Scheduler.hpp>
Public Member Functions | |
| Scheduler (Utils::SystemConfig &sysConfig) | |
Construct a scheduler and register runtime settings into sysConfig. | |
| DISABLE_COPY_AND_MOVE (Scheduler) | |
| Scheduler is neither copyable nor movable. | |
| ~Scheduler () override | |
| Destroy the scheduler and stop it if running. | |
| template<DerivedFromTask T, typename ... Args> | |
| void | emplaceTask (Args &&... args) |
| Convenience helper to construct and submit a task directly to the worker pool. | |
| void | pushTask (TaskPtr task) |
| Submit an already-constructed task to the worker pool. | |
| void | start () |
| Start all known nodes. | |
| void | stop () |
| Stop all known nodes. | |
| bool | isRunning () const noexcept |
| Whether the runtime is currently started. | |
| HookResult | preDelivery (Core::NodePtr src, Core::OutputPort const &out, Core::NodePtr dst, Core::InputPort &in, Core::MessagePtr &message) override |
| Delivery hook executed before a message is enqueued into a channel. | |
| HookResult | postDelivery (Core::NodePtr src, Core::OutputPort const &out, Core::NodePtr dst, Core::InputPort &in) override |
| Delivery hook executed after a message has been enqueued into a channel. | |
| void | registerNodeFd (FdWatch::BorrowedFd fd, FdWatch::EventInterests events, FdWatch::FdCallback cb, Core::NodeWPtr node) override |
| Register an FD watch on behalf of a node. | |
| void | deregisterNodeFd (FdWatch::BorrowedFd fd) noexcept override |
| Deregister a previously registered FD. | |
| void | deferNodeCall (FdWatch::Callback cb, Core::NodeWPtr node) override |
| Defer a callback to execute under the node lock on a worker thread. | |
| void | onNodeCreated (Core::NodePtr node) override |
| Graph hook invoked when a node is created. | |
| void | onNodeRemoved (Core::NodePtr node) override |
| Graph hook invoked when a node is removed. | |
| void | onChannelCreated (Core::ChannelPtr channel) override |
| Graph hook invoked when a channel is created. | |
| void | onChannelRemoved (Core::ChannelPtr channel) override |
| Graph hook invoked when a channel is removed. | |
Additional Inherited Members | |
| Public Types inherited from dfx::Hooks::Delivery | |
| enum class | HookResult { Proceed , Skip , Fail } |
| Result code controlling pushMessage() behavior. More... | |
Runtime scheduler and execution bridge between graph delivery, node execution, and FD events.
Scheduler is the central runtime component that:
In practice, this is the "runtime spine" of dfx: channels deliver messages, the scheduler decides how the next node gets executed, and external events (FD readiness) are funneled back into node work items.
Any work that must touch a node is scheduled as a node-bound task (NodeTask), which:
This is used to reduce latency and queue overhead when safe.
The inline fast-path is only taken when all of the following hold:
If the inline fast-path is taken, the hook returns Hooks::Delivery::HookResult::Skip to prevent the channel from enqueuing the message.
The current nesting depth is tracked per worker thread via ThreadData::nestedLevel (retrieved via ThreadPool::threadData()). Once the configured limit is reached, the scheduler forces delivery to be deferred through the normal queue + task mechanism.
| dfx::Runtime::Scheduler::Scheduler | ( | Utils::SystemConfig & | sysConfig | ) |
Construct a scheduler and register runtime settings into sysConfig.
The scheduler creates:
|
override |
Destroy the scheduler and stop it if running.
Calls stop() to ensure nodes are stopped before destruction.
|
overridevirtual |
Defer a callback to execute under the node lock on a worker thread.
Wraps cb into a node-bound task and submits it to the ThreadPool. Deferring a null callback is considered a bug and an exception will be throw.
Implements dfx::Runtime::Api::NodeReactor.
|
overridevirtualnoexcept |
Deregister a previously registered FD.
Removes the FD from the FdListener and erases internal tracking. Invalid FDs are ignored.
Implements dfx::Runtime::Api::NodeReactor.
| dfx::Runtime::Scheduler::DISABLE_COPY_AND_MOVE | ( | Scheduler | ) |
Scheduler is neither copyable nor movable.
|
inline |
|
inlinenoexcept |
Whether the runtime is currently started.
|
overridevirtual |
Graph hook invoked when a channel is created.
Sets this scheduler as the channel delivery hook (channel->setDeliveryHook(this)), enabling inline delivery decisions and deferred execution scheduling.
Implements dfx::Hooks::Graph.
|
overridevirtual |
Graph hook invoked when a channel is removed.
Clears the delivery hook and warns if messages were still pending in the channel, as those messages will be dropped as a result of channel removal.
Implements dfx::Hooks::Graph.
|
overridevirtual |
Graph hook invoked when a node is created.
Implements dfx::Hooks::Graph.
|
overridevirtual |
Graph hook invoked when a node is removed.
Implements dfx::Hooks::Graph.
|
overridevirtual |
Delivery hook executed after a message has been enqueued into a channel.
If the destination node is running, schedules a node-bound task that drains the input port via in.processAllPendingMessages().
If the destination node is not running, no task is scheduled: messages remain queued in the channel until the node is started.
Implements dfx::Hooks::Delivery.
|
overridevirtual |
Delivery hook executed before a message is enqueued into a channel.
Decides whether to:
This method is also where mime-type mismatch warnings are emitted.
Implements dfx::Hooks::Delivery.
|
inline |
Submit an already-constructed task to the worker pool.
|
overridevirtual |
Register an FD watch on behalf of a node.
When the FD triggers, the scheduler will schedule a node-bound task that runs the callback under the node lock. Invalid FDs are ignored. Registering a null callback is considered a bug and an exception will be throw.
Implements dfx::Runtime::Api::NodeReactor.
| void dfx::Runtime::Scheduler::start | ( | ) |
Start all known nodes.
For each registered node, a task is scheduled to call node->start() under the node lock. The call blocks until all start tasks have completed.
| void dfx::Runtime::Scheduler::stop | ( | ) |
Stop all known nodes.
For each registered node, a task is scheduled to call node->stop() under the node lock. The call blocks until all stop tasks have completed.