diff options
author | rtm <rtm> | 2006-07-01 21:26:01 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-07-01 21:26:01 +0000 |
commit | 8b4e2a08febc8b957b44732dbc7da831479a0005 (patch) | |
tree | 46c3b079ec65f0efbd1f3b603f1b11a3ae09e56d /pipe.c | |
parent | f7cea12b38a86e9b37fa5bc635310d3f85e5f8db (diff) | |
download | xv6-labs-8b4e2a08febc8b957b44732dbc7da831479a0005.tar.gz xv6-labs-8b4e2a08febc8b957b44732dbc7da831479a0005.tar.bz2 xv6-labs-8b4e2a08febc8b957b44732dbc7da831479a0005.zip |
swtch saves callee-saved registers
swtch idles on per-CPU stack, not on calling process's stack
fix pipe bugs
usertest.c tests pipes, fork, exit, close
Diffstat (limited to 'pipe.c')
-rw-r--r-- | pipe.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -28,6 +28,10 @@ pipe_alloc(struct fd **fd1, struct fd **fd2) goto oops; if((p = (struct pipe *) kalloc(PAGE)) == 0) goto oops; + p->readopen = 1; + p->writeopen = 1; + p->writep = 0; + p->readp = 0; (*fd1)->type = FD_PIPE; (*fd1)->readable = 1; (*fd1)->writeable = 0; @@ -54,10 +58,13 @@ pipe_alloc(struct fd **fd1, struct fd **fd2) void pipe_close(struct pipe *p, int writeable) { - if(writeable) + if(writeable){ p->writeopen = 0; - else + wakeup(&p->readp); + } else { p->readopen = 0; + wakeup(&p->writep); + } if(p->readopen == 0 && p->writeopen == 0) kfree((char *) p, PAGE); } @@ -71,11 +78,13 @@ pipe_write(struct pipe *p, char *addr, int n) while(((p->writep + 1) % PIPESIZE) == p->readp){ if(p->readopen == 0) return -1; + wakeup(&p->readp); sleep(&p->writep); } p->data[p->writep] = addr[i]; p->writep = (p->writep + 1) % PIPESIZE; } + wakeup(&p->readp); return i; } @@ -96,5 +105,6 @@ pipe_read(struct pipe *p, char *addr, int n) addr[i] = p->data[p->readp]; p->readp = (p->readp + 1) % PIPESIZE; } + wakeup(&p->writep); return i; } |