annotate src/impl/file_impl_pipe.cbc @ 187:9d385a07dbfc

aligned API at pipe close...
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Jan 2020 15:30:43 +0900 (2020-01-21)
parents 312f86884606
children 64a1b9b8f08e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
8c39a36878b1 fix_include_context_file_at_file_impl
anatofuz
parents: 179
diff changeset
1 #include "../../context.h"
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #interface "file.h"
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // ----
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // typedef struct pipe<Impl, Isa> impl file {
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // #define PIPESIZE 512
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
7 // union Data* file;
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 // struct spinlock lock;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 // char data[PIPESIZE];
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // uint nread; // number of bytes read
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // uint nwrite; // number of bytes written
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 // int readopen; // read fd is still open
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 // int writeopen; // write fd is still open
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
14 //
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
15 // // interface field
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
16 // int n;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
17 // char* addr;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
18 //
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
19 // // private code gear
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
20 // __code piperead1(Impl* pipe, char* addr, int n, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
21 // __code piperead2(Impl* pipe, char* addr, int n, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
22 // __code cbc_pipeclose(Impl* pipe, Isa* file, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
23 // __code cbc_pipeclose2(Impl* pipe, Isa* file, Isa* ff, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
24 // __code cbc_pipeclose3(Impl* pipe, Isa* file, Isa* ff, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
25 // __code cbc_pipeclose4(Impl* pipe, int writable, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
26 // __code cbc_pipe_close_writeopen(Impl* pipe, __code next(...));
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
27 // __code cbc_pipe_close_readopen(Impl* pipe, __code next(...));
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 // } pipe;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 // ----
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 file* createpipe(struct Context* cbc_context) {
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 struct file* file = new file();
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 struct pipe* pipe = new pipe();
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 file->file = (union Data*)pipe;
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
35 pipe->file = NULL;
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 pipe->lock = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 pipe->spinlock = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 pipe->data = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 pipe->nread = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 pipe->nwrite = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 pipe->readopen = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 pipe->writeopen = 0;
185
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
43 pipe->n = 0;
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
44 pipe->addr = NULL;
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
45 file->remoe = 0;
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 file->off = 0;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 file->st = NULL;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 file->addr = NULL;
185
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
49 file->pipe = 0;
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
50 file->inode = 0;
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 file->n = 0;
185
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
52 file->fd = 0;
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
53 pipe->piperead1 = C_piperead1pipe;
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
54 pipe->piperead2 = C_piperead2pipe;
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
55 pipe->cbc_pipeclose = C_cbc_pipeclosepipe;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
56 pipe->cbc_pipeclose2 = C_cbc_pipeclose2pipe;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
57 pipe->cbc_pipeclose3 = C_cbc_pipeclose3pipe;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
58 pipe->cbc_pipeclose4 = C_cbc_pipeclose4pipe;
185
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
59 pipe->cbc_pipe_close_writeopen = C_cbc_pipe_close_writeopenpipe;
7fc3c3da2159 bump pipe.h
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 184
diff changeset
60 pipe->cbc_pipe_close_readopen = C_cbc_pipe_close_readopenpipe;
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 file->stat = C_statpipe;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 file->read = C_readpipe;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 file->write = C_writepipe;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 file->close = C_closepipe;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 return file;
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }
184
00e5213ebabe remove_skip_annotation
anatofuz
parents: 183
diff changeset
67
179
2842d9e65751 fix_skip_codegear
anatofuz
parents: 177
diff changeset
68 __code statpipe(struct pipe* file, struct stat* st, __code next(...)) { //:skip
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
70 goto next(...);
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
165
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
73 __code readpipe(struct pipe* file, char* addr, int n, __code next(...)) {
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
74 acquire(&p->lock);
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
75 goto cbc_piperead1(file,addr,n,next);
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
76 }
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
165
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
78 __code piperead1(struct pipe* p, char* addr, int n, __code next(...)) {
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
79 if (p->nread == p->nwrite && p->writeopen){
177
anatofuz
parents: 176
diff changeset
80 goto cbc_piperead2(p,addr,n,next);
165
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
81 }
21e83548d738 def file_impl_pipe.cbc private code gears
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 164
diff changeset
82 n = 0;
177
anatofuz
parents: 176
diff changeset
83 goto cbc_piperead3(p,addr,n,next);
anatofuz
parents: 176
diff changeset
84 }
anatofuz
parents: 176
diff changeset
85
anatofuz
parents: 176
diff changeset
86 __code piperead2(struct pipe* p, char* addr, int n, __code next(...)) {
anatofuz
parents: 176
diff changeset
87 if(proc->killed){
anatofuz
parents: 176
diff changeset
88 release(&p->lock);
anatofuz
parents: 176
diff changeset
89 goto cbc_context->error();
anatofuz
parents: 176
diff changeset
90 }
anatofuz
parents: 176
diff changeset
91 goto cbc_sleep(p,&p->nread, &p->lock, next,cbc_piperead1);
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 }
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
179
2842d9e65751 fix_skip_codegear
anatofuz
parents: 177
diff changeset
94
2842d9e65751 fix_skip_codegear
anatofuz
parents: 177
diff changeset
95 __code cbc_sleep(struct pipe* p, unit* nread, struct spinlock* lock, __code next(...), __code pread(...)){ //:skip
166
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
96 if(proc == 0) {
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
97 goto cbc_context->panic("sleep");
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
98 }
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
99
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
100 if(lk == 0) {
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
101 goto cbc_context->panic("sleep without lk");
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
102 }
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
103
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
104 if(lk != &ptable.lock){ //DOC: sleeplock0
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
105 acquire(&ptable.lock); //DOC: sleeplock1
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
106 release(lk);
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
107 }
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
108 goto cbc_sched(cbc_sleep1);
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
109 }
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
110
179
2842d9e65751 fix_skip_codegear
anatofuz
parents: 177
diff changeset
111 __code cbc_sched_stub(struct pipe* p, unit* nread, struct spinlock* lock, __code next(...), __code pread(...)){ //:skip
166
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
112 proc->chan = chan;
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
113 proc->state = SLEEPING;
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
114 proc->lk = lk;
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
115 proc->cbc_next = next1;
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
116 }
a70c436936e4 impl cbc_sleep
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 165
diff changeset
117
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 __code writepipe(struct pipe* file, char* addr, int n, __code next(...)) {
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
120 goto next(...);
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 }
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
123 __code pipeclose(struct pipe* file,int fd,__code next(...)) {
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
124 proc->ofile[fd] = 0;
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
125 goto file->cbc_pipeclose(file->file, next);
164
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
9c501dca25e3 add file_impl_pipe.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
169
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 166
diff changeset
128
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
129 __code cbc_pipeclose(struct pipe* pipe, struct file* file, __code next(...)) {
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
130 struct file ff;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
131 acquire(*ftable.loc)
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
132
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
133 if (f->ref < 1) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
134 goto cbc_context->kernel_error->panic("file close");
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
135 }
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
136 goto pipe->cbc_pipeclose2(f,ff,next);
169
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 166
diff changeset
137 }
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
138
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
139 __code cbc_pipeclose2(struct pipe* pipe,struct file* file, struct file* ff,__code next(...)) {
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
140 if (--f->ref > 0) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
141 release(&ftable.lock);
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
142 goto cbc_context->return();
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
143 }
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
144 goto pipe->cbc_pipeclose3(f,ff,next);
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
145 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
146
186
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 185
diff changeset
147 __code cbc_pipeclose3(struct pipe* pipe,struct file* file, struct file* ff,__code next(...)) {
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
148 *ff = *f;
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
149 f->ref = 0;
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
150 f->type = FD_NONE;
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
151 relsease(&ftable.lock);
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
152 struct pipe* p = ff.pipe;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
153 int writable = ff.writable;
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
154
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
155 goto pipe->cbc_pipeclose4(p,writable,next);
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
156 }
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
157
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
158 __code cbc_pipeclose4(struct pipe* pipe, int writable, __code next(...)) {
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
159 acquire(&pipe->lock);
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
160 if (writable) {
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
161 goto pipe->cbc_pipe_close_writeopen(next);
170
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 169
diff changeset
162 }
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
163 goto pipe->cbc_pipe_close_readopen(next);
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
164 }
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
165
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
166
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
167 __code cbc_pipe_close_writeopen(struct pipe* pipe, __code next(...)) {
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
168 pipe->writeopen = 0;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
169 goto cbc_wakeup(&pipe->nread,pipe,cbc_pipe_release,next);
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
170 }
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
171
187
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
172 __code cbc_pipe_close_readopen(struct pipe* pipe, __code next(...)) {
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
173 pipe->readopen = 0;
9d385a07dbfc aligned API at pipe close...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 186
diff changeset
174 goto cbc_context->wakeup(&pipe->nwrite,pipe,cbc_pipe_release,next);
176
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
175 }
da4c83ae7ada impl_close_pipe
anatofuz
parents: 170
diff changeset
176