VLink  2.0.0
A high-performance communication middleware
vlink::GraphTask类 参考final

DAG node carrying a callback, predecessor and successor links, and run-time state. 更多...

#include <graph_task.h>

类 vlink::GraphTask 继承关系图:
vlink::GraphTask 的协作图:

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< GraphTaskcreate (Callback &&callback, int condition_number=0)
 Creates a regular work node. 更多...
 
static std::shared_ptr< GraphTaskcreate (const std::string &name, Callback &&callback, int condition_number=0)
 Creates a named regular work node. 更多...
 
static std::shared_ptr< GraphTaskcreate_condition (ConditionCallback &&callback, int condition_number=0)
 Creates a condition node whose return value selects a successor branch. 更多...
 
static std::shared_ptr< GraphTaskcreate_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.

成员类型定义说明

◆ Callback

Callback type for void-returning work nodes.

◆ ConditionCallback

Callback type for condition nodes; the return value selects an outgoing branch.

◆ FindTaskCallback

using vlink::GraphTask::FindTaskCallback = MoveFunction<void(const std::shared_ptr<GraphTask>&)>
protected

◆ StatusCallback

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.

成员枚举类型说明

◆ Policy

enum vlink::GraphTask::Policy : uint8_t

Policy controlling how many times the task may run within a pass.

枚举值
kPolicyOnce 

Run exactly once per execute pass (default).

kPolicyMultiple 

Allow multiple invocations within the pass.

kPolicyWaitAll 

Wait for every predecessor before running.

◆ Status

enum vlink::GraphTask::Status : uint8_t

Run-time execution state of a node within an execute pass.

枚举值
kStatusInActive 

Not yet submitted or cancelled.

kStatusPending 

Waiting for predecessors to complete.

kStatusRunning 

Currently executing.

kStatusDone 

Execution finished.

构造及析构函数说明

◆ GraphTask() [1/4]

vlink::GraphTask::GraphTask ( Callback &&  callback,
int  condition_number 
)
explicitprotected

◆ GraphTask() [2/4]

vlink::GraphTask::GraphTask ( const std::string &  name,
Callback &&  callback,
int  condition_number 
)
explicitprotected

◆ GraphTask() [3/4]

vlink::GraphTask::GraphTask ( ConditionCallback &&  callback,
int  condition_number 
)
explicitprotected

◆ GraphTask() [4/4]

vlink::GraphTask::GraphTask ( const std::string &  name,
ConditionCallback &&  callback,
int  condition_number 
)
explicitprotected

◆ ~GraphTask()

vlink::GraphTask::~GraphTask ( )
protected

成员函数说明

◆ cancel()

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.

◆ clear_status_callbacks()

void vlink::GraphTask::clear_status_callbacks ( )

Removes every status callback subscription on this node.

◆ create() [1/2]

static std::shared_ptr<GraphTask> vlink::GraphTask::create ( Callback &&  callback,
int  condition_number = 0 
)
static

Creates a regular work node.

参数
callbackWork function.
condition_numberNumber of outgoing branches (0 disables branching).
返回
Shared pointer to the new task.

◆ create() [2/2]

static std::shared_ptr<GraphTask> vlink::GraphTask::create ( const std::string &  name,
Callback &&  callback,
int  condition_number = 0 
)
static

Creates a named regular work node.

参数
nameNode name used in DOT output and status callbacks.
callbackWork function.
condition_numberNumber of outgoing branches.
返回
Shared pointer to the new task.

◆ create_condition() [1/2]

static std::shared_ptr<GraphTask> vlink::GraphTask::create_condition ( ConditionCallback &&  callback,
int  condition_number = 0 
)
static

Creates a condition node whose return value selects a successor branch.

参数
callbackPredicate returning the branch index.
condition_numberNumber of branches accepted; out-of-range returns skip all successors.
返回
Shared pointer to the new condition task.

◆ create_condition() [2/2]

static std::shared_ptr<GraphTask> vlink::GraphTask::create_condition ( const std::string &  name,
ConditionCallback &&  callback,
int  condition_number = 0 
)
static

Creates a named condition node.

