From 1b82f96703735e4ea4c23476cc484264c679cbff Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 24 Mar 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-03-24 --- pc/devlpt.c | 12 ++++++------ port/portfns.h | 2 +- port/proc.c | 7 ++++++- port/qio.c | 15 ++++++++++----- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pc/devlpt.c b/pc/devlpt.c index ae23bbb3feb2461f87becb41bcd51c8d5d7165b9..e2c2a87537e757d68ae53a4551d46319060f90a6 100644 --- a/pc/devlpt.c +++ b/pc/devlpt.c @@ -10,8 +10,8 @@ /* base addresses */ static int lptbase[] = { - 0x3bc, /* lpt1 */ - 0x378, /* lpt2 (sic) */ + 0x378, /* lpt1 */ + 0x3bc, /* lpt2 */ 0x278 /* lpt3 (sic) */ }; #define NDEV (sizeof lptbase/sizeof lptbase[0]) @@ -41,7 +41,7 @@ enum static int lptready(void*); static void outch(int, int); -static void lptintr(Ureg*); +static void lptintr(Ureg*, void*); static Rendez lptrendez; @@ -89,7 +89,7 @@ lptattach(char *spec) if(!set){ set = 1; - setvec(Parallelvec, lptintr); + setvec(Parallelvec, lptintr, 0); } if(i < 1 || i > NDEV) error(Ebadarg); @@ -217,8 +217,8 @@ lptready(void *base) } static void -lptintr(Ureg *ur) +lptintr(Ureg *ur, void *arg) { - USED(ur); + USED(ur, arg); wakeup(&lptrendez); } diff --git a/port/portfns.h b/port/portfns.h index 9710510f31b11243eec3943f57a3a3e0bfd8a6f9..4168cc760f094ce955848d740ff60f38ef472cf0 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -16,7 +16,7 @@ void buzz(int, int); void cachedel(Image*, ulong); void cachepage(Page*, Image*); void callbacks(void); -void newcallback(void (*)(void)); +int newcallback(void (*)(void)); int cangetc(void*); int canlock(Lock*); int canpage(Proc*); diff --git a/port/proc.c b/port/proc.c index 867fa1b07cfe111bb457949bbc991774fbb022d4..3065d7c7fb7884f7f2b2574f36f19ed8b8b6cee1 100644 --- a/port/proc.c +++ b/port/proc.c @@ -107,12 +107,17 @@ anyready(void) return m->hiq.head != 0 || m->loq.head != 0; } -void +int newcallback(void (*func)(void)) { *m->cbin = func; if(++m->cbin >= m->cbend) m->cbin = m->calls; + + if(m->hiq.head == 0 && m->loq.head == 0) + return 1; + + return 0; } void diff --git a/port/qio.c b/port/qio.c index ffb7a9d688f1743982e7549b42a71f8fb6b1fbed..4a51ec131e53474b2933e5045798673a4cd90dfd 100644 --- a/port/qio.c +++ b/port/qio.c @@ -223,14 +223,14 @@ qpass(Queue *q, Block *b) memmove(q->syncbuf, b->rp, i); q->syncbuf = 0; /* tell reader buffer is full */ len -= i; - if(len <= 0 || (q->state & Qmsg)){ + if(len <= 0 || (q->state & Qmsg)) { iunlock(q); wakeup(&q->rr); freeb(b); return i; } - /* queue anything that's left */ dowakeup = 1; + /* queue anything that's left */ b->rp += i; } @@ -243,6 +243,9 @@ qpass(Queue *q, Block *b) q->len += len; checkb(b, "qpass"); + if(q->len >= q->limit) + q->state |= Qflow; + if(q->state & Qstarve){ q->state &= ~Qstarve; dowakeup = 1; @@ -265,7 +268,6 @@ qproduce(Queue *q, void *vp, int len) int i, dowakeup; uchar *p = vp; -if(debuging) print("qproduce %d\n", len); /* sync with qread */ dowakeup = 0; lock(q); @@ -433,7 +435,7 @@ checkb(b, "qread 1"); q->len -= n; /* if writer flow controlled, restart */ - if((q->state & Qflow) && q->len < q->limit/2){ + if((q->state & Qflow) && q->len < q->limit){ q->state &= ~Qflow; dowakeup = 1; } else @@ -459,8 +461,11 @@ checkb(b, "qread 2"); } /* wakeup flow controlled writers (with a bit of histeresis) */ - if(dowakeup) + if(dowakeup){ + if(q->kick) + (*q->kick)(q->arg); wakeup(&q->wr); + } poperror(); qunlock(&q->rlock);