From ada2d0d0700b7b49e0455b39980e012630cd4801 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 8 Jun 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-06-08 --- power/dat.h | 3 ++- power/devbit3.c | 61 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/power/dat.h b/power/dat.h index 61b6809a0f143dd3fd9e1139679c0c19c1a6a38c..90a8abc2391c5890b11af82f30134c27c6a768ba 100644 --- a/power/dat.h +++ b/power/dat.h @@ -345,7 +345,8 @@ struct User * I/O point for bit3 interface. This is the easiest way to allocate * them, but not the prettiest or most general. */ - Bit3msg bit3; + Bit3msg kbit3; + Bit3msg ubit3; /* * Rest of structure controlled by devproc.c and friends. * lock(&p->debug) to modify. diff --git a/power/devbit3.c b/power/devbit3.c index f4e7f46d90fef2fa5024e0836de46e95f5fa63b7..6f8fcecd65df6fc5a78964a1270f2d3d5861e66e 100644 --- a/power/devbit3.c +++ b/power/devbit3.c @@ -11,6 +11,7 @@ static struct { QLock; + QLock buflock; int open; char buf[10*1024]; }bit3; @@ -89,7 +90,7 @@ bit3open(Chan *c, int omode) { Bit3msg *bp; - bp = &((User*)(u->p->upage->pa|KZERO))->bit3; + bp = &((User*)(u->p->upage->pa|KZERO))->kbit3; if(c->qid!=1 || omode!=ORDWR) error(0, Eperm); qlock(&bit3); @@ -134,26 +135,40 @@ bit3read(Chan *c, void *buf, long n) Bit3msg *bp; int docpy; - bp = &((User*)(u->p->upage->pa|KZERO))->bit3; - bp->rcount = 0; switch(c->qid){ case 1: if(n > sizeof bit3.buf) error(0, Egreg); - docpy = 0; - qlock(&bit3); - if((((ulong)buf)&(KSEGM|3)) == KSEG0) + if((((ulong)buf)&(KSEGM|3)) == KSEG0){ + /* + * use supplied buffer, no need to lock for reply + */ + bp = &((User*)(u->p->upage->pa|KZERO))->kbit3; + bp->rcount = 0; + qlock(&bit3); bit3send(bp, READ, buf, n); - else{ + qunlock(&bit3); + do + n = bp->rcount; + while(n == 0); + }else{ + /* + * use bit3 buffer. lock the buffer till the reply + */ + bp = &((User*)(u->p->upage->pa|KZERO))->ubit3; + bp->rcount = 0; + qlock(&bit3.buflock); + + qlock(&bit3); bit3send(bp, READ, bit3.buf, n); - docpy = 1; - } - qunlock(&bit3); - do - n = bp->rcount; - while(n == 0); - if(docpy) + qunlock(&bit3); + do + n = bp->rcount; + while(n == 0); memcpy(buf, bit3.buf, n); + + qunlock(&bit3.buflock); + } return n; } error(0, Egreg); @@ -165,19 +180,27 @@ bit3write(Chan *c, void *buf, long n) { Bit3msg *bp; - bp = &((User*)(u->p->upage->pa|KZERO))->bit3; switch(c->qid){ case 1: if(n > sizeof bit3.buf) error(0, Egreg); - qlock(&bit3); - if((((ulong)buf)&(KSEGM|3)) == KSEG0) + if((((ulong)buf)&(KSEGM|3)) == KSEG0){ + bp = &((User*)(u->p->upage->pa|KZERO))->kbit3; + qlock(&bit3); bit3send(bp, WRITE, buf, n); - else{ + qunlock(&bit3); + }else{ + bp = &((User*)(u->p->upage->pa|KZERO))->ubit3; + qlock(&bit3.buflock); + + qlock(&bit3); memcpy(bit3.buf, buf, n); bit3send(bp, WRITE, bit3.buf, n); + do; while(*BIT3ADDR); + qunlock(&bit3); + + qunlock(&bit3.buflock); } - qunlock(&bit3); return n; } error(0, Egreg);