scheduler: sched_stopotherthreads()

This commit is contained in:
Matheus
2024-04-14 13:21:54 -03:00
parent d3b17b90b9
commit d33ef16f87
4 changed files with 26 additions and 16 deletions
+1
View File
@@ -80,6 +80,7 @@ typedef struct proc_t {
extern proc_t *sched_initproc;
void sched_init();
void sched_stopotherthreads();
void sched_runinit();
__attribute__((noreturn)) void sched_threadexit();
void sched_queue(thread_t *thread);
+21
View File
@@ -253,6 +253,27 @@ __attribute__((noreturn)) void sched_threadexit() {
sched_stopcurrentthread();
}
void sched_stopotherthreads() {
thread_t *thread = _cpu()->thread;
proc_t *proc = thread->proc;
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();
proc->nomorethreads = false;
}
static void yield(context_t *context) {
thread_t *thread = _cpu()->thread;
+3 -1
View File
@@ -115,7 +115,9 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
ret.ret = 0;
// TODO kill other threads and close CLOEXEC fds
// close CLOEXEC fds
sched_stopotherthreads();
error:
free(path);
+1 -15
View File
@@ -11,21 +11,7 @@ __attribute__((noreturn)) void syscall_exit(context_t *context, int status) {
__assert(proc != sched_initproc);
__assert(spinlock_try(&proc->exiting)); // only one thread can exit at the same time
// 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();
sched_stopotherthreads();
// close fds
for (int fd = 0; fd < proc->fdcount; ++fd)