i cannot prove that release before wakeup is wrong, but i cannot convince myself it is right either
This commit is contained in:
parent
4bc5056c19
commit
ea6e370964
1 changed files with 2 additions and 8 deletions
10
pipe.c
10
pipe.c
|
@ -64,7 +64,6 @@ void
|
||||||
pipe_close(struct pipe *p, int writable)
|
pipe_close(struct pipe *p, int writable)
|
||||||
{
|
{
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
|
|
||||||
if(writable){
|
if(writable){
|
||||||
p->writeopen = 0;
|
p->writeopen = 0;
|
||||||
wakeup(&p->readp);
|
wakeup(&p->readp);
|
||||||
|
@ -72,7 +71,6 @@ pipe_close(struct pipe *p, int writable)
|
||||||
p->readopen = 0;
|
p->readopen = 0;
|
||||||
wakeup(&p->writep);
|
wakeup(&p->writep);
|
||||||
}
|
}
|
||||||
|
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
|
|
||||||
if(p->readopen == 0 && p->writeopen == 0)
|
if(p->readopen == 0 && p->writeopen == 0)
|
||||||
|
@ -86,7 +84,6 @@ pipe_write(struct pipe *p, char *addr, int n)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
|
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
while(((p->writep + 1) % PIPESIZE) == p->readp){
|
while(((p->writep + 1) % PIPESIZE) == p->readp){
|
||||||
if(p->readopen == 0 || cp->killed){
|
if(p->readopen == 0 || cp->killed){
|
||||||
|
@ -99,9 +96,8 @@ pipe_write(struct pipe *p, char *addr, int n)
|
||||||
p->data[p->writep] = addr[i];
|
p->data[p->writep] = addr[i];
|
||||||
p->writep = (p->writep + 1) % PIPESIZE;
|
p->writep = (p->writep + 1) % PIPESIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
release(&p->lock);
|
|
||||||
wakeup(&p->readp);
|
wakeup(&p->readp);
|
||||||
|
release(&p->lock);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +107,6 @@ 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){
|
||||||
if(p->writeopen == 0 || cp->killed){
|
if(p->writeopen == 0 || cp->killed){
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
|
@ -125,8 +120,7 @@ pipe_read(struct pipe *p, char *addr, int n)
|
||||||
addr[i] = p->data[p->readp];
|
addr[i] = p->data[p->readp];
|
||||||
p->readp = (p->readp + 1) % PIPESIZE;
|
p->readp = (p->readp + 1) % PIPESIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
release(&p->lock);
|
|
||||||
wakeup(&p->writep);
|
wakeup(&p->writep);
|
||||||
|
release(&p->lock);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue