提交 013daba4 创建 作者: David Benjamin's avatar David Benjamin

Delete tree in radix destructor

Possibly this just wants to live in the radix_node destructor. Right now we need level information, but we can stick that in without increasing the malloc size, and we'll have a bit to use instead later.
上级 1d7f9493
......@@ -30,6 +30,7 @@ struct radix_node : public rcu_freed {
ptr[i] = 0;
}
void delete_tree(u32 level);
virtual void do_gc() { delete this; }
NEW_DELETE_OPS(radix_node)
......@@ -61,6 +62,7 @@ struct radix {
radix(u32 shift) : root_(0), shift_(shift) {
root_.ptr() = new radix_node();
}
~radix();
radix_elem* search(u64 key);
radix_range search_lock(u64 start, u64 size);
......
......@@ -47,6 +47,27 @@ descend(u64 key, markptr<void> *n, u32 level, CB cb, bool create)
}
}
void
radix_node::delete_tree(u32 level)
{
for (int i = 0; i < (1<<bits_per_level); i++) {
void *child = ptr[i].ptr();
if (child != nullptr) {
if (level > 1)
static_cast<radix_node*>(child)->delete_tree(level-1);
else
static_cast<radix_elem*>(child)->decref();
}
}
do_gc();
}
radix::~radix()
{
void *root = root_.ptr();
static_cast<radix_node*>(root)->delete_tree(radix_levels);
}
radix_elem*
radix::search(u64 key)
{
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论