Skip to content

Commit

Permalink
i cannot prove that release before wakeup is wrong, but i cannot conv…
Browse files Browse the repository at this point in the history
…ince myself it is right either
  • Loading branch information
rsc committed Aug 14, 2007
1 parent 4bc5056 commit ea6e370
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ void
pipe_close(struct pipe *p, int writable)
{
acquire(&p->lock);

if(writable){
p->writeopen = 0;
wakeup(&p->readp);
} else {
p->readopen = 0;
wakeup(&p->writep);
}

release(&p->lock);

if(p->readopen == 0 && p->writeopen == 0)
Expand All @@ -86,7 +84,6 @@ pipe_write(struct pipe *p, char *addr, int n)
int i;

acquire(&p->lock);

for(i = 0; i < n; i++){
while(((p->writep + 1) % PIPESIZE) == p->readp){
if(p->readopen == 0 || cp->killed){
Expand All @@ -99,9 +96,8 @@ pipe_write(struct pipe *p, char *addr, int n)
p->data[p->writep] = addr[i];
p->writep = (p->writep + 1) % PIPESIZE;
}

release(&p->lock);
wakeup(&p->readp);
release(&p->lock);
return i;
}

Expand All @@ -111,7 +107,6 @@ 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){
release(&p->lock);
Expand All @@ -125,8 +120,7 @@ pipe_read(struct pipe *p, char *addr, int n)
addr[i] = p->data[p->readp];
p->readp = (p->readp + 1) % PIPESIZE;
}

release(&p->lock);
wakeup(&p->writep);
release(&p->lock);
return i;
}

0 comments on commit ea6e370

Please sign in to comment.