commit 238c5c1f53f81a6b2e757d0f3069365ee8328bca
parent 46a8768402960588017625417bc9451ed0d6ed57
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 25 Oct 2020 22:09:06 +0100
os9/proc: Add initial version of proc.c
Change-Id: Ia3b98b2d31eb7d19f47642fc4ea7c37f41dfb6df
Diffstat:
4 files changed, 94 insertions(+), 68 deletions(-)
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -44,6 +44,9 @@ typedef struct qid Qid;
typedef struct dir Dir;
typedef struct mach Mach;
typedef struct map Map;
+typedef struct namespace Namespace;
+typedef struct fdset Fdset;
+typedef struct ref Ref;
enum barrier_type {
CODE,
@@ -64,11 +67,11 @@ enum pstates {
};
enum pmodes {
- PDISABLED,
- PCOLD_START,
- PWARM_START,
- PIDLE,
- PNORMAL,
+ PDISABLED = 'D',
+ PCOLD_START = 'C',
+ PWARM_START = 'W',
+ PIDLE = 'I',
+ PNORMAL = 'N',
};
enum tflags {
@@ -141,6 +144,11 @@ struct chan {
mutex_t mutex;
};
+struct ref {
+ mutex_t m;
+ int cnt;
+};
+
struct mpoint {
Chan *new;
Chan *old;
@@ -172,19 +180,21 @@ struct task {
int state;
int flags;
- int mode;
+ char mode;
int start;
mutex_t m;
+ Context ctx;
/* communication ports */
/* healt monitor table */
/* Task *errhdl; */
- Map text;
- Map data;
- Map stack;
- Context ctx;
+ Map *text;
+ Map *data;
+ Map *stack;
+ Namespace *ns;
+ Fdset *fds;
};
struct win {
diff --git a/src/os9/Makefile b/src/os9/Makefile
@@ -3,10 +3,11 @@ PROJECTDIR=../..
include $(PROJECTDIR)/scripts/rules.mk
OBJS =\
- dlang.o\
- sched.o\
alloc.o\
+ dlang.o\
init.o\
+ proc.o\
+ sched.o\
dev/builtin.o\
DIRS =\
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -0,0 +1,71 @@
+#include <os9/os9.h>
+
+#include <limits.h>
+
+static Task tasktab[NR_TASKS];
+
+static void
+incref(Ref *rp)
+{
+ lock(&rp->m);
+ rp->cnt++;
+ unlock(&rp->m);
+}
+
+static void
+decref(Ref *rp)
+{
+ lock(&rp->m);
+ rp->cnt--;
+ unlock(&rp->m);
+}
+
+int
+getntask(int n, Task **tpp)
+{
+ Task *tp;
+
+ if (n >= NR_TASKS)
+ return -1;
+ tp = &tasktab[n];
+
+ if (tp->mode == PDISABLED)
+ return 0;
+
+ *tpp = tp;
+ return 1;
+}
+
+Task *
+gettask(int tid)
+{
+ Task *tp;
+
+ for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) {
+ if (tp->mode != PDISABLED && tp->tid == tid)
+ break;
+ }
+
+ return (tp != &tasktab[NR_TASKS]) ? tp : NULL;
+}
+
+static int
+newtid(void)
+{
+ int tid, id;
+ static int last;
+
+ id = tid = last;
+
+ do {
+ if (tid == INT_MAX)
+ tid = -1;
+ tid++;
+ if (gettask(tid) == NULL)
+ break;
+ } while (tid != last);
+
+ last = tid;
+
+ return (tid != id) ? tid : -1;
+}
diff --git a/src/os9/sched.c b/src/os9/sched.c
@@ -2,7 +2,6 @@
#include <errno.h>
-static Task tasktab[NR_TASKS];
static Win wintab[NR_WINS];
/* per cpu globals */
@@ -10,62 +9,7 @@ Task *task;
long long now;
int cpuid;
-int
-getntask(int n, Task **tpp)
-{
- Task *tp;
-
- if (n >= NR_TASKS)
- return -1;
- tp = &tasktab[n];
-
- if (tp->mode == PDISABLED)
- return 0;
-
- *tpp = tp;
- return 1;
-}
-
-Task *
-gettask(int tid)
-{
- Task *tp;
-
- for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) {
- if (tp->mode != PDISABLED && tp->tid == tid)
- return tp;
- }
-
- return NULL;
-}
-
#if 0
-
-enum rforkflags {
- RFPROC = 1 << 0,
-};
-
-int
-rfork(int flags)
-{
- Proc *p = proc;
-
- if ((flags & RFPROC) == 0) {
- p = proc;
- } else {
- for (p = tasktab; p < &tasktab[NR_PROCS]; ++p) {
- if (p->mode == PDISABLED)
- break;
- }
-
- if (p == &tasktab[NR_PROCS]) {
- errno = ENOMEM;
- return -1;
- }
- }
-}
-
-
void
sched(void)
{