mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 13:48:21 +00:00
add a function that gets called after every system call and make all threads quit on program exit
This commit is contained in:
@@ -380,6 +380,12 @@ __attribute__((noreturn)) int sched_die(){
|
||||
sched_dequeue();
|
||||
}
|
||||
|
||||
void sched_threadexitcheck(){
|
||||
if(arch_getcls()->thread->shouldexit)
|
||||
sched_die();
|
||||
}
|
||||
|
||||
|
||||
void sched_block(bool interruptible){
|
||||
|
||||
thread_t* thread = arch_getcls()->thread;
|
||||
|
||||
+24
-3
@@ -7,17 +7,38 @@
|
||||
#include <arch/interrupt.h>
|
||||
|
||||
void syscall_exit(int status){
|
||||
proc_t* proc = arch_getcls()->thread->proc;
|
||||
|
||||
|
||||
thread_t* thread = arch_getcls()->thread;
|
||||
proc_t* proc = thread->proc;
|
||||
|
||||
|
||||
proc_t* init = sched_getinit();
|
||||
|
||||
if(proc == init)
|
||||
_panic("Init exit", NULL);
|
||||
|
||||
spinlock_acquire(&init->lock);
|
||||
spinlock_acquire(&proc->lock);
|
||||
|
||||
// TODO make all other threads exit
|
||||
while(1){
|
||||
bool ok = true;
|
||||
for(uintmax_t i = 0; i < proc->threadcount; ++i){
|
||||
if(proc->threads[i] == thread)
|
||||
continue;
|
||||
if(thread->state != THREAD_STATE_DEAD)
|
||||
ok = false;
|
||||
proc->threads[i]->shouldexit = true;
|
||||
}
|
||||
|
||||
free(proc->threads);
|
||||
if(ok)
|
||||
break;
|
||||
|
||||
arch_interrupt_disable();
|
||||
sched_yield();
|
||||
arch_interrupt_enable();
|
||||
|
||||
}
|
||||
|
||||
for(uintmax_t fd = 0; fd < proc->fdtable.fdcount; ++ fd)
|
||||
fd_free(&proc->fdtable, fd);
|
||||
|
||||
Reference in New Issue
Block a user