summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-27 16:06:19 +0000
committerrsc <rsc>2007-08-27 16:06:19 +0000
commit3ce164707868e188ebdba315141d2d8ca1704285 (patch)
treec97f0abe69c6ee06275b958b32d17ec946ae2d5f
parent603deefc6b18610ce89f44c18fd933929588d3ea (diff)
downloadxv6-labs-3ce164707868e188ebdba315141d2d8ca1704285.tar.gz
xv6-labs-3ce164707868e188ebdba315141d2d8ca1704285.tar.bz2
xv6-labs-3ce164707868e188ebdba315141d2d8ca1704285.zip
nits
-rw-r--r--pipe.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/pipe.c b/pipe.c
index 5e1fed2..cd27cbf 100644
--- a/pipe.c
+++ b/pipe.c
@@ -25,12 +25,10 @@ pipe_alloc(struct file **f0, struct file **f1)
p = 0;
*f0 = *f1 = 0;
- if((*f0 = filealloc()) == 0)
- goto oops;
- if((*f1 = filealloc()) == 0)
- goto oops;
- if((p = (struct pipe*) kalloc(PAGE)) == 0)
- goto oops;
+ if((*f0 = filealloc()) == 0 || (*f1 = filealloc()) == 0)
+ goto bad;
+ if((p = (struct pipe*)kalloc(PAGE)) == 0)
+ goto bad;
p->readopen = 1;
p->writeopen = 1;
p->writep = 0;
@@ -46,9 +44,9 @@ pipe_alloc(struct file **f0, struct file **f1)
(*f1)->pipe = p;
return 0;
- oops:
+ bad:
if(p)
- kfree((char*) p, PAGE);
+ kfree((char*)p, PAGE);
if(*f0){
(*f0)->type = FD_NONE;
fileclose(*f0);
@@ -74,7 +72,7 @@ pipe_close(struct pipe *p, int writable)
release(&p->lock);
if(p->readopen == 0 && p->writeopen == 0)
- kfree((char*) p, PAGE);
+ kfree((char*)p, PAGE);
}
//PAGEBREAK: 20
@@ -107,10 +105,10 @@ pipe_read(struct pipe *p, char *addr, int n)
int i;
acquire(&p->lock);
- while(p->readp == p->writep){
- if(p->writeopen == 0 || cp->killed){
+ while(p->readp == p->writep && p->writeopen){
+ if(cp->killed){
release(&p->lock);
- return 0;
+ return -1;
}
sleep(&p->readp, &p->lock);
}