From d5c65a749f43f09f7c33cf7402d9bc2064083588 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 1 Jan 2023 10:37:24 -0300 Subject: [PATCH] scheduler: fix thread array stuff and fix stupid thing --- src/sys/sched/scheduler.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sys/sched/scheduler.c b/src/sys/sched/scheduler.c index a89f1b25..7f543822 100644 --- a/src/sys/sched/scheduler.c +++ b/src/sys/sched/scheduler.c @@ -264,6 +264,8 @@ thread_t* sched_newuthread(void* ip, size_t kstacksize, void* stack, proc_t* pro return NULL; } thread->tid = proc->pid; + proc->threadcount = 1; + proc->threads[0] = thread; } else{ spinlock_acquire(&proc->lock); @@ -273,6 +275,7 @@ thread_t* sched_newuthread(void* ip, size_t kstacksize, void* stack, proc_t* pro return NULL; } proc->threads = tmp; + proc->threads[proc->threadcount] = thread; ++proc->threadcount; spinlock_release(&proc->lock); thread->tid = getnextpid(); @@ -326,7 +329,7 @@ void sched_yieldtrampoline(thread_t* thread){ thread_t* nthread = getnext(); - + timer_resume(); switch_thread(nthread); @@ -368,6 +371,7 @@ void sched_dequeue(long state){ timer_stop(); arch_interrupt_disable(); + thread_t* current = arch_getcls()->thread; thread_t* thread = getnext(); timer_resume(); @@ -378,9 +382,9 @@ void sched_dequeue(long state){ arch_getcls()->thread = thread; vmm_switchcontext(thread->ctx); - thread->state = state; + current->state = state; if(state == THREAD_STATE_DEAD) - spinlock_release(&thread->proc->threadexitlock); + spinlock_release(¤t->proc->threadexitlock); switch_thread(thread);