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:
@@ -52,7 +52,10 @@ enum object_type_flags {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct object_ops {
|
struct object_ops {
|
||||||
kern_status_t (*destroy)(struct object *obj);
|
kern_status_t (*destroy)(struct object *obj, struct queue *q);
|
||||||
|
kern_status_t (*destroy_recurse)(
|
||||||
|
struct queue_entry *entry,
|
||||||
|
struct object **out);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct object_type {
|
struct object_type {
|
||||||
|
|||||||
@@ -83,6 +83,15 @@ struct object *object_ref(struct object *obj)
|
|||||||
return 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)
|
static void object_cleanup(struct object *obj, unsigned long flags)
|
||||||
{
|
{
|
||||||
if (obj->ob_refcount > 0 || obj->ob_handles > 0) {
|
if (obj->ob_refcount > 0 || obj->ob_handles > 0) {
|
||||||
@@ -90,11 +99,21 @@ static void object_cleanup(struct object *obj, unsigned long flags)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAS_OP(obj, destroy)) {
|
struct queue queue = QUEUE_INIT;
|
||||||
obj->ob_type->ob_ops.destroy(obj);
|
__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)
|
void object_unref(struct object *obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user