Newer
Older
int readopen; // read fd is still open
int writeopen; // write fd is still open
uint writep; // next index to write
uint readp; // next index to read
if((*f0 = filealloc()) == 0 || (*f1 = filealloc()) == 0)
goto bad;
if((p = (struct pipe*)kalloc(PAGE)) == 0)
goto bad;
p->readopen = 1;
p->writeopen = 1;
p->writep = 0;
p->readp = 0;
initlock(&p->lock, "pipe");
(*f0)->type = FD_PIPE;
(*f0)->readable = 1;
(*f0)->writable = 0;
(*f0)->pipe = p;
(*f1)->type = FD_PIPE;
(*f1)->readable = 0;
(*f1)->writable = 1;
(*f1)->pipe = p;
while(p->writep == p->readp + PIPESIZE) {
p->data[p->writep++ % PIPESIZE] = addr[i];

rsc
committed
release(&p->lock);
}
for(i = 0; i < n; i++){
if(p->readp == p->writep)
break;
addr[i] = p->data[p->readp++ % PIPESIZE];

rsc
committed
release(&p->lock);