mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
exit syscall: stop other threads
This commit is contained in:
@@ -69,6 +69,8 @@ typedef struct proc_t {
|
|||||||
vnode_t *root;
|
vnode_t *root;
|
||||||
spinlock_t nodeslock;
|
spinlock_t nodeslock;
|
||||||
semaphore_t waitsem;
|
semaphore_t waitsem;
|
||||||
|
spinlock_t exiting;
|
||||||
|
bool nomorethreads;
|
||||||
} proc_t;
|
} proc_t;
|
||||||
|
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
|
|||||||
@@ -9,12 +9,29 @@ __attribute__((noreturn)) void syscall_exit(context_t *context, int status) {
|
|||||||
thread_t *thread = _cpu()->thread;
|
thread_t *thread = _cpu()->thread;
|
||||||
proc_t *proc = thread->proc;
|
proc_t *proc = thread->proc;
|
||||||
__assert(proc != sched_initproc);
|
__assert(proc != sched_initproc);
|
||||||
|
__assert(spinlock_try(&proc->exiting)); // only one thread can exit at the same time
|
||||||
|
|
||||||
// TODO stop other threads
|
// stop other threads
|
||||||
|
spinlock_acquire(&proc->lock);
|
||||||
|
proc->nomorethreads = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < proc->threadtablesize; ++i) {
|
||||||
|
if (proc->threads[i] == NULL || proc->threads[i] == thread)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
proc->threads[i]->shouldexit = true;
|
||||||
|
sched_wakeup(proc->threads[i], SCHED_WAKEUP_REASON_INTERRUPTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
spinlock_release(&proc->lock);
|
||||||
|
|
||||||
|
while (__atomic_load_n(&proc->runningthreadcount, __ATOMIC_SEQ_CST) > 1) sched_yield();
|
||||||
|
|
||||||
|
// close fds
|
||||||
for (int fd = 0; fd < proc->fdcount; ++fd)
|
for (int fd = 0; fd < proc->fdcount; ++fd)
|
||||||
fd_close(fd);
|
fd_close(fd);
|
||||||
|
|
||||||
|
// zombify the proc
|
||||||
spinlock_acquire(&proc->lock);
|
spinlock_acquire(&proc->lock);
|
||||||
|
|
||||||
VOP_RELEASE(proc->root);
|
VOP_RELEASE(proc->root);
|
||||||
|
|||||||
Reference in New Issue
Block a user