Files
mop3/kernel/proc/resource.c
kamkow1 124aa12f5b
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
Redesign scheduling points
2026-01-30 02:36:27 +01:00

60 lines
1.6 KiB
C

#include <libk/assert.h>
#include <libk/list.h>
#include <libk/rbtree.h>
#include <libk/std.h>
#include <libk/string.h>
#include <mm/liballoc.h>
#include <mm/pmm.h>
#include <proc/mutex.h>
#include <proc/proc.h>
#include <proc/procgroup.h>
#include <proc/resource.h>
#include <sync/spin_lock.h>
#include <sys/debug.h>
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;
}
bool proc_delete_resource (struct proc_resource* resource) {
bool reschedule = resource->ops.cleanup (resource);
free (resource);
return reschedule;
}