summaryrefslogtreecommitdiff
path: root/pipe.c
diff options
context:
space:
mode:
authorkolya <kolya>2008-08-22 00:26:22 +0000
committerkolya <kolya>2008-08-22 00:26:22 +0000
commit02cc595f28f10067dcaacc7e147a3db7da277244 (patch)
treed743b6b39af5ad7268a69b3fa3bc4e78ac2fe191 /pipe.c
parent5c5470a2fa608204326c6eb06647037532a14655 (diff)
downloadxv6-labs-02cc595f28f10067dcaacc7e147a3db7da277244.tar.gz
xv6-labs-02cc595f28f10067dcaacc7e147a3db7da277244.tar.bz2
xv6-labs-02cc595f28f10067dcaacc7e147a3db7da277244.zip
clean up circular buffers, so pipe can queue 512 bytes rather than 511
Diffstat (limited to 'pipe.c')
-rw-r--r--pipe.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/pipe.c b/pipe.c
index 43f623a..fda3788 100644
--- a/pipe.c
+++ b/pipe.c
@@ -11,8 +11,8 @@
struct pipe {
int readopen; // read fd is still open
int writeopen; // write fd is still open
- int writep; // next index to write
- int readp; // next index to read
+ uint writep; // next index to write
+ uint readp; // next index to read
struct spinlock lock;
char data[PIPESIZE];
};
@@ -83,7 +83,7 @@ pipewrite(struct pipe *p, char *addr, int n)
acquire(&p->lock);
for(i = 0; i < n; i++){
- while(((p->writep + 1) % PIPESIZE) == p->readp){
+ while(p->writep == p->readp + PIPESIZE) {
if(p->readopen == 0 || cp->killed){
release(&p->lock);
return -1;
@@ -91,8 +91,7 @@ pipewrite(struct pipe *p, char *addr, int n)
wakeup(&p->readp);
sleep(&p->writep, &p->lock);
}
- p->data[p->writep] = addr[i];
- p->writep = (p->writep + 1) % PIPESIZE;
+ p->data[p->writep++ % PIPESIZE] = addr[i];
}
wakeup(&p->readp);
release(&p->lock);
@@ -115,8 +114,7 @@ piperead(struct pipe *p, char *addr, int n)
for(i = 0; i < n; i++){
if(p->readp == p->writep)
break;
- addr[i] = p->data[p->readp];
- p->readp = (p->readp + 1) % PIPESIZE;
+ addr[i] = p->data[p->readp++ % PIPESIZE];
}
wakeup(&p->writep);
release(&p->lock);