kupl::sgraph_add_node
Adds an sgraph node to the KUPL static graph, that is, add a task node. Compared with kupl_sgraph_add_node, this interface uses the lambda function to capture the input parameters of the kupl_sgraph_add_node callback, eliminating the need for manual parameter encapsulation and improving interface usability.
Interface Definition
kupl_sgraph_node_h sgraph_add_node(kupl_sgraph_h sgraph, kupl_sgraph_node_desc_t *desc, const std::function<void(void)> &func);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
sgraph |
kupl_sgraph_h |
Static graph to which a sgraph node needs to be added. |
Input/Output |
desc |
kupl_sgraph_node_desc_t * |
Description of the sgraph node to be added. For details, see the following table. |
Input |
func |
std::function<void(void)> |
Function associated with the sgraph node. This parameter specifies the function to be executed after the node is submitted for execution. |
Input |
Parameter |
Type |
Description |
|---|---|---|
field_mask |
uint64_t |
Mask, specifying which values in the structure are valid. Options:
|
name |
const char * |
Name of the node. This parameter takes effect only after the mask KUPL_SGRAPH_NODE_DESC_FIELD_NAME is configured. |
priority |
int |
Priority of the node. This parameter takes effect only after the mask KUPL_SGRAPH_NODE_DESC_FIELD_PRIORITY is configured. A larger value indicates a higher priority. |
flag |
uint32_t |
Flag of the node. This parameter takes effect only after the mask KUPL_SGRAPH_NODE_DESC_FIELD_FLAG is configured. The value can be set to KUPL_SGRAPH_NODE_FLAG_IMM, indicating that the node is immediately executed after being submitted. |
egroup |
kupl_egroup_h |
Affinity information about the current sgraph node. |
Return Value
- Success: the added sgraph node
- Failure: nullptr
Examples
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
The preceding example demonstrates how to add a gnode to a static graph and submit the static graph for execution. The preceding kupl::sgraph_add_node function adds an sgraph node to the static graph sgraph. The function associated with the sgraph node does not require any parameters.