diff src/impl/file_impl_pipe.cbc @ 170:9b0f4b421288

tweak
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 16 Jan 2020 20:34:18 +0900
parents e0255e66e646
children da4c83ae7ada
line wrap: on
line diff
--- a/src/impl/file_impl_pipe.cbc	Thu Jan 16 16:20:19 2020 +0900
+++ b/src/impl/file_impl_pipe.cbc	Thu Jan 16 20:34:18 2020 +0900
@@ -36,7 +36,7 @@
 }
 __code statpipe(struct pipe* file, struct stat* st, __code next(...)) {
 
-  goto next(...);
+    goto next(...);
 }
 
 __code readpipe(struct pipe* file, char* addr, int n, __code next(...)) {
@@ -85,11 +85,33 @@
 }
 
 __code closepipe(struct pipe* file,int fd,__code next(...)) {
-  proc->ofile[fd] = 0;
-  goto cbc_fileclose(f,next);
+    proc->ofile[fd] = 0;
+    goto cbc_fileclose(f,next);
 }
 
 
 __code cbc_fileclose(struct file* file, __code next(...)) {
-  goto next();
+    struct file ff;
+    acquire(*ftable.loc)
+
+    if (f->ref < 1) {
+        goto cbc_context->kernel_error->panic("file close");
+    }
+    goto cbc_fileclose2(f,ff,next);
 }
+
+__code cbc_fileclose2(struct file* file, struct file* ff,__code next(...)) {
+    if (--f->ref > 0) {
+        release(&ftable.lock);
+        goto cbc_context->return();
+    }
+    goto cbc_fileclose3(f,ff,next);
+}
+
+__code cbc_fileclose3(struct file* file, struct file* ff,__code next(...)) {
+    if (--f->ref > 0) {
+        release(&ftable.lock);
+        goto cbc_context->return();
+    }
+    goto cbc_fileclose3(f,ff,next);
+}
\ No newline at end of file