commit 2530b27878b32447a48cd62f914762f3400521c6
parent c32c2be34af08d1916382f329931866548e5cded
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 25 Oct 2020 18:48:42 +0100
os9: Move definition of struct mpoint to os9.h
This structure is going to be used in the driver part and
in the proc part, and for that reason is much better if
it is in the common header.
Change-Id: Ib5bccd11d660c1183a78977a83e801b8d07ef989
Diffstat:
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/include/os9/os9.h b/include/os9/os9.h
@@ -17,6 +17,9 @@
#define NR_TASKS 16
#define NR_WINS 32
+#define NR_MPOINTS 4
+#define NR_CHANS 20
+
#define NR_BUFFERS 512
#define HEAPSIZ (4 * PAGESIZE)
@@ -141,6 +144,12 @@ struct chan {
mutex_t mutex;
};
+struct mpoint {
+ Chan *new;
+ Chan *old;
+ mutex_t m;
+};
+
struct task {
int tid;
int pid;
diff --git a/src/os9/dev/dev.c b/src/os9/dev/dev.c
@@ -8,10 +8,8 @@
#include "dev.h"
-#define NR_MPOINTS 4
-
/*
- * Lock policy:
+ * Lock policy: TODO: Change the lock policy because it generates problems
* The channels are locked when accessed from the raw fdset array, which is
* currently done by newchan() and fd2chan().
* The channels are propagated through the functions in a locked state.
@@ -21,12 +19,6 @@
* The use of mutexes is then transparent for the drivers.
*/
-struct mpoint {
- Chan *new;
- Chan *old;
- mutex_t mutex;
-};
-
static Chan fdset[NR_CHANS];
static Chan slash;
static struct mpoint mpoints[NR_MPOINTS];
@@ -178,16 +170,16 @@ mntpoint(int type, Qid qid)
struct mpoint *mp;
for (mp = mpoints; mp < &mpoints[NR_MPOINTS]; mp++) {
- lock(&mp->mutex);
+ lock(&mp->m);
if ((cn = mp->new) == NULL) {
- unlock(&mp->mutex);
+ unlock(&mp->m);
continue;
}
if (cn->type == type && sameqid(cn->qid, qid)) {
- unlock(&mp->mutex);
+ unlock(&mp->m);
return mp->old;
}
- unlock(&mp->mutex);
+ unlock(&mp->m);
}
return NULL;
@@ -665,10 +657,10 @@ addmntpoint(Chan *c, char *new)
for (i = NR_MPOINTS-1; i >= 0; i--) {
mp = &mpoints[i];
- lock(&mp->mutex);
+ lock(&mp->m);
if (!mp->new)
break;
- unlock(&mp->mutex);
+ unlock(&mp->m);
}
if (i < 0) {
@@ -678,7 +670,7 @@ addmntpoint(Chan *c, char *new)
mp->new = cn;
mp->old = c;
- unlock(&mp->mutex);
+ unlock(&mp->m);
return 0;