From 2a5fdd86f50e0bea514572c708f2a341b1f36038 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 31 Dec 2022 18:16:52 -0300 Subject: [PATCH] scheduler: getnextpid() and fix tid not being assigned properly to new threads --- src/sys/sched/scheduler.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sys/sched/scheduler.c b/src/sys/sched/scheduler.c index fd43b45e..f100897f 100644 --- a/src/sys/sched/scheduler.c +++ b/src/sys/sched/scheduler.c @@ -30,6 +30,13 @@ proc_t* sched_getinit(){ return init; } +static int getnextpid(){ + spinlock_acquire(&pidlock); + int pid = nextpid++; + spinlock_release(&pidlock); + return pid; +} + static proc_t* allocproc(size_t threadcount){ proc_t* proc = alloc(sizeof(proc_t)); @@ -49,9 +56,7 @@ static proc_t* allocproc(size_t threadcount){ return NULL; } - spinlock_acquire(&pidlock); - proc->pid = nextpid++; - spinlock_release(&pidlock); + proc->pid = getnextpid(); return proc; @@ -258,6 +263,7 @@ thread_t* sched_newuthread(void* ip, size_t kstacksize, void* stack, proc_t* pro freethread(thread); return NULL; } + thread->tid = proc->pid; } else{ spinlock_acquire(&proc->lock); @@ -269,7 +275,9 @@ thread_t* sched_newuthread(void* ip, size_t kstacksize, void* stack, proc_t* pro proc->threads = tmp; ++proc->threadcount; spinlock_release(&proc->lock); + thread->tid = getnextpid(); } + thread->priority = prio; thread->proc = proc;