#include #include #include #include #include #include #include #include #include #include #include #include #include struct proc_resource* proc_find_resource (struct procgroup* procgroup, int rid) { spin_lock_ctx_t ctxpg; struct proc_resource* resource = NULL; spin_lock (&procgroup->lock, &ctxpg); rbtree_find (struct proc_resource, &procgroup->resource_tree, rid, resource, resource_tree_link, rid); spin_unlock (&procgroup->lock, &ctxpg); return resource; } struct proc_resource* proc_create_resource_mutex (struct procgroup* procgroup, int rid) { spin_lock_ctx_t ctxpg; struct proc_resource* resource; resource = proc_find_resource (procgroup, rid); if (resource != NULL) return resource; resource = malloc (sizeof (*resource)); if (resource == NULL) return NULL; memset (resource, 0, sizeof (*resource)); resource->lock = SPIN_LOCK_INIT; resource->ops.cleanup = &proc_cleanup_resource_mutex; resource->u.mutex.resource = resource; resource->rid = rid; resource->type = PR_MUTEX; spin_lock (&procgroup->lock, &ctxpg); rbtree_insert (struct proc_resource, &procgroup->resource_tree, &resource->resource_tree_link, resource_tree_link, rid); spin_unlock (&procgroup->lock, &ctxpg); return resource; } void proc_delete_resource (struct proc_resource* resource) { resource->ops.cleanup (resource); free (resource); }