Move mutex and mem create/cleanup functions into mutex.c and mem.c respectively
All checks were successful
Build documentation / build-and-deploy (push) Successful in 33s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 33s
This commit is contained in:
@@ -1,9 +1,29 @@
|
||||
#include <libk/std.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <proc/mem.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/resource.h>
|
||||
#include <sync/spin_lock.h>
|
||||
|
||||
bool proc_create_resource_mem (struct proc_resource_mem* mem, struct proc_resource_mem_init* init) {
|
||||
if (init->pages == 0)
|
||||
return false;
|
||||
|
||||
uintptr_t paddr = pmm_alloc (init->pages);
|
||||
if (paddr == PMM_ALLOC_ERR)
|
||||
return false;
|
||||
|
||||
mem->paddr = paddr;
|
||||
mem->pages = mem->alive_pages = init->pages;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void proc_cleanup_resource_mem (struct proc* proc, struct proc_resource* resource) {
|
||||
(void)proc;
|
||||
pmm_free (resource->u.mem.paddr, resource->u.mem.pages);
|
||||
}
|
||||
|
||||
void proc_mem_unref (struct proc* proc, struct proc_resource_mem* mem, size_t pages) {
|
||||
spin_lock_ctx_t ctxrs;
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ struct proc_resource_mem_init {
|
||||
size_t pages;
|
||||
};
|
||||
|
||||
bool proc_create_resource_mem (struct proc_resource_mem* mem, struct proc_resource_mem_init* init);
|
||||
void proc_cleanup_resource_mem (struct proc* proc, struct proc_resource* resource);
|
||||
void proc_mem_unref (struct proc* proc, struct proc_resource_mem* mem, size_t pages);
|
||||
|
||||
#endif // _KERNEL_PROC_MEM_H
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
#include <libk/assert.h>
|
||||
#include <libk/rbtree.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <proc/mutex.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
bool proc_create_resource_mutex (struct proc_mutex* mutex) {
|
||||
memset (mutex, 0, sizeof (*mutex));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void proc_cleanup_resource_mutex (struct proc* proc, struct proc_resource* resource) {
|
||||
struct proc_mutex* mutex = &resource->u.mutex;
|
||||
|
||||
proc_mutex_unlock (proc, mutex);
|
||||
}
|
||||
|
||||
void proc_mutex_lock (struct proc* proc, struct proc_mutex* mutex) {
|
||||
spin_lock_ctx_t ctxmt;
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ struct proc_mutex {
|
||||
struct proc* owner;
|
||||
};
|
||||
|
||||
bool proc_create_resource_mutex (struct proc_mutex* mutex);
|
||||
void proc_cleanup_resource_mutex (struct proc* proc, struct proc_resource* resource);
|
||||
void proc_mutex_lock (struct proc* proc, struct proc_mutex* mutex);
|
||||
bool proc_mutex_unlock (struct proc* proc, struct proc_mutex* mutex);
|
||||
|
||||
|
||||
@@ -42,38 +42,6 @@ void proc_drop_resource (struct proc* proc, struct proc_resource* resource) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool proc_create_resource_mem (struct proc_resource_mem* mem,
|
||||
struct proc_resource_mem_init* init) {
|
||||
if (init->pages == 0)
|
||||
return false;
|
||||
|
||||
uintptr_t paddr = pmm_alloc (init->pages);
|
||||
if (paddr == PMM_ALLOC_ERR)
|
||||
return false;
|
||||
|
||||
mem->paddr = paddr;
|
||||
mem->pages = mem->alive_pages = init->pages;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void proc_cleanup_resource_mem (struct proc* proc, struct proc_resource* resource) {
|
||||
(void)proc;
|
||||
pmm_free (resource->u.mem.paddr, resource->u.mem.pages);
|
||||
}
|
||||
|
||||
static bool proc_create_resource_mutex (struct proc_mutex* mutex) {
|
||||
memset (mutex, 0, sizeof (*mutex));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void proc_cleanup_resource_mutex (struct proc* proc, struct proc_resource* resource) {
|
||||
struct proc_mutex* mutex = &resource->u.mutex;
|
||||
|
||||
proc_mutex_unlock (proc, mutex);
|
||||
}
|
||||
|
||||
struct proc_resource* proc_create_resource (struct proc* proc, int rid, int type, int vis,
|
||||
void* data) {
|
||||
spin_lock_ctx_t ctxpr;
|
||||
|
||||
Reference in New Issue
Block a user