walk_tg_tree_from的图解

简介: walk_tg_tree_from的图解

在遍历task_group的时候,需要会调用到walk_tg_tree_from函数,从函数注释看,这个函数的流程是:

from为根节点,当进入一个节点时调用down回调函数,当离开一个节点时调用up函数。这个函数

采用的是深度遍历。

下面用一张图来说明:

/*
 * Iterate task_group tree rooted at *from, calling @down when first entering a
 * node and @up when leaving it for the final time.
 *
 * Caller must hold rcu_lock or sufficient equivalent.
 */
int walk_tg_tree_from(struct task_group *from,
           tg_visitor down, tg_visitor up, void *data)
{
  struct task_group *parent, *child;
  int ret;
  parent = from;
down:
  ret = (*down)(parent, data);
  if (ret)
    goto out;
  list_for_each_entry_rcu(child, &parent->children, siblings) {
    parent = child;
    goto down;
up:
    continue;
  }
  ret = (*up)(parent, data);
  if (ret || parent == from)
    goto out;
  child = parent;
  parent = parent->parent;
  if (parent)
    goto up;
out:
  return ret;
}
相关文章
|
7月前
|
缓存 索引
图解B Tree和B+ Tree
图解B Tree和B+ Tree
69 0
|
3月前
|
Shell
9-9|tree如何实现ll的效果
9-9|tree如何实现ll的效果
Leetcode 623. Add One Row to Tree
题目很简单,在树的第d层加一层,值为v。递归增加一层就好了。代码如下
49 0
|
存储 数据格式
1367:查找二叉树(tree_a)
1367:查找二叉树(tree_a)
LeetCode 429. N-ary Tree Level Order Traversal
给定一个 N 叉树,返回其节点值的层序遍历。 (即从左到右,逐层遍历)。
87 0
LeetCode 429. N-ary Tree Level Order Traversal
LeetCode 222. Count Complete Tree Nodes
给出一个完全二叉树,求出该树的节点个数。
91 0
LeetCode 222. Count Complete Tree Nodes
|
人工智能
[Codeforces 1286B] Numbers on Tree | 技巧构造
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer ai written on it. For each vertex i, Evlampiy calculated ci — the number of vertices j in the subtree of vertex i, such that a j < a i
118 0
[Codeforces 1286B] Numbers on Tree | 技巧构造
[LeetCode] Add One Row to Tree 二叉树中增加一行
Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d.
1073 0