nits
This commit is contained in:
parent
603deefc6b
commit
3ce1647078
1 changed files with 10 additions and 12 deletions
22
pipe.c
22
pipe.c
|
@ -25,12 +25,10 @@ pipe_alloc(struct file **f0, struct file **f1)
|
||||||
|
|
||||||
p = 0;
|
p = 0;
|
||||||
*f0 = *f1 = 0;
|
*f0 = *f1 = 0;
|
||||||
if((*f0 = filealloc()) == 0)
|
if((*f0 = filealloc()) == 0 || (*f1 = filealloc()) == 0)
|
||||||
goto oops;
|
goto bad;
|
||||||
if((*f1 = filealloc()) == 0)
|
if((p = (struct pipe*)kalloc(PAGE)) == 0)
|
||||||
goto oops;
|
goto bad;
|
||||||
if((p = (struct pipe*) kalloc(PAGE)) == 0)
|
|
||||||
goto oops;
|
|
||||||
p->readopen = 1;
|
p->readopen = 1;
|
||||||
p->writeopen = 1;
|
p->writeopen = 1;
|
||||||
p->writep = 0;
|
p->writep = 0;
|
||||||
|
@ -46,9 +44,9 @@ pipe_alloc(struct file **f0, struct file **f1)
|
||||||
(*f1)->pipe = p;
|
(*f1)->pipe = p;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
oops:
|
bad:
|
||||||
if(p)
|
if(p)
|
||||||
kfree((char*) p, PAGE);
|
kfree((char*)p, PAGE);
|
||||||
if(*f0){
|
if(*f0){
|
||||||
(*f0)->type = FD_NONE;
|
(*f0)->type = FD_NONE;
|
||||||
fileclose(*f0);
|
fileclose(*f0);
|
||||||
|
@ -74,7 +72,7 @@ pipe_close(struct pipe *p, int writable)
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
|
|
||||||
if(p->readopen == 0 && p->writeopen == 0)
|
if(p->readopen == 0 && p->writeopen == 0)
|
||||||
kfree((char*) p, PAGE);
|
kfree((char*)p, PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//PAGEBREAK: 20
|
//PAGEBREAK: 20
|
||||||
|
@ -107,10 +105,10 @@ pipe_read(struct pipe *p, char *addr, int n)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
while(p->readp == p->writep){
|
while(p->readp == p->writep && p->writeopen){
|
||||||
if(p->writeopen == 0 || cp->killed){
|
if(cp->killed){
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
sleep(&p->readp, &p->lock);
|
sleep(&p->readp, &p->lock);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue