Remove dead process from it's suspension queues
This commit is contained in:
@@ -47,8 +47,6 @@ void app_main (void) {
|
|||||||
|
|
||||||
spawn (&app_thread1);
|
spawn (&app_thread1);
|
||||||
|
|
||||||
/* for (volatile int i = 0; i < 1000*1000; i++) */
|
|
||||||
/* ; */
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
lock_mutex (MUTEX, RV_PRIVATE);
|
lock_mutex (MUTEX, RV_PRIVATE);
|
||||||
|
|
||||||
@@ -56,9 +54,6 @@ void app_main (void) {
|
|||||||
test ('a');
|
test ('a');
|
||||||
|
|
||||||
unlock_mutex (MUTEX, RV_PRIVATE);
|
unlock_mutex (MUTEX, RV_PRIVATE);
|
||||||
|
|
||||||
/* for (volatile int i = 0; i < 1000*1000; i++) */
|
|
||||||
/* ; */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +65,6 @@ void app_thread1 (void) {
|
|||||||
test ('b');
|
test ('b');
|
||||||
|
|
||||||
unlock_mutex (MUTEX, RV_PRIVATE);
|
unlock_mutex (MUTEX, RV_PRIVATE);
|
||||||
|
|
||||||
/* for (volatile int i = 0; i < 1000*1000; i++) */
|
|
||||||
/* ; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quit ();
|
quit ();
|
||||||
|
|||||||
@@ -184,10 +184,35 @@ struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, size_t stack_
|
|||||||
|
|
||||||
void proc_cleanup (struct proc* proc) {
|
void proc_cleanup (struct proc* proc) {
|
||||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||||
spin_lock_ctx_t ctxprpd;
|
spin_lock_ctx_t ctxprpd, ctxsq, ctxpr;
|
||||||
|
|
||||||
|
spin_lock (&proc->lock, &ctxpr);
|
||||||
|
|
||||||
|
/* clean suspension queue entries */
|
||||||
|
struct list_node_link *sq_link, *sq_link_tmp;
|
||||||
|
list_foreach (proc->sq_entries, sq_link, sq_link_tmp) {
|
||||||
|
struct proc_sq_entry* sq_entry = list_entry (sq_link, struct proc_sq_entry, proc_link);
|
||||||
|
struct proc_suspension_q* sq = sq_entry->sq;
|
||||||
|
|
||||||
|
spin_lock (&sq->lock, &ctxsq);
|
||||||
|
|
||||||
|
/* remove from sq's list */
|
||||||
|
list_remove (sq->proc_list, &sq_entry->sq_link);
|
||||||
|
|
||||||
|
/* remove from proc's list */
|
||||||
|
list_remove (proc->sq_entries, &sq_entry->proc_link);
|
||||||
|
|
||||||
|
spin_unlock (&sq->lock, &ctxsq);
|
||||||
|
|
||||||
|
free (sq_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
spin_unlock (&proc->lock, &ctxpr);
|
||||||
|
|
||||||
|
/* clean resources */
|
||||||
proc_cleanup_resources (proc);
|
proc_cleanup_resources (proc);
|
||||||
|
|
||||||
|
/* clean virtual address space */
|
||||||
if (atomic_fetch_sub (&proc->pd->refs, 1) == 1) {
|
if (atomic_fetch_sub (&proc->pd->refs, 1) == 1) {
|
||||||
DEBUG ("PID %d Free virtual address space\n", proc->pid);
|
DEBUG ("PID %d Free virtual address space\n", proc->pid);
|
||||||
struct list_node_link *mapping_link, *mapping_link_tmp;
|
struct list_node_link *mapping_link, *mapping_link_tmp;
|
||||||
@@ -206,13 +231,16 @@ void proc_cleanup (struct proc* proc) {
|
|||||||
free (proc->pd);
|
free (proc->pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clean kstack */
|
||||||
pmm_free (proc->pdata.kernel_stack - (uintptr_t)hhdm->offset - KSTACK_SIZE,
|
pmm_free (proc->pdata.kernel_stack - (uintptr_t)hhdm->offset - KSTACK_SIZE,
|
||||||
KSTACK_SIZE / PAGE_SIZE);
|
KSTACK_SIZE / PAGE_SIZE);
|
||||||
|
|
||||||
|
/* clean ustack */
|
||||||
if ((proc->flags & PROC_USTK_PREALLOC))
|
if ((proc->flags & PROC_USTK_PREALLOC))
|
||||||
pmm_free (proc->pdata.user_stack, USTACK_SIZE / PAGE_SIZE);
|
pmm_free (proc->pdata.user_stack, USTACK_SIZE / PAGE_SIZE);
|
||||||
|
|
||||||
DEBUG ("PID %d Free stacks\n", proc->pid);
|
DEBUG ("PID %d Free stacks\n", proc->pid);
|
||||||
|
|
||||||
|
/* clean the process */
|
||||||
free (proc);
|
free (proc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ static void proc_mutex_suspend (struct proc* proc, struct proc_suspension_q* sq,
|
|||||||
|
|
||||||
atomic_store (&proc->state, PROC_SUSPENDED);
|
atomic_store (&proc->state, PROC_SUSPENDED);
|
||||||
|
|
||||||
|
/* append to sq's list */
|
||||||
list_append (sq->proc_list, &sq_entry->sq_link);
|
list_append (sq->proc_list, &sq_entry->sq_link);
|
||||||
|
|
||||||
|
/* append to proc's list */
|
||||||
list_append (proc->sq_entries, &sq_entry->proc_link);
|
list_append (proc->sq_entries, &sq_entry->proc_link);
|
||||||
|
|
||||||
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
list_remove (cpu->proc_run_q, &proc->cpu_run_q_link);
|
||||||
@@ -60,7 +62,10 @@ static void proc_mutex_resume (struct proc* proc, struct proc_sq_entry* sq_entry
|
|||||||
spin_lock (&proc->lock, &ctxpr);
|
spin_lock (&proc->lock, &ctxpr);
|
||||||
spin_lock (&sq->lock, &ctxsq);
|
spin_lock (&sq->lock, &ctxsq);
|
||||||
|
|
||||||
|
/* remove from sq's list */
|
||||||
list_remove (sq->proc_list, &sq_entry->sq_link);
|
list_remove (sq->proc_list, &sq_entry->sq_link);
|
||||||
|
|
||||||
|
/* remove from proc's list */
|
||||||
list_remove (proc->sq_entries, &sq_entry->proc_link);
|
list_remove (proc->sq_entries, &sq_entry->proc_link);
|
||||||
|
|
||||||
proc->cpu = cpu;
|
proc->cpu = cpu;
|
||||||
|
|||||||
Reference in New Issue
Block a user