This commit is contained in:
rsc 2007-08-27 16:06:19 +00:00
parent 603deefc6b
commit 3ce1647078

16
pipe.c
View file

@ -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((*f0 = filealloc()) == 0 || (*f1 = filealloc()) == 0)
goto bad;
if((p = (struct pipe*)kalloc(PAGE)) == 0)
goto oops;
goto bad;
p->readopen = 1;
p->writeopen = 1;
p->writep = 0;
@ -46,7 +44,7 @@ pipe_alloc(struct file **f0, struct file **f1)
(*f1)->pipe = p;
return 0;
oops:
bad:
if(p)
kfree((char*)p, PAGE);
if(*f0){
@ -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);
}