From b57154864d9fe20bfac1269630e57a30736288ae Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 30 Sep 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-09-30 --- gnot/stream.c | 5 +++- gnot/sturp.c | 4 +-- port/stream.c | 81 +++++++++++++++++++++++++-------------------------- port/sturp.c | 4 +-- power/devhs.c | 2 +- 5 files changed, 49 insertions(+), 47 deletions(-) diff --git a/gnot/stream.c b/gnot/stream.c index 62c9881daa2911c7558684ea3a3cdee8d4f3177d..a9f2201b21d78ea6ebfe254b970671167fa8c429 100644 --- a/gnot/stream.c +++ b/gnot/stream.c @@ -905,7 +905,10 @@ streamctlread(Chan *c, void *vbuf, long n) static int isinput(void *x) { - return ((Queue *)x)->first != 0; + Queue *q; + + q = (Queue *)x; + return (q->flag&QHUNGUP) || q->first!=0; } /* diff --git a/gnot/sturp.c b/gnot/sturp.c index f2195a5e2eec616f0d096d707ede19c6ee976f88..1e63142c1f38fd7108f750161ac027ac2e45fc14 100644 --- a/gnot/sturp.c +++ b/gnot/sturp.c @@ -653,7 +653,7 @@ output(Urp *up) */ up->rexmit = 0; up->next = up->unacked; - } else if(up->unacked!=up->next && NOW>up->timer){ + } else if(up->unechoed!=up->next && NOW>up->timer){ /* * if a retransmit time has elapsed since a transmit, * send an ENQ @@ -944,7 +944,7 @@ todo(void *arg) return (up->state&INITING) ? NOW>up->timer /* time to INIT1 */ - : ((up->unacked!=up->next && NOW>up->timer) /* time to ENQ */ + : ((up->unechoed!=up->next && NOW>up->timer) /* time to ENQ */ || WINDOW(up)>0 && up->next!=up->nxb || (!QFULL(up->rq->next) && up->iseq!=(up->lastecho&7))); /* time to ECHO */ } diff --git a/port/stream.c b/port/stream.c index de54d797bd5a2aea28479bd84dce507384215220..a9f2201b21d78ea6ebfe254b970671167fa8c429 100644 --- a/port/stream.c +++ b/port/stream.c @@ -127,7 +127,7 @@ allocb(ulong size) ; /* - * look for a free block, garbage collect if there are none + * look for a free block */ lock(bcp); while(bcp->first == 0){ @@ -877,13 +877,38 @@ stringread(Chan *c, uchar *buf, long n, char *str) return n; } +/* + * return the stream id + */ +long +streamctlread(Chan *c, void *vbuf, long n) +{ + uchar *buf = vbuf; + char num[32]; + Stream *s; + + s = c->stream; + if(STREAMTYPE(c->qid) == Sctlqid){ + sprint(num, "%d", s->id); + return stringread(c, buf, n, num); + } else { + if(CHDIR & c->qid) + return devdirread(c, vbuf, n, 0, 0, streamgen); + else + panic("streamctlread"); + } +} + /* * return true if there is an output buffer available */ static int isinput(void *x) { - return ((Queue *)x)->first != 0; + Queue *q; + + q = (Queue *)x; + return (q->flag&QHUNGUP) || q->first!=0; } /* @@ -895,28 +920,16 @@ streamread(Chan *c, void *vbuf, long n) Block *bp; Stream *s; Queue *q; - long rv = 0; - int left, i, x; + int left, i; uchar *buf = vbuf; - char num[32]; - s = c->stream; - switch(STREAMTYPE(c->qid)){ - case Sdataqid: - break; - case Sctlqid: - sprint(num, "%d", s->id); - return stringread(c, buf, n, num); - default: - if(CHDIR & c->qid) - return devdirread(c, vbuf, n, 0, 0, streamgen); - else - panic("streamread"); - } + if(STREAMTYPE(c->qid) != Sdataqid) + return streamctlread(c, vbuf, n); /* * one reader at a time */ + s = c->stream; qlock(&s->rdlock); if(waserror()){ qunlock(&s->rdlock); @@ -974,10 +987,15 @@ streamread(Chan *c, void *vbuf, long n) * This routing is entrered with s->wrlock'ed and must unlock. */ static long -streamctlwrite(Stream *s, void *a, long n) +streamctlwrite(Chan *c, void *a, long n) { Qinfo *qi; Block *bp; + Stream *s; + + if(STREAMTYPE(c->qid) != Sctlqid) + panic("streamctlwrite %lux", c->qid); + s = c->stream; /* * package @@ -1037,27 +1055,11 @@ streamwrite(Chan *c, void *a, long n, int docopy) s = c->stream; - /* - * one writer at a time - qlock(&s->wrlock); - if(waserror()){ - qunlock(&s->wrlock); - nexterror(); - } - */ - /* * decode the qid */ - switch(STREAMTYPE(c->qid)){ - case Sdataqid: - break; - case Sctlqid: - n = streamctlwrite(s, a, n); - goto out; - default: - panic("bad stream qid\n"); - } + if(STREAMTYPE(c->qid) != Sdataqid) + return streamctlwrite(c, a, n); /* * No writes allowed on hungup channels @@ -1066,7 +1068,7 @@ streamwrite(Chan *c, void *a, long n, int docopy) if(q->other->flag & QHUNGUP) error(0, Ehungup); - if((GLOBAL(a) && !docopy) || n==0){ + if(!docopy && GLOBAL(a)){ /* * `a' is global to the whole system, just create a * pointer to it and pass it on. @@ -1103,9 +1105,6 @@ streamwrite(Chan *c, void *a, long n, int docopy) } } } -out: -/* qunlock(&s->wrlock); - poperror(); /**/ return n; } diff --git a/port/sturp.c b/port/sturp.c index 5261b0b9c0ba884c838f35810d4e60912f5df860..806825ae4a491e7dacf47bf1de5da37620153ffd 100644 --- a/port/sturp.c +++ b/port/sturp.c @@ -653,7 +653,7 @@ output(Urp *up) */ up->rexmit = 0; up->next = up->unacked; - } else if(up->unacked!=up->next && NOW>up->timer){ + } else if(up->unechoed!=up->next && NOW>up->timer){ /* * if a retransmit time has elapsed since a transmit, * send an ENQ @@ -944,7 +944,7 @@ todo(void *arg) return (up->state&INITING) ? NOW>up->timer /* time to INIT1 */ - : ((up->unacked!=up->next && NOW>up->timer) /* time to ENQ */ + : ((up->unechoed!=up->next && NOW>up->timer) /* time to ENQ */ || WINDOW(up)>0 && up->next!=up->nxb || (!QFULL(up->rq->next) && up->iseq!=(up->lastecho&7))); /* time to ECHO */ } diff --git a/power/devhs.c b/power/devhs.c index 8afdae8339da1d663cfcd8f1833a1dc8f43503c0..3f322aed9c48712190bfc20ce259ba02726dac58 100644 --- a/power/devhs.c +++ b/power/devhs.c @@ -554,6 +554,6 @@ hsvmeintr(int vec) hp->parity++; hsvmerestart(hp); print("hsvme %d: reset, csr = 0x%ux\n", - HSVME, csr); + vec - Vmevec, csr); } }