kernel: add support for recursive object destruction (without recursion)
this system makes it possible for an object that forms part of a tree to be safely recursively destroyed without using recursion.
This commit is contained in:
@@ -83,6 +83,15 @@ struct object *object_ref(struct object *obj)
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void __cleanup(struct object *obj, struct queue *queue)
|
||||
{
|
||||
if (HAS_OP(obj, destroy)) {
|
||||
obj->ob_type->ob_ops.destroy(obj, queue);
|
||||
}
|
||||
|
||||
vm_cache_free(&obj->ob_type->ob_cache, obj);
|
||||
}
|
||||
|
||||
static void object_cleanup(struct object *obj, unsigned long flags)
|
||||
{
|
||||
if (obj->ob_refcount > 0 || obj->ob_handles > 0) {
|
||||
@@ -90,11 +99,21 @@ static void object_cleanup(struct object *obj, unsigned long flags)
|
||||
return;
|
||||
}
|
||||
|
||||
if (HAS_OP(obj, destroy)) {
|
||||
obj->ob_type->ob_ops.destroy(obj);
|
||||
struct queue queue = QUEUE_INIT;
|
||||
__cleanup(obj, &queue);
|
||||
|
||||
if (!HAS_OP(obj, destroy_recurse)) {
|
||||
return;
|
||||
}
|
||||
|
||||
vm_cache_free(&obj->ob_type->ob_cache, obj);
|
||||
while (!queue_empty(&queue)) {
|
||||
struct queue_entry *entry = queue_pop_front(&queue);
|
||||
struct object *child = NULL;
|
||||
obj->ob_type->ob_ops.destroy_recurse(entry, &child);
|
||||
if (child) {
|
||||
__cleanup(child, &queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void object_unref(struct object *obj)
|
||||
|
||||
Reference in New Issue
Block a user