commit 237dade319fdee4a8675109948a577aebfdcc627
parent 4387497cba74b53fc5dd3858d985327d0e8a8a94
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date: Tue, 22 Nov 2022 09:34:06 +0100
os9: Move Chan and Space functions to dev.c
They are better suitable there instead of proc. We also do
some small style changes.
Diffstat:
3 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -329,8 +329,10 @@ extern int devread(Chan *c, void *buf, int n);
extern int devclose(Chan *c);
extern int mount(char *, char *, char *);
extern int bind(char *, char *);
-
-/* sched.c */
+extern Nspace *newspace(Nspace *);
+extern Fdset *newfds(Fdset *);
+extern void delspace(Nspace *);
+extern void delfds(Fdset *);
/* globals */
extern Chan *console;
diff --git a/src/os9/dev/dev.c b/src/os9/dev/dev.c
@@ -49,6 +49,50 @@ newchan(unsigned char type)
return c;
}
+Nspace *
+newspace(Nspace *from)
+{
+ Nspace *ns;
+
+ if ((ns = allocspace()) == NULL)
+ return NULL;
+
+ *ns = (from) ? *from : (Nspace) {0};
+ initref(&ns->ref);
+
+ return ns;
+}
+
+Fdset *
+newfds(Fdset *from)
+{
+ Fdset *fds;
+
+ if ((fds = allocfds()) == NULL)
+ return NULL;
+
+ *fds = (from) ? *from : (Fdset) {0};
+ initref(&fds->ref);
+
+ return fds;
+}
+
+void
+delspace(Nspace *ns)
+{
+ if (!decref(&ns->ref))
+ return;
+ freespace(ns);
+}
+
+void
+delfds(Fdset *fds)
+{
+ if (!decref(&fds->ref))
+ return;
+ freefds(fds);
+}
+
void
delchan(Chan *c)
{
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -157,50 +157,6 @@ err:
return NULL;
}
-static Nspace *
-newspace(Nspace *from)
-{
- Nspace *ns;
-
- if ((ns = allocspace()) == NULL)
- return NULL;
-
- *ns = (from) ? *from : (Nspace) {0};
- initref(&ns->ref);
-
- return ns;
-}
-
-static Fdset *
-newfds(Fdset *from)
-{
- Fdset *fds;
-
- if ((fds = allocfds()) == NULL)
- return NULL;
-
- *fds = (from) ? *from : (Fdset) {0};
- initref(&fds->ref);
-
- return fds;
-}
-
-static void
-delspace(Nspace *ns)
-{
- if (!decref(&ns->ref))
- return;
- freespace(ns);
-}
-
-static void
-delfds(Fdset *fds)
-{
- if (!decref(&fds->ref))
- return;
- freefds(fds);
-}
-
/*
* tp must be blocked when this function is called
*/
@@ -249,19 +205,19 @@ clone(Task *parent)
tp->text = parent->text;
if (tp->text)
- incref(&parent->text->ref);
+ incref(&tp->text->ref);
tp->data = parent->data;
if (tp->data)
- incref(&parent->data->ref);
+ incref(&tp->data->ref);
tp->ns = parent->ns;
if (tp->ns)
- incref(&parent->ns->ref);
+ incref(&tp->ns->ref);
tp->fds = parent->fds;
if (tp->fds)
- incref(&parent->fds->ref);
+ incref(&tp->fds->ref);
return tp;