From 1621bb1a9b14f2067bdc0800548a675c0c356c75 Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 3 Jul 2023 22:48:04 -0300 Subject: [PATCH] scheduler: fix threadexit interrupt disable --- kernel-src/sys/scheduler.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel-src/sys/scheduler.c b/kernel-src/sys/scheduler.c index 918d3d2e..e6ae69e4 100644 --- a/kernel-src/sys/scheduler.c +++ b/kernel-src/sys/scheduler.c @@ -196,7 +196,6 @@ __attribute__((noreturn)) void sched_stopcurrentthread() { } __attribute__((noreturn)) void sched_threadexit() { - interrupt_set(false); thread_t *thread = _cpu()->thread; proc_t *proc = thread->proc; @@ -205,10 +204,12 @@ __attribute__((noreturn)) void sched_threadexit() { if (proc) { __atomic_fetch_sub(&proc->runningthreadcount, 1, __ATOMIC_SEQ_CST); + __assert(oldctx != &vmm_kernelctx); if (proc->runningthreadcount == 0) vmm_destroycontext(oldctx); } + interrupt_set(false); _cpu()->thread = NULL; // because a thread deallocating its own data is a nightmare, thread deallocation and such will be left to whoever frees the proc it's tied to @@ -229,6 +230,7 @@ static void yield(context_t *context) { if (next || sleeping) { ARCH_CONTEXT_THREADSAVE(thread, context); + if (sleeping) spinlock_release(&thread->sleeplock); else