From db93f44502b69fdf0682f5eb77e0da899d7d4897 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 30 May 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-05-30 --- port/devpipe.c | 10 +++----- port/netif.c | 4 +-- port/portdat.h | 50 -------------------------------------- port/portfns.h | 3 ++- port/qio.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 72 insertions(+), 61 deletions(-) diff --git a/port/devpipe.c b/port/devpipe.c index 38a4d0a46646f039f414f984d35d7b1112c0cfb7..c1f1521c48b3a5a9227676643484ac8d16ed6161 100644 --- a/port/devpipe.c +++ b/port/devpipe.c @@ -65,19 +65,17 @@ pipeattach(char *spec) exhausted("memory"); p->ref = 1; - p->q[0] = qopen(64*1024, 0, 0); + p->q[0] = qopen(64*1024, 0, 0, 0); if(p->q[0] == 0){ free(p); exhausted("memory"); } - p->q[0]->state &= ~Qmsg; - p->q[1] = qopen(32*1024, 0, 0); + p->q[1] = qopen(32*1024, 0, 0, 0); if(p->q[1] == 0){ free(p->q[0]); free(p); exhausted("memory"); } - p->q[1]->state &= ~Qmsg; lock(&pipealloc); p->path = ++pipealloc.path; @@ -139,10 +137,10 @@ pipestat(Chan *c, char *db) devdir(c, c->qid, ".", 2*DIRLEN, eve, CHDIR|0555, &dir); break; case Qdata0: - devdir(c, c->qid, "data", p->q[0]->len, eve, 0660, &dir); + devdir(c, c->qid, "data", qlen(p->q[0]), eve, 0660, &dir); break; case Qdata1: - devdir(c, c->qid, "data1", p->q[1]->len, eve, 0660, &dir); + devdir(c, c->qid, "data1", qlen(p->q[1]), eve, 0660, &dir); break; default: panic("pipestat"); diff --git a/port/netif.c b/port/netif.c index 704ba7a771cc39a02f6fb14871f7bc525e8ab04e..d6afccfa2d26836a3f317cefe6a0e7ca8dc4aae1 100644 --- a/port/netif.c +++ b/port/netif.c @@ -24,7 +24,7 @@ netifinit(Netif *nif, char *name, int nfile, ulong limit) nif->f = xalloc(nfile*sizeof(Netfile*)); memset(nif->f, 0, nfile*sizeof(Netfile*)); nif->limit = limit; - nif->out = qopen(limit, 0, 0); + nif->out = qopen(limit, 1, 0, 0); } /* @@ -339,7 +339,7 @@ openfile(Netif *nif, int id) error(Enodev); } *fp = f; - f->in = qopen(nif->limit, 0, 0); + f->in = qopen(nif->limit, 1, 0, 0); qlock(f); } else { qlock(f); diff --git a/port/portdat.h b/port/portdat.h index 28ffc0742266964f34975ce5e09569bf092664f6..51085e68c9c061d4940496f9580b7f2ccaf0dcef 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -636,56 +636,6 @@ struct Proc PMMU; }; -/* - * IO queues - */ -struct Block -{ - Block *next; - - uchar *rp; /* first unconsumed byte */ - uchar *wp; /* first empty byte */ - uchar *lim; /* 1 past the end of the buffer */ - uchar *base; /* start of the buffer */ - uchar flag; - - Rendez r; /* waiting reader */ -}; -#define BLEN(b) ((b)->wp - (b)->rp) - -struct Queue -{ - Lock; - - Block *bfirst; /* buffer */ - Block *blast; - - int len; /* bytes in queue */ - int limit; /* max bytes in queue */ - int state; - - void (*kick)(void*); /* restart output */ - void *arg; /* argument to kick */ - - QLock rlock; /* mutex for reading processes */ - Rendez rr; /* process waiting to read */ - QLock wlock; /* mutex for writing processes */ - Rendez wr; /* process waiting to write */ -}; - -enum -{ - /* Block.flag */ - Bfilled=1, /* block filled */ - - /* Queue.state */ - Qstarve= (1<<0), /* consumer starved */ - Qmsg= (1<<1), /* message stream */ - Qclosed= (1<<2), - Qflow= (1<<3), -}; - - enum { PRINTSIZE = 256, diff --git a/port/portfns.h b/port/portfns.h index 8a3fc9f314db3bd8d562acfb804d33dfa4d2e9c2..7fd1bb151262286a7dd0d5462c1b61d5fae712ff 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -173,8 +173,9 @@ ulong pwait(Waitmsg*); void qclose(Queue*); int qconsume(Queue*, uchar*, int); void qhangup(Queue*); +int qlen(Queue*); void qlock(QLock*); -Queue* qopen(int, void (*)(void*), void*); +Queue* qopen(int, int, void (*)(void*), void*); int qproduce(Queue*, uchar*, int); long qread(Queue*, char*, int); void qreopen(Queue*); diff --git a/port/qio.c b/port/qio.c index 37318161de1fbde3f3714b1ee159727e8ae43279..119a7528a2d5c0da4deb801304302918185c0391 100644 --- a/port/qio.c +++ b/port/qio.c @@ -5,6 +5,9 @@ #include "fns.h" #include "../port/error.h" +/* + * interrupt level memory allocation + */ typedef struct Chunk Chunk; typedef struct Chunkl Chunkl; typedef struct Arena Arena; @@ -38,6 +41,56 @@ struct Arena static Arena arena; +/* + * IO queues + */ +typedef struct Block Block; +typedef struct Queue Queue; + +struct Block +{ + Block *next; + + uchar *rp; /* first unconsumed byte */ + uchar *wp; /* first empty byte */ + uchar *lim; /* 1 past the end of the buffer */ + uchar *base; /* start of the buffer */ + uchar flag; +}; +#define BLEN(b) ((b)->wp - (b)->rp) + +struct Queue +{ + Lock; + + Block *bfirst; /* buffer */ + Block *blast; + + int len; /* bytes in queue */ + int limit; /* max bytes in queue */ + int state; + + void (*kick)(void*); /* restart output */ + void *arg; /* argument to kick */ + + QLock rlock; /* mutex for reading processes */ + Rendez rr; /* process waiting to read */ + QLock wlock; /* mutex for writing processes */ + Rendez wr; /* process waiting to write */ +}; + +enum +{ + /* Block.flag */ + Bfilled=1, /* block filled */ + + /* Queue.state */ + Qstarve= (1<<0), /* consumer starved */ + Qmsg= (1<<1), /* message stream */ + Qclosed= (1<<2), + Qflow= (1<<3), +}; + /* * Manage interrupt level memory allocation. */ @@ -297,7 +350,7 @@ qproduce(Queue *q, uchar *p, int len) * called by non-interrupt code */ Queue* -qopen(int limit, void (*kick)(void*), void *arg) +qopen(int limit, int msg, void (*kick)(void*), void *arg) { Queue *q; @@ -309,7 +362,7 @@ qopen(int limit, void (*kick)(void*), void *arg) q->limit = limit; q->kick = kick; q->arg = arg; - q->state = Qmsg; + q->state = msg ? Qmsg : 0; return q; } @@ -518,3 +571,12 @@ qreopen(Queue *q) { q->state &= ~Qclosed; } + +/* + * return bytes queued + */ +int +qlen(Queue *q) +{ + return q->len; +}