Newer
Older
#include "types.h"
#include "param.h"
#include "x86.h"
#include "mmu.h"
#include "proc.h"
#include "defs.h"
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
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;
int
pipe_write(struct pipe *p, char *addr, int n)
{
int i;
for(i = 0; i < n; i++){
while(((p->writep + 1) % PIPESIZE) == p->readp){
}
p->data[p->writep] = addr[i];
p->writep = (p->writep + 1) % PIPESIZE;
}

rsc
committed
release(&p->lock);
return i;
}
int
pipe_read(struct pipe *p, char *addr, int n)
{
int i;
}
for(i = 0; i < n; i++){
if(p->readp == p->writep)
break;
addr[i] = p->data[p->readp];
p->readp = (p->readp + 1) % PIPESIZE;
}

rsc
committed
release(&p->lock);