summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-10-22 06:36:36 -0400
committerFrans Kaashoek <[email protected]>2020-11-05 06:56:51 -0500
commite1bb4c74346bc439e8c0cd93750f90bb82c537c8 (patch)
tree76d8bb4eee2345576cb877c7e0b98d5afe6ebde7
parent329935eca8484d7f1d34c1d43b16c495d861ad75 (diff)
downloadxv6-labs-e1bb4c74346bc439e8c0cd93750f90bb82c537c8.tar.gz
xv6-labs-e1bb4c74346bc439e8c0cd93750f90bb82c537c8.tar.bz2
xv6-labs-e1bb4c74346bc439e8c0cd93750f90bb82c537c8.zip
test for closed pipe or killed on every char, not just if pipe full
-rw-r--r--kernel/pipe.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/kernel/pipe.c b/kernel/pipe.c
index 7ed402d..b6eefb9 100644
--- a/kernel/pipe.c
+++ b/kernel/pipe.c
@@ -76,26 +76,29 @@ pipeclose(struct pipe *pi, int writable)
int
pipewrite(struct pipe *pi, uint64 addr, int n)
{
- int i;
- char ch;
+ int i = 0;
struct proc *pr = myproc();
acquire(&pi->lock);
- for(i = 0; i < n; i++){
- while(pi->nwrite == pi->nread + PIPESIZE){ //DOC: pipewrite-full
- if(pi->readopen == 0 || pr->killed){
- release(&pi->lock);
- return -1;
- }
+ while(i < n){
+ if(pi->readopen == 0 || pr->killed){
+ release(&pi->lock);
+ return -1;
+ }
+ if(pi->nwrite == pi->nread + PIPESIZE){ //DOC: pipewrite-full
wakeup(&pi->nread);
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);
release(&pi->lock);
+
return i;
}