Unlock mutexes on process death
This commit is contained in:
@@ -37,6 +37,8 @@ void app_main (void) {
|
|||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
test (letter);
|
test (letter);
|
||||||
|
|
||||||
|
process_quit ();
|
||||||
|
|
||||||
mutex_unlock (MUTEX);
|
mutex_unlock (MUTEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <limine/requests.h>
|
#include <limine/requests.h>
|
||||||
#include <mm/liballoc.h>
|
#include <mm/liballoc.h>
|
||||||
#include <mm/pmm.h>
|
#include <mm/pmm.h>
|
||||||
|
#include <proc/mutex.h>
|
||||||
#include <proc/proc.h>
|
#include <proc/proc.h>
|
||||||
#include <proc/procgroup.h>
|
#include <proc/procgroup.h>
|
||||||
#include <proc/resource.h>
|
#include <proc/resource.h>
|
||||||
@@ -118,6 +119,8 @@ void proc_cleanup (struct proc* proc) {
|
|||||||
|
|
||||||
spin_unlock (&proc->lock, &ctxpr);
|
spin_unlock (&proc->lock, &ctxpr);
|
||||||
|
|
||||||
|
proc_mutexes_cleanup (proc);
|
||||||
|
|
||||||
pmm_free (proc->pdata.kernel_stack, KSTACK_SIZE / PAGE_SIZE);
|
pmm_free (proc->pdata.kernel_stack, KSTACK_SIZE / PAGE_SIZE);
|
||||||
procgroup_unmap (proc->procgroup, proc->pdata.tls_vaddr, proc->procgroup->tls.tls_tmpl_pages);
|
procgroup_unmap (proc->procgroup, proc->pdata.tls_vaddr, proc->procgroup->tls.tls_tmpl_pages);
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,39 @@ static void proc_mutex_resume (struct proc* proc, struct proc_sq_entry* sq_entry
|
|||||||
cpu_request_sched (cpu);
|
cpu_request_sched (cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void proc_mutexes_cleanup (struct proc* proc) {
|
||||||
|
spin_lock_ctx_t ctxpg, ctxrs;
|
||||||
|
|
||||||
|
spin_lock (&proc->procgroup->lock, &ctxpg);
|
||||||
|
|
||||||
|
struct rb_node_link* rnode;
|
||||||
|
rbtree_first (&proc->procgroup->resource_tree, rnode);
|
||||||
|
|
||||||
|
while (rnode) {
|
||||||
|
struct rb_node_link* next;
|
||||||
|
rbtree_next (rnode, next);
|
||||||
|
|
||||||
|
struct proc_resource* resource = rbtree_entry (rnode, struct proc_resource, resource_tree_link);
|
||||||
|
|
||||||
|
rnode = next;
|
||||||
|
|
||||||
|
spin_lock (&resource->lock, &ctxrs);
|
||||||
|
|
||||||
|
if (resource->type != PR_MUTEX) {
|
||||||
|
spin_unlock (&resource->lock, &ctxrs);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource->u.mutex.owner == proc && resource->u.mutex.locked) {
|
||||||
|
spin_unlock (&resource->lock, &ctxrs);
|
||||||
|
|
||||||
|
proc_mutex_unlock (proc, &resource->u.mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spin_unlock (&proc->procgroup->lock, &ctxpg);
|
||||||
|
}
|
||||||
|
|
||||||
void proc_cleanup_resource_mutex (struct proc_resource* resource) {
|
void proc_cleanup_resource_mutex (struct proc_resource* resource) {
|
||||||
struct proc_mutex* mutex = &resource->u.mutex;
|
struct proc_mutex* mutex = &resource->u.mutex;
|
||||||
spin_lock_ctx_t ctxmt, ctxsq;
|
spin_lock_ctx_t ctxmt, ctxsq;
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ struct proc_mutex {
|
|||||||
void proc_cleanup_resource_mutex (struct proc_resource* resource);
|
void proc_cleanup_resource_mutex (struct proc_resource* resource);
|
||||||
void proc_mutex_lock (struct proc* proc, struct proc_mutex* mutex);
|
void proc_mutex_lock (struct proc* proc, struct proc_mutex* mutex);
|
||||||
bool proc_mutex_unlock (struct proc* proc, struct proc_mutex* mutex);
|
bool proc_mutex_unlock (struct proc* proc, struct proc_mutex* mutex);
|
||||||
|
void proc_mutexes_cleanup (struct proc* proc);
|
||||||
|
|
||||||
#endif // _KERNEL_PROC_MUTEX_H
|
#endif // _KERNEL_PROC_MUTEX_H
|
||||||
|
|||||||
Reference in New Issue
Block a user