参数
nameNode name.
callbackPredicate returning the branch index.
condition_numberBranch count.
返回
Shared pointer to the new condition task.

◆ execute()

template<class GraphEngineT >
void vlink::GraphTask::execute ( GraphEngineT *  graph_engine)
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.

模板参数
GraphEngineTEngine type exposing post_task and optionally post_task_with_priority.
参数
graph_engineTarget engine instance.
函数调用图:

◆ export_to_dot()

std::string vlink::GraphTask::export_to_dot ( ) const

Exports the reachable sub-graph as a Graphviz DOT document.

返回
DOT source string.

◆ get_condition_number()

int vlink::GraphTask::get_condition_number ( ) const

Returns the configured branch count.

返回
Branch count.

◆ get_group_name()

std::string vlink::GraphTask::get_group_name ( ) const

Returns the group name.

返回
Group name.

◆ get_max_recursion_depth()

uint32_t vlink::GraphTask::get_max_recursion_depth ( ) const

Returns the maximum recursion depth used for cycle detection.

返回
Recursion depth bound.

◆ get_name()

std::string vlink::GraphTask::get_name ( ) const

Returns the node name.

返回
Node name.

◆ get_policy()

Policy vlink::GraphTask::get_policy ( ) const

Returns the configured execution policy.

返回
Policy enumerator.

◆ get_precede_task_list()

std::vector<std::weak_ptr<GraphTask> > vlink::GraphTask::get_precede_task_list ( ) const

Returns the current predecessor list as weak pointers.

返回
Vector of weak predecessor pointers.

◆ get_priority()

uint16_t vlink::GraphTask::get_priority ( ) const

Returns the configured dispatch priority.

返回
Priority value.

◆ get_status()

Status vlink::GraphTask::get_status ( ) const

Returns the current execution status of this node.

返回
Status enumerator.

◆ get_succeed_task_list()

std::vector<std::weak_ptr<GraphTask> > vlink::GraphTask::get_succeed_task_list ( ) const

Returns the current successor list as weak pointers.

返回
Vector of weak successor pointers.

◆ has_cycle()

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.

◆ is_condition_task()

bool vlink::GraphTask::is_condition_task ( ) const

Reports whether this node was created via create_condition.

返回
true for condition nodes.

◆ precede()

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.

参数
taskSuccessor node.

◆ process_and_traverse()

void vlink::GraphTask::process_and_traverse ( FindTaskCallback &&  callback)
protected
这是这个函数的调用关系图:

◆ register_status_callback()

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.

参数
callbackStatus change callback.
返回
Subscription id (>0). Returns 0 when callback is empty.

◆ remove_precede_task()

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.

参数
taskPreviously attached successor.

◆ remove_succeed_task()

void vlink::GraphTask::remove_succeed_task ( const std::shared_ptr< GraphTask > &  task)

Removes an incoming edge created by succeed.

参数
taskPreviously attached predecessor.

◆ set_condition_number()

void vlink::GraphTask::set_condition_number ( int  condition_number)

Sets the number of outgoing condition branches.

参数
condition_numberBranch count.

◆ set_group_name()

void vlink::GraphTask::set_group_name ( const std::string &  name)

Sets a group name used to visually cluster nodes in DOT output.

参数
nameGroup name.

◆ set_max_recursion_depth()

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.

参数
depthMaximum recursion depth.

◆ set_name()

void vlink::GraphTask::set_name ( const std::string &  name)

Sets the node name used in DOT output and status callbacks.

参数
nameNode name.

◆ set_policy()

void vlink::GraphTask::set_policy ( Policy  policy)

Sets the execution policy for this node.

参数
policyPolicy enumerator.

◆ set_priority()

void vlink::GraphTask::set_priority ( uint16_t  priority)

Sets the dispatch priority used by priority-aware engines.

参数
priorityPriority value.

◆ succeed()

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.

参数
taskPredecessor node.

◆ unregister_status_callback()

bool vlink::GraphTask::unregister_status_callback ( uint32_t  id)

Removes a previously registered status callback by id.

参数
idSubscription id returned by register_status_callback.
返回
true when the subscription was found and removed.

该类的文档由以下文件生成: