mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
scheduler: getnextpid() and fix tid not being assigned properly to new threads
This commit is contained in:
@@ -30,6 +30,13 @@ proc_t* sched_getinit(){
|
|||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getnextpid(){
|
||||||
|
spinlock_acquire(&pidlock);
|
||||||
|
int pid = nextpid++;
|
||||||
|
spinlock_release(&pidlock);
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
static proc_t* allocproc(size_t threadcount){
|
static proc_t* allocproc(size_t threadcount){
|
||||||
|
|
||||||
proc_t* proc = alloc(sizeof(proc_t));
|
proc_t* proc = alloc(sizeof(proc_t));
|
||||||
@@ -49,9 +56,7 @@ static proc_t* allocproc(size_t threadcount){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_acquire(&pidlock);
|
proc->pid = getnextpid();
|
||||||
proc->pid = nextpid++;
|
|
||||||
spinlock_release(&pidlock);
|
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
|
|
||||||
@@ -258,6 +263,7 @@ thread_t* sched_newuthread(void* ip, size_t kstacksize, void* stack, proc_t* pro
|
|||||||
freethread(thread);
|
freethread(thread);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
thread->tid = proc->pid;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
spinlock_acquire(&proc->lock);
|
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->threads = tmp;
|
||||||
++proc->threadcount;
|
++proc->threadcount;
|
||||||
spinlock_release(&proc->lock);
|
spinlock_release(&proc->lock);
|
||||||
|
thread->tid = getnextpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
thread->priority = prio;
|
thread->priority = prio;
|
||||||
thread->proc = proc;
|
thread->proc = proc;
|
||||||
|
|||||||
Reference in New Issue
Block a user