changeset 135:0c24464a66d8

introduce protoype sysread interface
author anatofuz
date Thu, 12 Dec 2019 12:57:29 +0900
parents 2a0de2f8596e
children fb75c5e661c2
files .hgignore src/interface/SysRead.h src/sys_read_impl.cbc
diffstat 3 files changed, 62 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Dec 11 17:23:41 2019 +0900
+++ b/.hgignore	Thu Dec 12 12:57:29 2019 +0900
@@ -14,3 +14,4 @@
 */Makefile
 mkfs
 
+*.orig
--- a/src/interface/SysRead.h	Wed Dec 11 17:23:41 2019 +0900
+++ b/src/interface/SysRead.h	Thu Dec 12 12:57:29 2019 +0900
@@ -1,9 +1,23 @@
 typedef struct SysRead<Type, Impl>{
    union  Data* sys_read;
+   union Data* impl;
    int num;
    char* addr;
    struct file* file;
-   __code read(Impl* sys_read, __code next(...));
+   int r;
+   struct pipe* pipe;
+   __code read(Impl* sys_read, union Data* impl, char* addr, int n, __code (*next)(int ret));
    //__code ret(Impl* cbc_sys_file, UInteger* num);
    __code next(...);
+   //__code cbc_fileread1(Impl* sys_read, int r);
+   __code cbc_fileread(Impl* sys_read, struct file* file, char* addr, int n, __code (*next)(int ret));
+   __code cbc_piperead(Impl* sys_read, struct pipe *p, char *addr, int n, __code (*next)(int ret));
+   //__code cbc_piperead1(Impl* sys_read, struct pipe* p);
+   //__code cbc_piperead2(Impl* sys_read, int i, int n,struct pipe* p);
+   //__code cbc_piperead3(Impl* sys_read, struct pipe* p, int i);
 } SysRead;
+
+/*
+ * cbc_piperead cbc_filereのAPIは微妙な違いしかない
+ * union Dataから実装の型を見てキャストすると良さそう
+ */
--- a/src/sys_read_impl.cbc	Wed Dec 11 17:23:41 2019 +0900
+++ b/src/sys_read_impl.cbc	Thu Dec 12 12:57:29 2019 +0900
@@ -1,6 +1,5 @@
 #include "../context.h"
 #interface "SysRead.h"
-//data_gear "file.dg"
 
 // ----
 // typedef struct SysReadImpl <Type, Isa> impl SysRead {
@@ -15,8 +14,15 @@
     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(...)) {
@@ -28,3 +34,42 @@
 
 }
 
+__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);
+}