changeset 176:da4c83ae7ada

impl_close_pipe
author anatofuz
date Fri, 17 Jan 2020 15:02:42 +0900
parents de3934dd522a
children d4e068b15f30
files src/impl/file_impl_pipe.cbc
diffstat 1 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/file_impl_pipe.cbc	Fri Jan 17 14:37:26 2020 +0900
+++ b/src/impl/file_impl_pipe.cbc	Fri Jan 17 15:02:42 2020 +0900
@@ -81,7 +81,7 @@
 
 __code writepipe(struct pipe* file, char* addr, int n, __code next(...)) {
 
-  goto next(...);
+    goto next(...);
 }
 
 __code closepipe(struct pipe* file,int fd,__code next(...)) {
@@ -109,9 +109,30 @@
 }
 
 __code cbc_fileclose3(struct file* file, struct file* ff,__code next(...)) {
-    if (--f->ref > 0) {
-        release(&ftable.lock);
-        goto cbc_context->return();
+    *ff = *f;
+    f->ref = 0;
+    f->type = FD_NONE;
+    relsease(&ftable.lock);
+    
+    goto cbc_pipe_close(ff.pipe,ff.writable,next);
+}
+
+__code cbc_pipe_close(struct pipe* p, int writable, __code next(...)) {
+    acquire(&p->lock);
+    if (writable) {
+        goto cbc_pipe_close_writeopen(p,next);
     }
-    goto cbc_fileclose3(f,ff,next);
-}
\ No newline at end of file
+    goto cbc_pipe_close_readopen(p,next);
+}
+
+
+__code cbc_pipe_close_writeopen(struct pipe* p, __code next(...)) {
+    p->writeopen = 0;
+    goto cbc_wakeup(&p->nread,p,cbc_pipe_release,next);
+}
+
+__code cbc_pipe_close_readopen(struct pipe* p, __code next(...)) {
+    p->writeopen = 0;
+    goto cbc_->wakeup(&p->nwrite,p,cbc_pipe_release,next);
+}
+