commit 435ac77bd3b15f28e5f7f511e77de3eecf368a77
parent e19076abd5ed5c07456e07bc181692588ed862a6
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date: Thu, 17 Nov 2022 06:46:07 +0100
os9: Call newtask from kproc()
It makes pid and ppid creation centralized in newtask().
Diffstat:
3 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -84,7 +84,7 @@ enum tflags {
};
enum tmode {
- TDORMANT,
+ TINIT,
TREADY,
TRUNNING,
TWAITING,
diff --git a/src/os9/dev/devproc.c b/src/os9/dev/devproc.c
@@ -124,7 +124,7 @@ taskstatusread(Chan *c, void *buf, int n)
Task *tp;
char tmp[1024];
static char *states[] = {
- [TDORMANT] = "dormant",
+ [TINIT] = "init",
[TREADY] = "ready",
[TRUNNING] = "running",
[TWAITING] = "waiting",
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -43,7 +43,6 @@ iproc(void)
if ((tp = kproc(initfn)) == NULL)
panic("init task failed");
- tp->affinity = -1;
proc = tp;
unlock(&proc->m);
}
@@ -185,7 +184,7 @@ newslot(void)
for (tp = tasktab; tp < &tasktab[NR_TASKS]; tp++) {
lock(&tp->m);
if (tp->state == TFREE) {
- tp->state = TWAITING;
+ tp->state = TINIT;
break;
}
unlock(&tp->m);
@@ -216,7 +215,7 @@ newtask(void)
for (;;) {
if (pid == MAXTID)
- pid = -1;
+ pid = 0;
pid++;
if (pid == last)
goto err;
@@ -230,6 +229,8 @@ newtask(void)
last = pid;
tp->pid = pid;
+ tp->ppid = (proc) ? proc->pid : 0;
+
unlock(&m);
return tp;
@@ -433,7 +434,7 @@ kproc(void *fn)
{
Task *tp;
- if ((tp = newslot()) == NULL)
+ if ((tp = newtask()) == NULL)
return NULL;
tp->text = NULL;
@@ -441,9 +442,6 @@ kproc(void *fn)
tp->fds = NULL;
tp->ns = NULL;
- tp->pid = 1;
- tp->ppid = -1;
-
tp->entry = fn;
tp->prio = 0;
@@ -452,7 +450,7 @@ kproc(void *fn)
tp->wait = 0;
tp->locklevel = 0;
- tp->affinity = 0;
+ tp->affinity = -1;
tp->period = 0;
tp->duration = 0;