… | |
… | |
13 | |
13 | |
14 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
14 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
16 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
16 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | |
17 | |
18 | #define STACKSIZE 1024 /* yeah */ |
18 | #define STACKSIZE (128 * sizeof (long)) /* yeah */ |
19 | |
19 | |
20 | enum { |
20 | enum { |
21 | REQ_QUIT, |
21 | REQ_QUIT, |
22 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
22 | REQ_OPEN, REQ_CLOSE, REQ_READ, REQ_WRITE, |
23 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
23 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK |
… | |
… | |
62 | aio_thread *thr; |
62 | aio_thread *thr; |
63 | |
63 | |
64 | New (0, thr, 1, aio_thread); |
64 | New (0, thr, 1, aio_thread); |
65 | |
65 | |
66 | if (clone (aio_proc, |
66 | if (clone (aio_proc, |
67 | &(thr->stack[STACKSIZE]), |
67 | &(thr->stack[STACKSIZE - sizeof (long)]), |
68 | CLONE_VM|CLONE_FS|CLONE_FILES, |
68 | CLONE_VM|CLONE_FS|CLONE_FILES, |
69 | thr) >= 0) |
69 | thr) >= 0) |
70 | started++; |
70 | started++; |
71 | else |
71 | else |
72 | Safefree (thr); |
72 | Safefree (thr); |
… | |
… | |
88 | { |
88 | { |
89 | nreqs++; |
89 | nreqs++; |
90 | req->next = 0; |
90 | req->next = 0; |
91 | |
91 | |
92 | if (qe) |
92 | if (qe) |
|
|
93 | { |
93 | qe->next = req; |
94 | qe->next = req; |
|
|
95 | qe = req; |
|
|
96 | } |
94 | else |
97 | else |
95 | qe = qs = req; |
98 | qe = qs = req; |
96 | |
99 | |
97 | send_reqs (); |
100 | send_reqs (); |
98 | } |
101 | } |
… | |
… | |
154 | req->callback = SvREFCNT_inc (callback); |
157 | req->callback = SvREFCNT_inc (callback); |
155 | |
158 | |
156 | send_req (req); |
159 | send_req (req); |
157 | } |
160 | } |
158 | |
161 | |
|
|
162 | static void |
|
|
163 | poll_wait () |
|
|
164 | { |
|
|
165 | fd_set rfd; |
|
|
166 | FD_ZERO(&rfd); |
|
|
167 | FD_SET(respipe[0], &rfd); |
|
|
168 | |
|
|
169 | select (respipe[0] + 1, &rfd, 0, 0, 0); |
|
|
170 | } |
|
|
171 | |
159 | static int |
172 | static int |
160 | poll_cb (pTHX) |
173 | poll_cb (pTHX) |
161 | { |
174 | { |
162 | dSP; |
175 | dSP; |
163 | int count = 0; |
176 | int count = 0; |
164 | aio_req req; |
177 | aio_req req; |
165 | |
178 | |
166 | while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
179 | while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
167 | { |
180 | { |
|
|
181 | nreqs--; |
|
|
182 | |
168 | if (req->type == REQ_QUIT) |
183 | if (req->type == REQ_QUIT) |
169 | { |
184 | { |
170 | Safefree (req->thread); |
185 | Safefree (req->thread); |
171 | started--; |
186 | started--; |
172 | } |
187 | } |
… | |
… | |
199 | |
214 | |
200 | if (req->callback) |
215 | if (req->callback) |
201 | SvREFCNT_dec (req->callback); |
216 | SvREFCNT_dec (req->callback); |
202 | |
217 | |
203 | errno = errorno; |
218 | errno = errorno; |
204 | nreqs--; |
|
|
205 | count++; |
219 | count++; |
206 | } |
220 | } |
207 | |
221 | |
208 | Safefree (req); |
222 | Safefree (req); |
209 | } |
223 | } |
… | |
… | |
361 | cur--; |
375 | cur--; |
362 | } |
376 | } |
363 | |
377 | |
364 | while (started > nthreads) |
378 | while (started > nthreads) |
365 | { |
379 | { |
366 | fd_set rfd; |
380 | poll_wait (); |
367 | FD_ZERO(&rfd); |
|
|
368 | FD_SET(respipe[0], &rfd); |
|
|
369 | |
|
|
370 | select (respipe[0] + 1, &rfd, 0, 0, 0); |
|
|
371 | poll_cb (aTHX); |
381 | poll_cb (aTHX); |
372 | } |
382 | } |
373 | |
383 | |
374 | void |
384 | void |
375 | aio_open(pathname,flags,mode,callback) |
385 | aio_open(pathname,flags,mode,callback) |