0

执行以下操作是否有效

struct foo {
int data;
struct rb_node node
};
struct rb_root root;
/* Filling tree with kalloc'ed foo nodes */
struct rb_node *node=rb_first(&root);
while (node)
{
 struct rb_node *next=rb_next(node);
 kfree(node);
 node = next;
}
root=RB_ROOT;

事实上,我只想用线性时间同时做 foreach 和 clear 。

4

1 回答 1

0

探索了 rb_next 实现。它在正确的孩子之前返回父母。因此,以这种方式清除列表是不可能的。

于 2012-06-09T07:17:31.873 回答