test for closed pipe or killed on every char, not just if pipe full
This commit is contained in:
parent
329935eca8
commit
e1bb4c7434
|
@ -76,26 +76,29 @@ pipeclose(struct pipe *pi, int writable)
|
||||||
int
|
int
|
||||||
pipewrite(struct pipe *pi, uint64 addr, int n)
|
pipewrite(struct pipe *pi, uint64 addr, int n)
|
||||||
{
|
{
|
||||||
int i;
|
int i = 0;
|
||||||
char ch;
|
|
||||||
struct proc *pr = myproc();
|
struct proc *pr = myproc();
|
||||||
|
|
||||||
acquire(&pi->lock);
|
acquire(&pi->lock);
|
||||||
for(i = 0; i < n; i++){
|
while(i < n){
|
||||||
while(pi->nwrite == pi->nread + PIPESIZE){ //DOC: pipewrite-full
|
if(pi->readopen == 0 || pr->killed){
|
||||||
if(pi->readopen == 0 || pr->killed){
|
release(&pi->lock);
|
||||||
release(&pi->lock);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
if(pi->nwrite == pi->nread + PIPESIZE){ //DOC: pipewrite-full
|
||||||
wakeup(&pi->nread);
|
wakeup(&pi->nread);
|
||||||
sleep(&pi->nwrite, &pi->lock);
|
sleep(&pi->nwrite, &pi->lock);
|
||||||
|
} else {
|
||||||
|
char ch;
|
||||||
|
if(copyin(pr->pagetable, &ch, addr + i, 1) == -1)
|
||||||
|
break;
|
||||||
|
pi->data[pi->nwrite++ % PIPESIZE] = ch;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if(copyin(pr->pagetable, &ch, addr + i, 1) == -1)
|
|
||||||
break;
|
|
||||||
pi->data[pi->nwrite++ % PIPESIZE] = ch;
|
|
||||||
}
|
}
|
||||||
wakeup(&pi->nread);
|
wakeup(&pi->nread);
|
||||||
release(&pi->lock);
|
release(&pi->lock);
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue