annotate src/pipe.cbc @ 170:9b0f4b421288

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