annotate src/pipe.cbc @ 280:21a5761e3e7a

mv_extraction_dg_compile_sources Context2Util
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 28 Jan 2020 15:20:34 +0900
parents 7c200a8328fa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "types.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "defs.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "param.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "mmu.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "proc.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "fs.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "file.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include "spinlock.h"
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define PIPESIZE 512
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
52
214d21c891c7 rename to cbc
kono
parents: 37
diff changeset
12 #define __ncode __code
173
7c200a8328fa fix user malloc and spinlock redefinition
kono
parents: 154
diff changeset
13 // data_gear "pipe.h"
7c200a8328fa fix user malloc and spinlock redefinition
kono
parents: 154
diff changeset
14
154
343f8f3c8f18 add pipe.h
anatofuz
parents: 113
diff changeset
15 /*
0
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 struct pipe {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 struct spinlock lock;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 char data[PIPESIZE];
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 uint nread; // number of bytes read
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 uint nwrite; // number of bytes written
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 int readopen; // read fd is still open
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 int writeopen; // write fd is still open
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 };
154
343f8f3c8f18 add pipe.h
anatofuz
parents: 113
diff changeset
24 */
0
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 int pipealloc(struct file **f0, struct file **f1)
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 struct pipe *p;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 p = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 *f0 = *f1 = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 if((*f0 = filealloc()) == 0 || (*f1 = filealloc()) == 0) {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 goto bad;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 if((p = kmalloc (get_order(sizeof(*p)))) == 0) {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 goto bad;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 p->readopen = 1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 p->writeopen = 1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 p->nwrite = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 p->nread = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 initlock(&p->lock, "pipe");
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 (*f0)->type = FD_PIPE;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 (*f0)->readable = 1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 (*f0)->writable = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 (*f0)->pipe = p;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 (*f1)->type = FD_PIPE;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 (*f1)->readable = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 (*f1)->writable = 1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 (*f1)->pipe = p;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 return 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 //PAGEBREAK: 20
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 bad:
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 if(p) {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 kfree (p, get_order(sizeof*p));
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 if(*f0) {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 fileclose(*f0);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 if(*f1) {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 fileclose(*f1);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 return -1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 void pipeclose(struct pipe *p, int writable)
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 acquire(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 if(writable){
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 p->writeopen = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 wakeup(&p->nread);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 } else {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 p->readopen = 0;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 wakeup(&p->nwrite);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 if(p->readopen == 0 && p->writeopen == 0){
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 release(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 kfree (p, get_order(sizeof(*p)));
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 } else {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 release(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 //PAGEBREAK: 40
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 int pipewrite(struct pipe *p, char *addr, int n)
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 int i;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 acquire(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 for(i = 0; i < n; i++){
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 while(p->nwrite == p->nread + PIPESIZE){ //DOC: pipewrite-full
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 if(p->readopen == 0 /*|| proc->killed*/){
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 release(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 return -1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 wakeup(&p->nread);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 sleep(&p->nwrite, &p->lock); //DOC: pipewrite-sleep
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 p->data[p->nwrite++ % PIPESIZE] = addr[i];
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 wakeup(&p->nread); //DOC: pipewrite-wakeup1
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 release(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 return n;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
52
214d21c891c7 rename to cbc
kono
parents: 37
diff changeset
124 __ncode cbc_piperead3(){
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
125 struct pipe *p = proc->cbc_arg.cbc_console_arg.p;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
126 int i = proc->cbc_arg.cbc_console_arg.i;
37
mir3636
parents: 36
diff changeset
127 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
128 release(&p->lock);
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
129
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
130 goto next(i);
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
131 }
35
mir3636
parents: 0
diff changeset
132
52
214d21c891c7 rename to cbc
kono
parents: 37
diff changeset
133 __ncode cbc_piperead2(){
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
134 int i = proc->cbc_arg.cbc_console_arg.i;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
135 int n = proc->cbc_arg.cbc_console_arg.n;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
136 struct pipe *p = proc->cbc_arg.cbc_console_arg.p;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
137 char *addr = proc->cbc_arg.cbc_console_arg.addr;
37
mir3636
parents: 36
diff changeset
138 if (i < n && !(p->nread == p->nwrite)) {
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
139 addr[i] = p->data[p->nread++ % PIPESIZE];
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
140 i ++;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
141 proc->cbc_arg.cbc_console_arg.i = i;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
142 proc->cbc_arg.cbc_console_arg.p = p;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
143 proc->cbc_arg.cbc_console_arg.addr = addr;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
144 goto cbc_piperead2();
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
145 }
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
146 proc->cbc_arg.cbc_console_arg.p = p;
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
147 goto cbc_wakeup(&p->nwrite, cbc_piperead3); //DOC: piperead-wakeup
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
148 }
35
mir3636
parents: 0
diff changeset
149
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
150 __ncode cbc_piperead1(){
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
151 struct pipe *p = proc->cbc_arg.cbc_console_arg.p;
37
mir3636
parents: 36
diff changeset
152 __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
153 if (p->nread == p->nwrite && p->writeopen){
35
mir3636
parents: 0
diff changeset
154 if(proc->killed){
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
155 release(&p->lock);
35
mir3636
parents: 0
diff changeset
156 goto next(-1);
mir3636
parents: 0
diff changeset
157 }
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
158 proc->cbc_arg.cbc_console_arg.p = p;
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
159 goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1);
35
mir3636
parents: 0
diff changeset
160 }
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
161 int i = 0;
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
162 proc->cbc_arg.cbc_console_arg.i = i;
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
163 proc->cbc_arg.cbc_console_arg.p = p;
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
164 goto cbc_piperead2();
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
165 }
35
mir3636
parents: 0
diff changeset
166
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
167 __ncode cbc_piperead(struct pipe *p, char *addr, int n, __code (*next)(int ret))
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
168 {
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
169 acquire(&p->lock);
113
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
170 proc->cbc_arg.cbc_console_arg.n = n;
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
171 proc->cbc_arg.cbc_console_arg.p = p;
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
172 proc->cbc_arg.cbc_console_arg.addr = addr;
ef44d384ad9d rollback rev 52
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
173 proc->cbc_arg.cbc_console_arg.next = next;
36
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
174 goto cbc_piperead1();
d4e5846ddb48 cbc_piperead
mir3636
parents: 35
diff changeset
175 }
35
mir3636
parents: 0
diff changeset
176
0
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 int piperead(struct pipe *p, char *addr, int n)
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 int i;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 acquire(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 if(proc->killed){
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 release(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 return -1;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 sleep(&p->nread, &p->lock); //DOC: piperead-sleep*/
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 for(i = 0; i < n; i++){ //DOC: piperead-copy
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if(p->nread == p->nwrite) {
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 break;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 addr[i] = p->data[p->nread++ % PIPESIZE];
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 }
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 wakeup(&p->nwrite); //DOC: piperead-wakeup
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 release(&p->lock);
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 return i;
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 }