kupl::sgraph_add_node
向kupl静态图中添加 sgraph node节点,即添加任务节点。相较于kupl_sgraph_add_node接口而言,该接口通过lambda函数特性捕获kupl_sgraph_add_node提交任务节点回调函数的入参, 避免用户入参封装行为,提高接口易用性。
接口定义
kupl_sgraph_node_h sgraph_add_node(kupl_sgraph_h sgraph, kupl_sgraph_node_desc_t *desc, const std::function<void(void)> &func);
参数
参数名 |
类型 |
描述 |
输入/输出 |
|---|---|---|---|
sgraph |
kupl_sgraph_h |
需要向其中添加sgraph node的静态图 |
输入/输出 |
desc |
kupl_sgraph_node_desc_t * |
需要添加的sgraph node的描述,具体见下表 |
输入 |
func |
std::function<void(void)> |
sgraph node节点的函数,该节点提交执行后需要执行的具体函数 |
输入 |
参数名 |
类型 |
描述 |
|---|---|---|
field_mask |
uint64_t |
掩码,用于指定结构体中哪些值有效。 具体可设置的掩码:
|
name |
const char * |
需要配置掩码KUPL_SGRAPH_NODE_DESC_FIELD_NAME 后才能生效;该节点的名字 |
priority |
int |
需要配置掩码KUPL_SGRAPH_NODE_DESC_FIELD_PRIORITY 后才能生效;该节点的优先级,数值越大,优先级越高 |
flag |
uint32_t |
需要配置掩码 KUPL_SGRAPH_NODE_DESC_FIELD_FLAG后才能生效;该节点的flag,可设置为 KUPL_SGRAPH_NODE_FLAG_IMM,表示提交后将直接执行该节点 |
egroup |
kupl_egroup_h |
指定当前sgraph node的亲和性信息 |
返回值
- 成功:返回添加的 sgraph node节点
- 失败:返回nullptr
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> #include "kupl.h" int main() { kupl_graph_h graph = kupl_graph_create(nullptr); kupl_sgraph_h sgraph = kupl_sgraph_create(); kupl_sgraph_node_desc_t node_desc = { .field_mask = KUPL_SGRAPH_NODE_DESC_FIELD_NAME, .name = "sgraph_task", }; kupl_sgraph_node_h node = kupl::sgraph_add_node(sgraph, &node_desc, []() { printf("sgraph task test\n"); }); kupl_sgraph_task_desc_t task_desc = { .sgraph = sgraph, }; kupl_task_info_t info = { .type = KUPL_TASK_TYPE_SGRAPH, .desc = &task_desc, }; kupl_graph_submit(graph, &info); kupl_graph_wait(graph); kupl_graph_destroy(graph); kupl_sgraph_destroy(sgraph); return 0; } |
sgraph task test
上述示例演示了在静态图中添加gnode,并通过提交静态图执行的流程。上述kupl::sgraph_add_node函数向静态图sgraph中添加了sgraph node节点,该sgraph node节点的函数不需要参数。