|
VLink
2.0.0
A high-performance communication middleware
|
DAG node carrying a callback, predecessor and successor links, and run-time state. 更多...
#include <graph_task.h>
Public 类型 | |
| enum | Status : uint8_t { kStatusInActive = 0 , kStatusPending = 1 , kStatusRunning = 2 , kStatusDone = 3 } |
Run-time execution state of a node within an execute pass. 更多... | |
| enum | Policy : uint8_t { kPolicyOnce = 0 , kPolicyMultiple = 1 , kPolicyWaitAll = 2 } |
| Policy controlling how many times the task may run within a pass. 更多... | |
| using | Callback = MoveFunction< void()> |
| Callback type for void-returning work nodes. 更多... | |
| using | ConditionCallback = MoveFunction< int()> |
| Callback type for condition nodes; the return value selects an outgoing branch. 更多... | |
| using | StatusCallback = MoveFunction< void(const std::string &, Status)> |
| Status-change notification callback. 更多... | |
Public 成员函数 | |
| template<class GraphEngineT > | |
| void | execute (GraphEngineT *graph_engine) |
Submits the reachable sub-graph to graph_engine. 更多... | |
| void | cancel () |
| Cancels this node and propagates the cancellation downstream. 更多... | |
| void | precede (const std::shared_ptr< GraphTask > &task) |
Declares that this node must complete before task starts. 更多... | |
| void | succeed (const std::shared_ptr< GraphTask > &task) |
Declares that task must complete before this node starts. 更多... | |
| uint32_t | register_status_callback (StatusCallback &&callback) |
| Subscribes a callback to status transitions on this node. 更多... | |
| bool | unregister_status_callback (uint32_t id) |
| Removes a previously registered status callback by id. 更多... | |
| void | clear_status_callbacks () |
| Removes every status callback subscription on this node. 更多... | |
| void | set_name (const std::string &name) |
| Sets the node name used in DOT output and status callbacks. 更多... | |
| void | set_group_name (const std::string &name) |
| Sets a group name used to visually cluster nodes in DOT output. 更多... | |
| void | set_condition_number (int condition_number) |
| Sets the number of outgoing condition branches. 更多... | |
| void | set_priority (uint16_t priority) |
| Sets the dispatch priority used by priority-aware engines. 更多... | |
| void | set_max_recursion_depth (uint32_t depth) |
| Sets the maximum recursion depth that bounds DFS traversals. 更多... | |
| void | set_policy (Policy policy) |
| Sets the execution policy for this node. 更多... | |
| std::string | get_name () const |
| Returns the node name. 更多... | |
| std::string | get_group_name () const |
| Returns the group name. 更多... | |
| int | get_condition_number () const |
| Returns the configured branch count. 更多... | |
| uint16_t | get_priority () const |
| Returns the configured dispatch priority. 更多... | |
| uint32_t | get_max_recursion_depth () const |
| Returns the maximum recursion depth used for cycle detection. 更多... | |
| Policy | get_policy () const |
| Returns the configured execution policy. 更多... | |
| Status | get_status () const |
| Returns the current execution status of this node. 更多... | |
| void | remove_precede_task (const std::shared_ptr< GraphTask > &task) |
Removes an outgoing edge created by precede. 更多... | |
| void | remove_succeed_task (const std::shared_ptr< GraphTask > &task) |
Removes an incoming edge created by succeed. 更多... | |
| std::vector< std::weak_ptr< GraphTask > > | get_precede_task_list () const |
| Returns the current predecessor list as weak pointers. 更多... | |
| std::vector< std::weak_ptr< GraphTask > > | get_succeed_task_list () const |
| Returns the current successor list as weak pointers. 更多... | |
| bool | is_condition_task () const |
Reports whether this node was created via create_condition. 更多... | |
| bool | has_cycle () const |
| Detects whether the reachable sub-graph contains a cycle. 更多... | |
| std::string | export_to_dot () const |
| Exports the reachable sub-graph as a Graphviz DOT document. 更多... | |
静态 Public 成员函数 | |
| static std::shared_ptr< GraphTask > | create (Callback &&callback, int condition_number=0) |
| Creates a regular work node. 更多... | |
| static std::shared_ptr< GraphTask > | create (const std::string &name, Callback &&callback, int condition_number=0) |
| Creates a named regular work node. 更多... | |
| static std::shared_ptr< GraphTask > | create_condition (ConditionCallback &&callback, int condition_number=0) |
| Creates a condition node whose return value selects a successor branch. 更多... | |
| static std::shared_ptr< GraphTask > | create_condition (const std::string &name, ConditionCallback &&callback, int condition_number=0) |
| Creates a named condition node. 更多... | |
Protected 类型 | |
| using | FindTaskCallback = MoveFunction< void(const std::shared_ptr< GraphTask > &)> |
Protected 成员函数 | |
| GraphTask (Callback &&callback, int condition_number) | |
| GraphTask (const std::string &name, Callback &&callback, int condition_number) | |
| GraphTask (ConditionCallback &&callback, int condition_number) | |
| GraphTask (const std::string &name, ConditionCallback &&callback, int condition_number) | |
| ~GraphTask () | |
| void | process_and_traverse (FindTaskCallback &&callback) |
DAG node carrying a callback, predecessor and successor links, and run-time state.
Must be created through the create / create_condition factories so callbacks share std::enable_shared_from_this safely. execute traverses the reachable sub-graph and submits ready tasks to a user-supplied engine.
| using vlink::GraphTask::Callback = MoveFunction<void()> |
Callback type for void-returning work nodes.
| using vlink::GraphTask::ConditionCallback = MoveFunction<int()> |
Callback type for condition nodes; the return value selects an outgoing branch.
|
protected |
| using vlink::GraphTask::StatusCallback = MoveFunction<void(const std::string&, Status)> |
Status-change notification callback.
Invoked with the task name and the new status whenever the node transitions.
| enum vlink::GraphTask::Policy : uint8_t |
| enum vlink::GraphTask::Status : uint8_t |
|
explicitprotected |
|
explicitprotected |
|
explicitprotected |
|
explicitprotected |
|
protected |
| void vlink::GraphTask::cancel | ( | ) |
Cancels this node and propagates the cancellation downstream.
Sets this node's status to kStatusInActive and walks the successor list forward marking every reachable node inactive. Predecessors are unaffected. Inactive nodes are skipped by the engine and by downstream kPolicyWaitAll counters.
| void vlink::GraphTask::clear_status_callbacks | ( | ) |
Removes every status callback subscription on this node.
|
static |
Creates a regular work node.
| callback | Work function. |
| condition_number | Number of outgoing branches (0 disables branching). |
|
static |
Creates a named regular work node.
| name | Node name used in DOT output and status callbacks. |
| callback | Work function. |
| condition_number | Number of outgoing branches. |
|
static |
Creates a condition node whose return value selects a successor branch.
| callback | Predicate returning the branch index. |
| condition_number | Number of branches accepted; out-of-range returns skip all successors. |
|
static |
Creates a named condition node.
| name | Node name. |
| callback | Predicate returning the branch index. |
| condition_number | Branch count. |
|
inline |
Submits the reachable sub-graph to graph_engine.
Details
Traverses the sub-graph, identifies ready nodes and posts them via post_task or post_task_with_priority when available. Compatible with MessageLoop, MultiLoop and ThreadPool.
| GraphEngineT | Engine type exposing post_task and optionally post_task_with_priority. |
| graph_engine | Target engine instance. |
| std::string vlink::GraphTask::export_to_dot | ( | ) | const |
Exports the reachable sub-graph as a Graphviz DOT document.
| int vlink::GraphTask::get_condition_number | ( | ) | const |
Returns the configured branch count.
| std::string vlink::GraphTask::get_group_name | ( | ) | const |
Returns the group name.
| uint32_t vlink::GraphTask::get_max_recursion_depth | ( | ) | const |
Returns the maximum recursion depth used for cycle detection.
| std::string vlink::GraphTask::get_name | ( | ) | const |
Returns the node name.
| Policy vlink::GraphTask::get_policy | ( | ) | const |
Returns the configured execution policy.
| std::vector<std::weak_ptr<GraphTask> > vlink::GraphTask::get_precede_task_list | ( | ) | const |
Returns the current predecessor list as weak pointers.
| uint16_t vlink::GraphTask::get_priority | ( | ) | const |
Returns the configured dispatch priority.
| Status vlink::GraphTask::get_status | ( | ) | const |
Returns the current execution status of this node.
| std::vector<std::weak_ptr<GraphTask> > vlink::GraphTask::get_succeed_task_list | ( | ) | const |
Returns the current successor list as weak pointers.
| bool vlink::GraphTask::has_cycle | ( | ) | const |
Detects whether the reachable sub-graph contains a cycle.
Iterative DFS with a recursion stack. Acquires per-node mutexes one at a time and does not take the global topology mutex; safe to call from status callbacks fired by invoke or cancel.
true when a cycle is found or the recursion bound is exceeded. | bool vlink::GraphTask::is_condition_task | ( | ) | const |
Reports whether this node was created via create_condition.
true for condition nodes. | void vlink::GraphTask::precede | ( | const std::shared_ptr< GraphTask > & | task | ) |
Declares that this node must complete before task starts.
Runs a reachability pre-check on task 's downstream cone before mutating any list; the edge is rejected (with an error log) if it would form a cycle. On success task is appended to this node's successor list and this node is appended to task 's predecessor list. Topology mutation is serialised by a process-wide recursive mutex shared across every GraphTask instance, so concurrent writers are safe; read paths (execute, has_cycle, export_to_dot) read per-node snapshots without taking that mutex.
| task | Successor node. |
|
protected |
| uint32_t vlink::GraphTask::register_status_callback | ( | StatusCallback && | callback | ) |
Subscribes a callback to status transitions on this node.
Each call appends a new subscriber. On every status change the node snapshots the current subscriber set under status_callbacks_mtx, releases the lock, then invokes the snapshot in unspecified order. Because callbacks fire without the mutex held they may freely register / unregister callbacks on the same node; such mutations apply on the next transition. Exceptions are caught and logged; remaining subscribers still fire.
| callback | Status change callback. |
0 when callback is empty. | void vlink::GraphTask::remove_precede_task | ( | const std::shared_ptr< GraphTask > & | task | ) |
Removes an outgoing edge created by precede.
Removes task from the successor list and removes this node from task 's predecessor list. Logs an error when the edge does not exist.
| task | Previously attached successor. |
| void vlink::GraphTask::remove_succeed_task | ( | const std::shared_ptr< GraphTask > & | task | ) |
Removes an incoming edge created by succeed.
| task | Previously attached predecessor. |
| void vlink::GraphTask::set_condition_number | ( | int | condition_number | ) |
Sets the number of outgoing condition branches.
| condition_number | Branch count. |
| void vlink::GraphTask::set_group_name | ( | const std::string & | name | ) |
Sets a group name used to visually cluster nodes in DOT output.
| name | Group name. |
| void vlink::GraphTask::set_max_recursion_depth | ( | uint32_t | depth | ) |
Sets the maximum recursion depth that bounds DFS traversals.
Traversals exceeding this depth treat the graph as conservatively cyclic. Default: 10000.
| depth | Maximum recursion depth. |
| void vlink::GraphTask::set_name | ( | const std::string & | name | ) |
Sets the node name used in DOT output and status callbacks.
| name | Node name. |
| void vlink::GraphTask::set_policy | ( | Policy | policy | ) |
Sets the execution policy for this node.
| policy | Policy enumerator. |
| void vlink::GraphTask::set_priority | ( | uint16_t | priority | ) |
Sets the dispatch priority used by priority-aware engines.
| priority | Priority value. |
| void vlink::GraphTask::succeed | ( | const std::shared_ptr< GraphTask > & | task | ) |
Declares that task must complete before this node starts.
Mirror of precede; rejects edges that would form a cycle. Shares the same single-writer topology mutex as precede.
| task | Predecessor node. |
| bool vlink::GraphTask::unregister_status_callback | ( | uint32_t | id | ) |
Removes a previously registered status callback by id.
| id | Subscription id returned by register_status_callback. |
true when the subscription was found and removed.