diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-05-03 19:34:48 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-05-03 19:34:48 +0200 |
commit | 9de8d61fe6a08ec9bb021bf13fcd6536b797d1ea (patch) | |
tree | f695f7856f2748e48882a02ab7c0834eff38e843 /sys/src/ape/lib/ap/plan9 | |
parent | e8efd0a2421994dcc0a8731d82be2301f19e9d09 (diff) |
ape: get rid of fixed MUXADDR for buffered i/o
instead of trying to resize the segment (which will not work when
the kernel picks the address as it will allocate right before
the base of the topmost segment), we create the mux segment with the
maximum size needed (arround 1.4MB) for OPEN_MAX filedescriptors.
buf slots will be reused and slots get demand paged once used.
Diffstat (limited to 'sys/src/ape/lib/ap/plan9')
-rw-r--r-- | sys/src/ape/lib/ap/plan9/_buf.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/sys/src/ape/lib/ap/plan9/_buf.c b/sys/src/ape/lib/ap/plan9/_buf.c index fe3588cb2..6a375672b 100644 --- a/sys/src/ape/lib/ap/plan9/_buf.c +++ b/sys/src/ape/lib/ap/plan9/_buf.c @@ -20,10 +20,9 @@ typedef struct Muxseg { int waittime; /* time for timer process to wait */ fd_set rwant; /* fd's that select wants to read */ fd_set ewant; /* fd's that select wants to know eof info on */ - Muxbuf bufs[INITBUFS]; /* can grow, via segbrk() */ + Muxbuf bufs[OPEN_MAX]; } Muxseg; -#define MUXADDR ((void*)0x6000000) static Muxseg *mux = 0; /* shared memory segment */ /* _muxsid and _killmuxsid are known in libbsd's listen.c */ @@ -50,14 +49,13 @@ static int copynotehandler(void *, char *); int _startbuf(int fd) { - long i, slot; - int pid, sid; + int i, pid, sid; Fdinfo *f; Muxbuf *b; if(mux == 0){ _RFORK(RFREND); - mux = (Muxseg*)_SEGATTACH(0, "shared", MUXADDR, sizeof(Muxseg)); + mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg)); if((long)mux == -1){ _syserrno(); return -1; @@ -66,7 +64,7 @@ _startbuf(int fd) atexit(_killmuxsid); } - if(fd == -1) + if(fd < 0) return 0; lock(&mux->lock); @@ -85,17 +83,16 @@ _startbuf(int fd) errno = EIO; return -1; } - - slot = mux->curfds++; - if(mux->curfds > INITBUFS) { - if(_SEGBRK(mux, mux->bufs+mux->curfds) < 0){ - _syserrno(); - unlock(&mux->lock); - return -1; - } + for(b = mux->bufs; b < &mux->bufs[mux->curfds]; b++) + if(b->fd == -1) + goto Found; + if(mux->curfds >= OPEN_MAX){ + unlock(&mux->lock); + errno = ENFILE; + return -1; } - - b = &mux->bufs[slot]; + mux->curfds++; +Found: b->n = 0; b->putnext = b->data; b->getnext = b->data; |