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:
2026-02-23 18:34:12 +00:00
parent 37ae7aeef7
commit 5690dd5b9c
2 changed files with 26 additions and 4 deletions

View File

@@ -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)