From 95978c0451f06a83f4a6802cbbac7d005da06e3a Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 17 Jul 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-07-17 --- gnot/dat.h | 1 + gnot/devdk.c | 2 +- gnot/devmnt.c | 11 ++++++++++- gnot/fns.h | 1 + gnot/main.c | 1 + gnot/sturp.c | 21 ++++++++++++++++----- port/devdk.c | 2 +- port/devmnt.c | 30 +++++++++++++++++++++++++++++- port/sturp.c | 21 ++++++++++++++++----- power/conf.h | 1 + power/dat.h | 1 + power/fns.h | 1 + 12 files changed, 79 insertions(+), 14 deletions(-) diff --git a/gnot/dat.h b/gnot/dat.h index ee0116431d44f417826927cb83080b8c5259962a..6d3d915d8a8772e0ddad34304b2dd95bde1e198f 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -138,6 +138,7 @@ struct Conf int nbitmap; /* bitmap structs (devbit.c) */ int nbitbyte; /* bytes of bitmap data (devbit.c) */ int nfont; /* font structs (devbit.c) */ + int nurp; /* max urp conversations */ }; struct Dev diff --git a/gnot/devdk.c b/gnot/devdk.c index cbd68b42e9238d7a74e9b34a7e516bb9b6393d8c..88599861ed9b0178e491ba31402c32f01b3732c7 100644 --- a/gnot/devdk.c +++ b/gnot/devdk.c @@ -551,7 +551,7 @@ void dkreset(void) { newqinfo(&dkmuxinfo); - newqinfo(&urpinfo); + urpreset(); } /* diff --git a/gnot/devmnt.c b/gnot/devmnt.c index 7ed1cd338f930f188222d250716e8c3733298dc5..c96f567a91dad05afe95d1d46a88913cf1dd2b3c 100644 --- a/gnot/devmnt.c +++ b/gnot/devmnt.c @@ -54,6 +54,7 @@ struct Mnthdr Rendez r; Proc *p; Mntbuf *mbr; + int readreply; /* true if we are reader or our reply has come */ }; struct @@ -670,6 +671,11 @@ mnterrdequeue(MntQ *q, Mnthdr *mh) /* queue is unlocked */ qunlock(q); } +int +mntreadreply(void *a) +{ + return ((Mnthdr *)a)->readreply; +} void mntxmit(Mnt *m, Mnthdr *mh) { @@ -760,6 +766,7 @@ mntxmit(Mnt *m, Mnthdr *mh) mqfree(q); nexterror(); } + mh->readreply = 0; if((*devtab[q->msg->type].write)(q->msg, mbw->buf, n) != n){ print("short write in mntxmit\n"); error(0, Eshortmsg); @@ -790,6 +797,7 @@ mntxmit(Mnt *m, Mnthdr *mh) if(w = q->writer){ /* advance a writer to reader */ q->reader = w->p; q->writer = w->next; + w->readreply = 1; wakeup(&w->r); } qunlock(q); @@ -812,6 +820,7 @@ mntxmit(Mnt *m, Mnthdr *mh) q->writer = w->next; else ow->next = w->next; + w->readreply = 1; wakeup(&w->r); goto Read; } @@ -827,7 +836,7 @@ mntxmit(Mnt *m, Mnthdr *mh) mnterrdequeue(q, mh); nexterror(); } - sleep(&mh->r, return0, 0); + sleep(&mh->r, mntreadreply, mh); poperror(); qlock(q); qlocked = 1; diff --git a/gnot/fns.h b/gnot/fns.h index 4dfcee4b973cfc574045cd63e38dbddc7e192388..7835acc6257dc58b4ab358431fac15635e4fed25 100644 --- a/gnot/fns.h +++ b/gnot/fns.h @@ -155,6 +155,7 @@ void touser(void); void tsleep(Rendez*, int (*)(void*), void*, int); void twakeme(Alarm*); void unlock(Lock*); +void urpreset(void); void usepage(Page*, int); void userinit(void); void validaddr(ulong, ulong, int); diff --git a/gnot/main.c b/gnot/main.c index a097e64ea087380098d15b756ca26512f4a53487..185a4402a679376cba3fa2820956aa4e5bb2a9e7 100644 --- a/gnot/main.c +++ b/gnot/main.c @@ -313,4 +313,5 @@ confinit(void) if(*(uchar*)MOUSE & (1<<4)) conf.nbitbyte *= 2; /* ldepth 1 */ conf.nfont = 10*mul; + conf.nurp = 32; } diff --git a/gnot/sturp.c b/gnot/sturp.c index a89c8b4ff789513caee3b3b6fa2d94d4a41f6f86..2ebfe9f3e635dda8bb94998278fdbb8bc967898f 100644 --- a/gnot/sturp.c +++ b/gnot/sturp.c @@ -7,7 +7,6 @@ #include "errno.h" enum { - Nurp= 32, MSrexmit= 1000, Nmask= 0x7, }; @@ -97,7 +96,7 @@ struct Urp { #define OPEN 0x8 #define CLOSING 0x10 -Urp urp[Nurp]; +Urp *urp; /* * predeclared @@ -121,6 +120,13 @@ static void urpvomit(char*, Urp*); Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" }; +void +urpreset(void) +{ + newqinfo(&urpinfo); + urp = (Urp *)ialloc(conf.nurp*sizeof(Urp), 0); +} + static void urpopen(Queue *q, Stream *s) { @@ -131,14 +137,17 @@ urpopen(Queue *q, Stream *s) /* * find a free urp structure */ - for(up = urp; up < &urp[Nurp]; up++){ + for(up = urp; up < &urp[conf.nurp]; up++){ qlock(up); if(up->state == 0) break; qunlock(up); } - if(up == &urp[Nurp]) + if(up == &urp[conf.nurp]){ + q->ptr = 0; + WR(q)->ptr = 0; error(0, Egreg); + } q->ptr = q->other->ptr = up; up->rq = q; @@ -177,6 +186,8 @@ urpclose(Queue *q) int i; up = (Urp *)q->ptr; + if(up == 0) + return; /* * wait for all outstanding messages to drain, tell kernel @@ -967,7 +978,7 @@ urpdump(void) { Urp *up; - for(up = urp; up < &urp[Nurp]; up++) + for(up = urp; up < &urp[conf.nurp]; up++) if(up->rq) urpvomit("", up); } diff --git a/port/devdk.c b/port/devdk.c index cbd68b42e9238d7a74e9b34a7e516bb9b6393d8c..88599861ed9b0178e491ba31402c32f01b3732c7 100644 --- a/port/devdk.c +++ b/port/devdk.c @@ -551,7 +551,7 @@ void dkreset(void) { newqinfo(&dkmuxinfo); - newqinfo(&urpinfo); + urpreset(); } /* diff --git a/port/devmnt.c b/port/devmnt.c index 84e44060446fae5211e5bc61169ebda75ef15913..c96f567a91dad05afe95d1d46a88913cf1dd2b3c 100644 --- a/port/devmnt.c +++ b/port/devmnt.c @@ -54,6 +54,7 @@ struct Mnthdr Rendez r; Proc *p; Mntbuf *mbr; + int readreply; /* true if we are reader or our reply has come */ }; struct @@ -670,6 +671,11 @@ mnterrdequeue(MntQ *q, Mnthdr *mh) /* queue is unlocked */ qunlock(q); } +int +mntreadreply(void *a) +{ + return ((Mnthdr *)a)->readreply; +} void mntxmit(Mnt *m, Mnthdr *mh) { @@ -760,6 +766,7 @@ mntxmit(Mnt *m, Mnthdr *mh) mqfree(q); nexterror(); } + mh->readreply = 0; if((*devtab[q->msg->type].write)(q->msg, mbw->buf, n) != n){ print("short write in mntxmit\n"); error(0, Eshortmsg); @@ -790,6 +797,7 @@ mntxmit(Mnt *m, Mnthdr *mh) if(w = q->writer){ /* advance a writer to reader */ q->reader = w->p; q->writer = w->next; + w->readreply = 1; wakeup(&w->r); } qunlock(q); @@ -812,6 +820,7 @@ mntxmit(Mnt *m, Mnthdr *mh) q->writer = w->next; else ow->next = w->next; + w->readreply = 1; wakeup(&w->r); goto Read; } @@ -827,7 +836,7 @@ mntxmit(Mnt *m, Mnthdr *mh) mnterrdequeue(q, mh); nexterror(); } - sleep(&mh->r, return0, 0); + sleep(&mh->r, mntreadreply, mh); poperror(); qlock(q); qlocked = 1; @@ -859,3 +868,22 @@ mntxmit(Mnt *m, Mnthdr *mh) mbfree(mbw); poperror(); } + +mntdump() +{ + int i; + MntQ *q; + Mnthdr *h; + Proc *p; + + for(i=0; imsg) + continue; + p = q->reader; + print("q rdr %d wrtr ", p? p->pid : 0); + for(h=q->writer; h; h=h->next) + print("(%lux %lux %d)", h, &h->r, (p=h->p)? p->pid : 0); + print("\n"); + } +} diff --git a/port/sturp.c b/port/sturp.c index a89c8b4ff789513caee3b3b6fa2d94d4a41f6f86..2ebfe9f3e635dda8bb94998278fdbb8bc967898f 100644 --- a/port/sturp.c +++ b/port/sturp.c @@ -7,7 +7,6 @@ #include "errno.h" enum { - Nurp= 32, MSrexmit= 1000, Nmask= 0x7, }; @@ -97,7 +96,7 @@ struct Urp { #define OPEN 0x8 #define CLOSING 0x10 -Urp urp[Nurp]; +Urp *urp; /* * predeclared @@ -121,6 +120,13 @@ static void urpvomit(char*, Urp*); Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" }; +void +urpreset(void) +{ + newqinfo(&urpinfo); + urp = (Urp *)ialloc(conf.nurp*sizeof(Urp), 0); +} + static void urpopen(Queue *q, Stream *s) { @@ -131,14 +137,17 @@ urpopen(Queue *q, Stream *s) /* * find a free urp structure */ - for(up = urp; up < &urp[Nurp]; up++){ + for(up = urp; up < &urp[conf.nurp]; up++){ qlock(up); if(up->state == 0) break; qunlock(up); } - if(up == &urp[Nurp]) + if(up == &urp[conf.nurp]){ + q->ptr = 0; + WR(q)->ptr = 0; error(0, Egreg); + } q->ptr = q->other->ptr = up; up->rq = q; @@ -177,6 +186,8 @@ urpclose(Queue *q) int i; up = (Urp *)q->ptr; + if(up == 0) + return; /* * wait for all outstanding messages to drain, tell kernel @@ -967,7 +978,7 @@ urpdump(void) { Urp *up; - for(up = urp; up < &urp[Nurp]; up++) + for(up = urp; up < &urp[conf.nurp]; up++) if(up->rq) urpvomit("", up); } diff --git a/power/conf.h b/power/conf.h index 45f1fae33f39d9e426692a486b2ff955f6f2bbe6..8f1343efd731898225634c770bf49a6d5f898640 100644 --- a/power/conf.h +++ b/power/conf.h @@ -23,6 +23,7 @@ Conftab conftab[] = { {"nsrv", &conf.nsrv }, {"nnoifc", &conf.nnoifc }, {"nnoconv", &conf.nnoconv }, + {"nurp", &conf.nurp }, { 0, 0 }, }; diff --git a/power/dat.h b/power/dat.h index 718055f26e436b70ab0414ad890b290b91a26560..0d6cf1429fdd924d731496eef3f98970b7cafb5f 100644 --- a/power/dat.h +++ b/power/dat.h @@ -144,6 +144,7 @@ struct Conf ulong nsrv; /* public servers (devsrv.c) */ ulong nnoifc; /* number of nonet interfaces */ ulong nnoconv; /* number of nonet conversations/ifc */ + ulong nurp; /* max urp conversations */ }; struct Dev diff --git a/power/fns.h b/power/fns.h index d41370dbf7ea1556b2c61aa5e7ad4f71d31e1b04..e97966c6075bbc8c39e9a5d969d4e3a1f3151f04 100644 --- a/power/fns.h +++ b/power/fns.h @@ -179,6 +179,7 @@ void twakeme(Alarm*); void unlock(Lock*); void usepage(Page*, int); void userinit(void); +void urpreset(void); void validaddr(ulong, ulong, int); void vecinit(void); void vector80(void);