changeset 165:21e83548d738

def file_impl_pipe.cbc private code gears
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 15 Jan 2020 19:56:28 +0900
parents 9c501dca25e3
children a70c436936e4
files src/impl/file_impl_pipe.cbc src/impl/pipe.h
diffstat 2 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/file_impl_pipe.cbc	Wed Jan 15 18:53:32 2020 +0900
+++ b/src/impl/file_impl_pipe.cbc	Wed Jan 15 19:56:28 2020 +0900
@@ -39,9 +39,21 @@
   goto next(...);
 }
 
-__code readpipe(struct pipe* file, char* addr, __code next(...)) {
+__code readpipe(struct pipe* file, char* addr, int n, __code next(...)) {
+    acquire(&p->lock);
+    goto cbc_piperead1(file,addr,n,next);
+}
 
-  goto 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(...)) {
--- a/src/impl/pipe.h	Wed Jan 15 18:53:32 2020 +0900
+++ b/src/impl/pipe.h	Wed Jan 15 19:56:28 2020 +0900
@@ -6,4 +6,12 @@
     uint nwrite;    // number of bytes written
     int readopen;   // read fd is still open
     int writeopen;  // write fd is still open
+
+    // interface field
+    int n;
+    char* addr;
+
+    // private code gear
+    __code piperead1(Impl* pipe, char* addr, int n, __code next(...));
+    __code piperead2(Impl* pipe, char* addr, int n, __code next(...));
 } pipe;