#include "../context.h" #interface "file.h" // ---- // typedef struct pipe impl file { // #define PIPESIZE 512 // struct spinlock lock; // char data[PIPESIZE]; // uint nread; // number of bytes read // uint nwrite; // number of bytes written // int readopen; // read fd is still open // int writeopen; // write fd is still open // } pipe; // ---- file* createpipe(struct Context* cbc_context) { struct file* file = new file(); struct pipe* pipe = new pipe(); file->file = (union Data*)pipe; pipe->lock = 0; pipe->spinlock = 0; pipe->data = 0; pipe->nread = 0; pipe->nwrite = 0; pipe->readopen = 0; pipe->writeopen = 0; file->off = 0; file->st = NULL; file->addr = NULL; file->n = 0; file->stat = C_statpipe; file->read = C_readpipe; file->write = C_writepipe; file->close = C_closepipe; return file; } __code statpipe(struct pipe* file, struct stat* st, __code next(...)) { goto next(...); } __code readpipe(struct pipe* file, char* addr, int n, __code next(...)) { acquire(&p->lock); goto cbc_piperead1(file,addr,n,next); } __code piperead1(struct pipe* p, char* addr, int n, __code next(...)) { if (p->nread == p->nwrite && p->writeopen){ if(proc->killed){ release(&p->lock); goto cbc_context->error(); } goto cbc_sleep(p,&p->nread, &p->lock, cbc_piperead1); } n = 0; goto cbc_piperead2(p,n); } __code writepipe(struct pipe* file, char* addr, int n, __code next(...)) { goto next(...); } __code closepipe(struct pipe* file,__code next(...)) { goto next(...); }