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
+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;