# HG changeset patch # User anatofuz # Date 1576652122 -32400 # Node ID 49d8aba0002a57b48a4141eceadb16b4d9c50d9b # Parent d3f97de6362230a2a1cdb240085d0715768ec0c1 switch use sys_pipe_read.cbc diff -r d3f97de63622 -r 49d8aba0002a src/file_read.cbc --- a/src/file_read.cbc Mon Dec 16 21:55:29 2019 +0900 +++ b/src/file_read.cbc Wed Dec 18 15:55:22 2019 +0900 @@ -22,10 +22,10 @@ return NULL; //Error? } -__code selectReadInstance(struct Context cbc_context, struct file* f, __code ret(int i)) { +__code selectReadInstance(struct Context cbc_context, struct file* f, __code next(int i)) { if (f->readable == 0) { i = -1; - goto ret(i); + goto next(i); } SysRead* read = createFileReadInstFromFile(proc->cbc_context, f); goto read->read(f,addr,n); diff -r d3f97de63622 -r 49d8aba0002a src/impl/SysReadImpl.h --- a/src/impl/SysReadImpl.h Mon Dec 16 21:55:29 2019 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -typedef struct SysReadImpl impl SysRead { - -} SysReadImpl; diff -r d3f97de63622 -r 49d8aba0002a src/sys_pipe_read.cbc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sys_pipe_read.cbc Wed Dec 18 15:55:22 2019 +0900 @@ -0,0 +1,67 @@ +#include "../context.h" +#interface "SysRead.h" + +// ---- +// typedef struct PipeRead impl SysRead { +// struct pipe* p; +// int i; +// int n; +// __code cbc_piperead1(Type* sys_read, struct pipe* p, __code next(...)); +// __code cbc_piperead2(Type* sys_read, int i, int n, struct pipe* p, __code next(...)); +// __code cbc_piperead3(Type* sys_read, int i, struct pipe* p, __code next(...)); +// __code next(...); +// } PipeRead; +// ---- + +SysRead* createPipeRead(struct Context* cbc_context) { + struct SysRead* sys_read = new SysRead(); + struct PipeRead* pipe_read = new PipeRead(); + sys_read->sys_read = (union Data*)pipe_read; + pipe_read->p = NULL; + pipe_read->i = 0; + pipe_read->n = 0; + sys_read->impl = NULL; + sys_read->addr = NULL; + sys_read->n = 0; + pipe_read->cbc_piperead1 = C_cbc_piperead1PipeRead; + pipe_read->cbc_piperead2 = C_cbc_piperead2PipeRead; + pipe_read->cbc_piperead3 = C_cbc_piperead3PipeRead; + sys_read->read = C_readPipeRead; + return sys_read; +} +__code cbc_piperead1PipeRead(struct PipeRead* sys_read, struct pipe* p, __code next(...)) { + if (p->nread == p->nwrite && p->writeopen){ + if(proc->killed){ + release(&p->lock); + goto next(); + } + proc->cbc_arg.cbc_console_arg.p = p; + goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1); + } + goto cbc_piperead2SysReadImpl(sys_read,0,sys_read->n,sys_read->p); +} + +__code cbc_piperead2PipeRead(struct PipeRead* sys_read, int i, int n, struct pipe* p, __code next(...)) { + if (i < n && !(p->nread == p->nwrite)) { + addr[i] = p->data[p->nread++ % PIPESIZE]; + i ++; + goto cbc_piperead2(sys_read,i,n,p,addr); + } + goto cbc_wakeup(&p->nwrite, cbc_piperead3); //DOC: piperead-wakeup +} + +__code cbc_piperead3PipeRead(struct PipeRead* sys_read, int i, struct pipe* p, __code next(...)) { + + goto next(...); +} + +__code nextPipeRead(...) { + +} + +__code readPipeRead(struct PipeRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) { + + goto next(int ret,...); +} + + diff -r d3f97de63622 -r 49d8aba0002a src/sys_read_impl.cbc --- a/src/sys_read_impl.cbc Mon Dec 16 21:55:29 2019 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -#include "../context.h" -#interface "SysRead.h" - -// ---- -// typedef struct SysReadImpl impl SysRead { -// -// } SysReadImpl; -// ---- - -SysRead* createSysReadImpl(struct Context* cbc_context) { - struct SysRead* sys_read = new SysRead(); - struct SysReadImpl* sys_read_impl = new SysReadImpl(); - sys_read->sys_read = (union Data*)sys_read_impl; - sys_read->num = 0; - sys_read->addr = NULL; - sys_read->file = NULL; - sys_read->r = 0; - sys_read->pipe = NULL; - sys_read->read = C_readSysReadImpl; - sys_read->next = C_nextSysReadImpl; - sys_read->cbc_fileread1 = C_cbc_fileread1SysReadImpl; - sys_read->cbc_fileread = C_cbc_filereadSysReadImpl; - sys_read->cbc_piperead1 = C_cbc_piperead1SysReadImpl; - sys_read->cbc_piperead2 = C_cbc_piperead2SysReadImpl; - sys_read->cbc_piperead3 = C_cbc_piperead3SysReadImpl; - return sys_read; -} -__code readSysReadImpl(struct SysReadImpl* sys_read, __code next(...)) { - - goto next(...); -} - -__code nextSysReadImpl(...) { - -} - -__code cbc_fileread1SysReadImpl(struct SysReadImpl* sys_read, int r) { - -} - -__code cbc_filereadSysReadImpl(struct SysReadImpl* sys_read, struct file* file, char* addr, int n, __code (*next)(int ret)) { - - goto (*next); -} - -__code cbc_piperead1SysReadImpl(struct SysReadImpl* sys_read, struct pipe* p) { - __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next; - if (p->nread == p->nwrite && p->writeopen){ - if(proc->killed){ - release(&p->lock); - goto next(-1); - } - proc->cbc_arg.cbc_console_arg.p = p; - goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1); - } - goto cbc_piperead2SysReadImpl(sys_read,0,sys_read->n,sys_read->p); -} - -__code cbc_piperead2SysReadImpl(struct SysReadImpl* sys_read, int i, int n,struct pipe* p, char* addr) { - if (i < n && !(p->nread == p->nwrite)) { - addr[i] = p->data[p->nread++ % PIPESIZE]; - i ++; - goto cbc_piperead2(sys_read,i,n,p,addr); - } - goto cbc_wakeup(&p->nwrite, cbc_piperead3); //DOC: piperead-wakeup -} - -__code cbc_piperead3SysReadImpl(struct SysReadImpl* sys_read, struct pipe* p, int i) { - -} - -__code cbc_pipereadSysReadImpl(struct SysReadImpl* sys_read, struct pipe* p, char* addr, int n) { - acquire(&p->lock); - goto cbc_piperead1SysReadImpl(sys_read,p); -}