From 6c0be7940e814ea5fe5044474ec683d5cb069fa3 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 24 Nov 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-11-24 --- pc/ether509.c | 8 ++--- port/devcons.c | 24 +++++-------- port/devmnt.c | 2 +- port/portdat.h | 2 +- port/portfns.h | 1 + port/qio.c | 92 +++++++++++++++++++++++++++++++++++++++++++++----- 6 files changed, 99 insertions(+), 30 deletions(-) diff --git a/pc/ether509.c b/pc/ether509.c index e4071c0b42782a8362b2e40f5bfafcc99f4e99fa..c3c369793b54101b7bd3f03431de6197ca4e7245 100644 --- a/pc/ether509.c +++ b/pc/ether509.c @@ -56,11 +56,11 @@ enum { Rst = 0x04, /* Reset Adapter */ Ena = 0x01, /* Enable Adapter */ - TxFreeBytes = 0x0C, /* window 1 */ - TxStatus = 0x0B, - Timer = 0x0A, + Fifo = 0x00, /* window 1 */ RxStatus = 0x08, - Fifo = 0x00, + Timer = 0x0A, + TxStatus = 0x0B, + TxFreeBytes = 0x0C, /* Status/Interrupt Bits */ Latch = 0x0001, /* Interrupt Latch */ diff --git a/port/devcons.c b/port/devcons.c index 5ea6ba784a09ee43a888ba2c0b1a0bb7f4e6262b..1294b0f4178542c2f8cde8397b30e8c7e0cdc292 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -48,7 +48,7 @@ printinit(void) static void putstrn0(char *str, int n, int usewrite) { - int m, x; + int m; char *t; char buf[PRINTSIZE+2]; @@ -76,21 +76,15 @@ putstrn0(char *str, int n, int usewrite) buf[m+1] = '\n'; if(usewrite) qwrite(printq, buf, m+2); - else { - x = splhi(); - qproduce(printq, buf, m+2); - splx(x); - } + else + qiwrite(printq, buf, m+2); str = t + 1; n -= m + 1; } else { if(usewrite) qwrite(printq, str, n); - else { - x = splhi(); - qproduce(printq, str, n); - splx(x); - } + else + qiwrite(printq, str, n); break; } } @@ -247,14 +241,14 @@ echo(Rune r, char *buf, int n) */ if(r == '\n'){ if(printq) - qproduce(printq, "\r", 1); + qiwrite(printq, "\r", 1); } else if(r == 0x15){ buf = "^U\n"; n = 3; } screenputs(buf, n); if(printq) - qproduce(printq, buf, n); + qiwrite(printq, buf, n); } /* @@ -518,9 +512,7 @@ consread(Chan *c, void *buf, long n, ulong offset) qread(kbdq, &kbd.line[kbd.x], 1); ch = kbd.line[kbd.x]; if(kbd.raw){ - i = splhi(); - qproduce(lineq, &kbd.line[kbd.x], 1); - splx(i); + qiwrite(lineq, &kbd.line[kbd.x], 1); continue; } eol = 0; diff --git a/port/devmnt.c b/port/devmnt.c index f3b1882d5f909534e4799540233b1b1c21aae2cf..305617f49e2b47e9b2c8af58a6e2711b4271802e 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -27,7 +27,7 @@ struct Mntalloc Mnt *list; /* Mount devices in use */ Mnt *mntfree; /* Free list */ Mntrpc *rpcfree; - int id; + ulong id; int rpctag; }mntalloc; diff --git a/port/portdat.h b/port/portdat.h index d1f953ed0087843e2311bac2bcd47ef9d880f6e1..f7ba3f2af15a60e19276ed7708532161fcbbfe19 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -143,7 +143,7 @@ struct Chan Chan* link; ulong offset; /* in file */ ushort type; - ushort dev; + ulong dev; ushort mode; /* read/write */ ushort flag; Qid qid; diff --git a/port/portfns.h b/port/portfns.h index 1d34a73a5f0dfd2dd8f190620be91d8eb5f97192..41a76c8f1124985536f82e5b7f5057a2738f4b2e 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -204,6 +204,7 @@ long qread(Queue*, void*, int); void qreopen(Queue*); void qunlock(QLock*); int qwindow(Queue*); +long qiwrite(Queue*, void*, int); long qwrite(Queue*, void*, int); void qsetlimit(Queue*, int); void qnoblock(Queue*, int); diff --git a/port/qio.c b/port/qio.c index ed429629bde0cb0c2cbe1b48c1eee76563e1b272..7d8af518208df91c2226ca311a0250f00416712f 100644 --- a/port/qio.c +++ b/port/qio.c @@ -170,15 +170,22 @@ qconsume(Queue *q, void *vp, int len) /* sync with qwrite */ lock(q); - b = q->bfirst; - if(b == 0){ - q->state |= Qstarve; - unlock(q); - return -1; - } - QDEBUG checkb(b, "qconsume 1"); + for(;;) { + b = q->bfirst; + if(b == 0){ + q->state |= Qstarve; + unlock(q); + return -1; + } + QDEBUG checkb(b, "qconsume 1"); + + n = BLEN(b); + if(n > 0) + break; + q->bfirst = b->next; + freeb(b); + }; - n = BLEN(b); if(n < len) len = n; memmove(p, b->rp, len); @@ -605,6 +612,69 @@ qwrite(Queue *q, void *vp, int len) return len; } +/* + * used by print() to write to a queue + */ +int +qiwrite(Queue *q, void *vp, int len) +{ + int n, sofar, dowakeup; + Block *b; + uchar *p = vp; + + dowakeup = 0; + + sofar = 0; + do { + n = len-sofar; + if(n > 128*1024) + n = 128*1024; + + b = allocb(n); + memmove(b->wp, p+sofar, n); + b->wp += n; + + ilock(q); + + QDEBUG checkb(b, "qiwrite"); + if(q->syncbuf){ + /* we guessed wrong and did an extra copy */ + if(n > q->synclen) + n = q->synclen; + memmove(q->syncbuf, b->rp, n); + q->synclen = n; + q->syncbuf = 0; + dowakeup = 1; + freeb(b); + } else { + /* we guessed right, queue it */ + if(q->bfirst) + q->blast->next = b; + else + q->bfirst = b; + q->blast = b; + q->len += n; + + if(q->state & Qstarve){ + q->state &= ~Qstarve; + dowakeup = 1; + } + } + + iunlock(q); + + if(dowakeup){ + if(q->kick) + (*q->kick)(q->arg); + wakeup(&q->rr); + } + + sofar += n; + } while(sofar < len && (q->state & Qmsg) == 0); + + return len; +} + /* * Mark a queue as closed. No further IO is permitted. * All blocks are released. @@ -739,3 +809,9 @@ qflush(Queue *q) /* wake up readers/writers */ wakeup(&q->wr); } + +int +qstate(Queue *q) +{ + return q->state; +}