|
|
1 | /* solaris */ |
|
|
2 | #define _POSIX_PTHREAD_SEMANTICS 1 |
|
|
3 | |
|
|
4 | #if __linux |
|
|
5 | # define _GNU_SOURCE |
|
|
6 | #endif |
|
|
7 | |
1 | #define _REENTRANT 1 |
8 | #define _REENTRANT 1 |
|
|
9 | |
2 | #include <errno.h> |
10 | #include <errno.h> |
3 | |
11 | |
4 | #include "EXTERN.h" |
12 | #include "EXTERN.h" |
5 | #include "perl.h" |
13 | #include "perl.h" |
6 | #include "XSUB.h" |
14 | #include "XSUB.h" |
7 | |
15 | |
8 | #include "autoconf/config.h" |
16 | #include "autoconf/config.h" |
9 | |
17 | |
|
|
18 | #include <pthread.h> |
|
|
19 | |
|
|
20 | #include <stddef.h> |
|
|
21 | #include <errno.h> |
|
|
22 | #include <sys/time.h> |
|
|
23 | #include <sys/select.h> |
10 | #include <sys/types.h> |
24 | #include <sys/types.h> |
11 | #include <sys/stat.h> |
25 | #include <sys/stat.h> |
12 | |
26 | #include <limits.h> |
13 | #include <unistd.h> |
27 | #include <unistd.h> |
14 | #include <fcntl.h> |
28 | #include <fcntl.h> |
15 | #include <signal.h> |
29 | #include <signal.h> |
16 | #include <sched.h> |
30 | #include <sched.h> |
17 | |
31 | |
18 | #include <pthread.h> |
32 | #if HAVE_SENDFILE |
|
|
33 | # if __linux |
|
|
34 | # include <sys/sendfile.h> |
|
|
35 | # elif __freebsd |
|
|
36 | # include <sys/socket.h> |
|
|
37 | # include <sys/uio.h> |
|
|
38 | # elif __hpux |
|
|
39 | # include <sys/socket.h> |
|
|
40 | # elif __solaris /* not yet */ |
|
|
41 | # include <sys/sendfile.h> |
|
|
42 | # else |
|
|
43 | # error sendfile support requested but not available |
|
|
44 | # endif |
|
|
45 | #endif |
19 | |
46 | |
20 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
47 | /* used for struct dirent, AIX doesn't provide it */ |
21 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
48 | #ifndef NAME_MAX |
22 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
49 | # define NAME_MAX 4096 |
|
|
50 | #endif |
23 | |
51 | |
24 | #if __ia64 |
52 | #if __ia64 |
25 | # define STACKSIZE 65536 |
53 | # define STACKSIZE 65536 |
|
|
54 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
|
|
55 | # define STACKSIZE PTHREAD_STACK_MIN |
26 | #else |
56 | #else |
27 | # define STACKSIZE 4096 |
57 | # define STACKSIZE 16384 |
28 | #endif |
58 | #endif |
|
|
59 | |
|
|
60 | /* buffer size for various temporary buffers */ |
|
|
61 | #define AIO_BUFSIZE 65536 |
|
|
62 | |
|
|
63 | #define dBUF \ |
|
|
64 | char *aio_buf = malloc (AIO_BUFSIZE); \ |
|
|
65 | if (!aio_buf) \ |
|
|
66 | return -1; |
|
|
67 | |
|
|
68 | #define fBUF free (aio_buf) |
29 | |
69 | |
30 | enum { |
70 | enum { |
31 | REQ_QUIT, |
71 | REQ_QUIT, |
32 | REQ_OPEN, REQ_CLOSE, |
72 | REQ_OPEN, REQ_CLOSE, |
33 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
73 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
|
|
74 | REQ_SENDFILE, |
34 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
75 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
35 | REQ_FSYNC, REQ_FDATASYNC, |
76 | REQ_FSYNC, REQ_FDATASYNC, |
36 | REQ_UNLINK, REQ_RMDIR, |
77 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
37 | REQ_SYMLINK, |
78 | REQ_READDIR, |
|
|
79 | REQ_LINK, REQ_SYMLINK, |
|
|
80 | REQ_GROUP, REQ_NOP, |
|
|
81 | REQ_BUSY, |
38 | }; |
82 | }; |
39 | |
83 | |
|
|
84 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
|
|
85 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
86 | |
40 | typedef struct aio_cb { |
87 | typedef struct aio_cb |
|
|
88 | { |
41 | struct aio_cb *volatile next; |
89 | struct aio_cb *volatile next; |
42 | |
90 | |
43 | int type; |
91 | SV *data, *callback; |
44 | |
92 | SV *fh, *fh2; |
45 | int fd; |
93 | void *dataptr, *data2ptr; |
|
|
94 | Stat_t *statdata; |
46 | off_t offset; |
95 | off_t offset; |
47 | size_t length; |
96 | size_t length; |
48 | ssize_t result; |
97 | ssize_t result; |
|
|
98 | |
|
|
99 | STRLEN dataoffset; |
|
|
100 | int type; |
|
|
101 | int fd, fd2; |
|
|
102 | int errorno; |
49 | mode_t mode; /* open */ |
103 | mode_t mode; /* open */ |
50 | int errorno; |
|
|
51 | SV *data, *callback, *fh; |
|
|
52 | void *dataptr, *data2ptr; |
|
|
53 | STRLEN dataoffset; |
|
|
54 | |
104 | |
55 | Stat_t *statdata; |
105 | unsigned char flags; |
|
|
106 | unsigned char pri; |
|
|
107 | |
|
|
108 | SV *self; /* the perl counterpart of this request, if any */ |
|
|
109 | struct aio_cb *grp, *grp_prev, *grp_next, *grp_first; |
56 | } aio_cb; |
110 | } aio_cb; |
57 | |
111 | |
|
|
112 | enum { |
|
|
113 | FLAG_CANCELLED = 0x01, |
|
|
114 | }; |
|
|
115 | |
58 | typedef aio_cb *aio_req; |
116 | typedef aio_cb *aio_req; |
|
|
117 | typedef aio_cb *aio_req_ornot; |
59 | |
118 | |
|
|
119 | enum { |
|
|
120 | PRI_MIN = -4, |
|
|
121 | PRI_MAX = 4, |
|
|
122 | |
|
|
123 | DEFAULT_PRI = 0, |
|
|
124 | PRI_BIAS = -PRI_MIN, |
|
|
125 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
|
|
126 | }; |
|
|
127 | |
|
|
128 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
|
|
129 | |
60 | static int started; |
130 | static int started, wanted; |
61 | static volatile int nreqs; |
131 | static volatile int nreqs; |
62 | static int max_outstanding = 1<<30; |
132 | static int max_outstanding = 1<<30; |
63 | static int respipe [2]; |
133 | static int respipe [2]; |
64 | |
134 | |
|
|
135 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
|
|
136 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
|
|
137 | #else |
|
|
138 | # define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|
|
139 | #endif |
|
|
140 | |
65 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
141 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
66 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
142 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
67 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
143 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
68 | |
144 | |
69 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
145 | /* |
70 | static volatile aio_req ress, rese; /* queue start, queue end */ |
146 | * a somewhat faster data structure might be nice, but |
|
|
147 | * with 8 priorities this actually needs <20 insns |
|
|
148 | * per shift, the most expensive operation. |
|
|
149 | */ |
|
|
150 | typedef struct { |
|
|
151 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
|
|
152 | int size; |
|
|
153 | } reqq; |
71 | |
154 | |
|
|
155 | static reqq req_queue; |
|
|
156 | static reqq res_queue; |
|
|
157 | |
|
|
158 | int reqq_push (reqq *q, aio_req req) |
|
|
159 | { |
|
|
160 | int pri = req->pri; |
|
|
161 | req->next = 0; |
|
|
162 | |
|
|
163 | if (q->qe[pri]) |
|
|
164 | { |
|
|
165 | q->qe[pri]->next = req; |
|
|
166 | q->qe[pri] = req; |
|
|
167 | } |
|
|
168 | else |
|
|
169 | q->qe[pri] = q->qs[pri] = req; |
|
|
170 | |
|
|
171 | return q->size++; |
|
|
172 | } |
|
|
173 | |
|
|
174 | aio_req reqq_shift (reqq *q) |
|
|
175 | { |
|
|
176 | int pri; |
|
|
177 | |
|
|
178 | if (!q->size) |
|
|
179 | return 0; |
|
|
180 | |
|
|
181 | --q->size; |
|
|
182 | |
|
|
183 | for (pri = NUM_PRI; pri--; ) |
|
|
184 | { |
|
|
185 | aio_req req = q->qs[pri]; |
|
|
186 | |
|
|
187 | if (req) |
|
|
188 | { |
|
|
189 | if (!(q->qs[pri] = req->next)) |
|
|
190 | q->qe[pri] = 0; |
|
|
191 | |
|
|
192 | return req; |
|
|
193 | } |
|
|
194 | } |
|
|
195 | |
|
|
196 | abort (); |
|
|
197 | } |
|
|
198 | |
|
|
199 | static void req_invoke (aio_req req); |
72 | static void free_req (aio_req req) |
200 | static void req_free (aio_req req); |
73 | { |
|
|
74 | if (req->data) |
|
|
75 | SvREFCNT_dec (req->data); |
|
|
76 | |
201 | |
|
|
202 | /* must be called at most once */ |
|
|
203 | static SV *req_sv (aio_req req, const char *klass) |
|
|
204 | { |
77 | if (req->fh) |
205 | if (!req->self) |
|
|
206 | { |
|
|
207 | req->self = (SV *)newHV (); |
|
|
208 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
|
|
209 | } |
|
|
210 | |
|
|
211 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
|
|
212 | } |
|
|
213 | |
|
|
214 | static aio_req SvAIO_REQ (SV *sv) |
|
|
215 | { |
|
|
216 | MAGIC *mg; |
|
|
217 | |
|
|
218 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
|
|
219 | croak ("object of class " AIO_REQ_KLASS " expected"); |
|
|
220 | |
|
|
221 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
|
|
222 | |
|
|
223 | return mg ? (aio_req)mg->mg_ptr : 0; |
|
|
224 | } |
|
|
225 | |
|
|
226 | static void aio_grp_feed (aio_req grp) |
|
|
227 | { |
|
|
228 | while (grp->length < grp->fd2 && !(grp->flags & FLAG_CANCELLED)) |
|
|
229 | { |
|
|
230 | int old_len = grp->length; |
|
|
231 | |
|
|
232 | if (grp->fh2 && SvOK (grp->fh2)) |
|
|
233 | { |
|
|
234 | dSP; |
|
|
235 | |
|
|
236 | ENTER; |
|
|
237 | SAVETMPS; |
|
|
238 | PUSHMARK (SP); |
|
|
239 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
|
|
240 | PUTBACK; |
|
|
241 | call_sv (grp->fh2, G_VOID | G_EVAL | G_KEEPERR); |
|
|
242 | SPAGAIN; |
|
|
243 | FREETMPS; |
|
|
244 | LEAVE; |
|
|
245 | } |
|
|
246 | |
|
|
247 | /* stop if no progress has been made */ |
|
|
248 | if (old_len == grp->length) |
|
|
249 | { |
78 | SvREFCNT_dec (req->fh); |
250 | SvREFCNT_dec (grp->fh2); |
79 | |
251 | grp->fh2 = 0; |
80 | if (req->statdata) |
252 | break; |
81 | Safefree (req->statdata); |
253 | } |
82 | |
|
|
83 | if (req->callback) |
|
|
84 | SvREFCNT_dec (req->callback); |
|
|
85 | |
|
|
86 | Safefree (req); |
|
|
87 | } |
|
|
88 | |
|
|
89 | static void |
|
|
90 | poll_wait () |
|
|
91 | { |
|
|
92 | if (nreqs && !ress) |
|
|
93 | { |
254 | } |
|
|
255 | } |
|
|
256 | |
|
|
257 | static void aio_grp_dec (aio_req grp) |
|
|
258 | { |
|
|
259 | --grp->length; |
|
|
260 | |
|
|
261 | /* call feeder, if applicable */ |
|
|
262 | aio_grp_feed (grp); |
|
|
263 | |
|
|
264 | /* finish, if done */ |
|
|
265 | if (!grp->length && grp->fd) |
|
|
266 | { |
|
|
267 | req_invoke (grp); |
|
|
268 | req_free (grp); |
|
|
269 | } |
|
|
270 | } |
|
|
271 | |
|
|
272 | static void poll_wait () |
|
|
273 | { |
94 | fd_set rfd; |
274 | fd_set rfd; |
|
|
275 | |
|
|
276 | while (nreqs) |
|
|
277 | { |
|
|
278 | int size; |
|
|
279 | #if !(__i386 || __x86_64) /* safe without sempahore on this archs */ |
|
|
280 | pthread_mutex_lock (&reslock); |
|
|
281 | #endif |
|
|
282 | size = res_queue.size; |
|
|
283 | #if !(__i386 || __x86_64) /* safe without sempahore on this archs */ |
|
|
284 | pthread_mutex_unlock (&reslock); |
|
|
285 | #endif |
|
|
286 | |
|
|
287 | if (size) |
|
|
288 | return; |
|
|
289 | |
95 | FD_ZERO(&rfd); |
290 | FD_ZERO(&rfd); |
96 | FD_SET(respipe [0], &rfd); |
291 | FD_SET(respipe [0], &rfd); |
97 | |
292 | |
98 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
293 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
99 | } |
294 | } |
100 | } |
295 | } |
101 | |
296 | |
102 | static int |
297 | static void req_invoke (aio_req req) |
103 | poll_cb () |
298 | { |
|
|
299 | dSP; |
|
|
300 | |
|
|
301 | if (!(req->flags & FLAG_CANCELLED) && SvOK (req->callback)) |
|
|
302 | { |
|
|
303 | errno = req->errorno; |
|
|
304 | |
|
|
305 | ENTER; |
|
|
306 | SAVETMPS; |
|
|
307 | PUSHMARK (SP); |
|
|
308 | EXTEND (SP, 1); |
|
|
309 | |
|
|
310 | switch (req->type) |
|
|
311 | { |
|
|
312 | case REQ_READDIR: |
|
|
313 | { |
|
|
314 | SV *rv = &PL_sv_undef; |
|
|
315 | |
|
|
316 | if (req->result >= 0) |
|
|
317 | { |
|
|
318 | char *buf = req->data2ptr; |
|
|
319 | AV *av = newAV (); |
|
|
320 | |
|
|
321 | while (req->result) |
|
|
322 | { |
|
|
323 | SV *sv = newSVpv (buf, 0); |
|
|
324 | |
|
|
325 | av_push (av, sv); |
|
|
326 | buf += SvCUR (sv) + 1; |
|
|
327 | req->result--; |
|
|
328 | } |
|
|
329 | |
|
|
330 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
331 | } |
|
|
332 | |
|
|
333 | PUSHs (rv); |
|
|
334 | } |
|
|
335 | break; |
|
|
336 | |
|
|
337 | case REQ_OPEN: |
|
|
338 | { |
|
|
339 | /* convert fd to fh */ |
|
|
340 | SV *fh; |
|
|
341 | |
|
|
342 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
343 | PUTBACK; |
|
|
344 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
345 | SPAGAIN; |
|
|
346 | |
|
|
347 | fh = SvREFCNT_inc (POPs); |
|
|
348 | |
|
|
349 | PUSHMARK (SP); |
|
|
350 | XPUSHs (sv_2mortal (fh)); |
|
|
351 | } |
|
|
352 | break; |
|
|
353 | |
|
|
354 | case REQ_GROUP: |
|
|
355 | req->fd = 2; /* mark group as finished */ |
|
|
356 | |
|
|
357 | if (req->data) |
|
|
358 | { |
|
|
359 | int i; |
|
|
360 | AV *av = (AV *)req->data; |
|
|
361 | |
|
|
362 | EXTEND (SP, AvFILL (av) + 1); |
|
|
363 | for (i = 0; i <= AvFILL (av); ++i) |
|
|
364 | PUSHs (*av_fetch (av, i, 0)); |
|
|
365 | } |
|
|
366 | break; |
|
|
367 | |
|
|
368 | case REQ_NOP: |
|
|
369 | case REQ_BUSY: |
|
|
370 | break; |
|
|
371 | |
|
|
372 | default: |
|
|
373 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
374 | break; |
|
|
375 | } |
|
|
376 | |
|
|
377 | |
|
|
378 | PUTBACK; |
|
|
379 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
380 | SPAGAIN; |
|
|
381 | |
|
|
382 | FREETMPS; |
|
|
383 | LEAVE; |
|
|
384 | } |
|
|
385 | |
|
|
386 | if (req->grp) |
|
|
387 | { |
|
|
388 | aio_req grp = req->grp; |
|
|
389 | |
|
|
390 | /* unlink request */ |
|
|
391 | if (req->grp_next) req->grp_next->grp_prev = req->grp_prev; |
|
|
392 | if (req->grp_prev) req->grp_prev->grp_next = req->grp_next; |
|
|
393 | |
|
|
394 | if (grp->grp_first == req) |
|
|
395 | grp->grp_first = req->grp_next; |
|
|
396 | |
|
|
397 | aio_grp_dec (grp); |
|
|
398 | } |
|
|
399 | |
|
|
400 | if (SvTRUE (ERRSV)) |
|
|
401 | { |
|
|
402 | req_free (req); |
|
|
403 | croak (0); |
|
|
404 | } |
|
|
405 | } |
|
|
406 | |
|
|
407 | static void req_free (aio_req req) |
|
|
408 | { |
|
|
409 | if (req->self) |
|
|
410 | { |
|
|
411 | sv_unmagic (req->self, PERL_MAGIC_ext); |
|
|
412 | SvREFCNT_dec (req->self); |
|
|
413 | } |
|
|
414 | |
|
|
415 | SvREFCNT_dec (req->data); |
|
|
416 | SvREFCNT_dec (req->fh); |
|
|
417 | SvREFCNT_dec (req->fh2); |
|
|
418 | SvREFCNT_dec (req->callback); |
|
|
419 | Safefree (req->statdata); |
|
|
420 | |
|
|
421 | if (req->type == REQ_READDIR && req->result >= 0) |
|
|
422 | free (req->data2ptr); |
|
|
423 | |
|
|
424 | Safefree (req); |
|
|
425 | } |
|
|
426 | |
|
|
427 | static void req_cancel (aio_req req) |
|
|
428 | { |
|
|
429 | req->flags |= FLAG_CANCELLED; |
|
|
430 | |
|
|
431 | if (req->type == REQ_GROUP) |
|
|
432 | { |
|
|
433 | aio_req sub; |
|
|
434 | |
|
|
435 | for (sub = req->grp_first; sub; sub = sub->grp_next) |
|
|
436 | req_cancel (sub); |
|
|
437 | } |
|
|
438 | } |
|
|
439 | |
|
|
440 | static int poll_cb () |
104 | { |
441 | { |
105 | dSP; |
442 | dSP; |
106 | int count = 0; |
443 | int count = 0; |
107 | int do_croak = 0; |
444 | int do_croak = 0; |
108 | aio_req req; |
445 | aio_req req; |
109 | |
446 | |
110 | for (;;) |
447 | for (;;) |
111 | { |
448 | { |
112 | pthread_mutex_lock (&reslock); |
449 | pthread_mutex_lock (&reslock); |
113 | req = ress; |
450 | req = reqq_shift (&res_queue); |
114 | |
451 | |
115 | if (req) |
452 | if (req) |
116 | { |
453 | { |
117 | ress = req->next; |
|
|
118 | |
|
|
119 | if (!ress) |
454 | if (!res_queue.size) |
120 | { |
455 | { |
121 | rese = 0; |
|
|
122 | |
|
|
123 | /* read any signals sent by the worker threads */ |
456 | /* read any signals sent by the worker threads */ |
124 | char buf [32]; |
457 | char buf [32]; |
125 | while (read (respipe [0], buf, 32) == 32) |
458 | while (read (respipe [0], buf, 32) == 32) |
126 | ; |
459 | ; |
127 | } |
460 | } |
… | |
… | |
130 | pthread_mutex_unlock (&reslock); |
463 | pthread_mutex_unlock (&reslock); |
131 | |
464 | |
132 | if (!req) |
465 | if (!req) |
133 | break; |
466 | break; |
134 | |
467 | |
135 | nreqs--; |
468 | --nreqs; |
136 | |
469 | |
137 | if (req->type == REQ_QUIT) |
470 | if (req->type == REQ_QUIT) |
138 | started--; |
471 | started--; |
|
|
472 | else if (req->type == REQ_GROUP && req->length) |
|
|
473 | { |
|
|
474 | req->fd = 1; /* mark request as delayed */ |
|
|
475 | continue; |
|
|
476 | } |
139 | else |
477 | else |
140 | { |
478 | { |
141 | int errorno = errno; |
|
|
142 | errno = req->errorno; |
|
|
143 | |
|
|
144 | if (req->type == REQ_READ) |
479 | if (req->type == REQ_READ) |
145 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
480 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
|
|
481 | |
|
|
482 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
|
|
483 | SvREADONLY_off (req->data); |
146 | |
484 | |
147 | if (req->statdata) |
485 | if (req->statdata) |
148 | { |
486 | { |
149 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
487 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
150 | PL_laststatval = req->result; |
488 | PL_laststatval = req->result; |
151 | PL_statcache = *(req->statdata); |
489 | PL_statcache = *(req->statdata); |
152 | } |
490 | } |
153 | |
491 | |
154 | ENTER; |
492 | req_invoke (req); |
155 | PUSHMARK (SP); |
|
|
156 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
157 | |
493 | |
158 | if (req->type == REQ_OPEN) |
|
|
159 | { |
|
|
160 | /* convert fd to fh */ |
|
|
161 | SV *fh; |
|
|
162 | |
|
|
163 | PUTBACK; |
|
|
164 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
165 | SPAGAIN; |
|
|
166 | |
|
|
167 | fh = SvREFCNT_inc (POPs); |
|
|
168 | |
|
|
169 | PUSHMARK (SP); |
|
|
170 | XPUSHs (sv_2mortal (fh)); |
|
|
171 | } |
|
|
172 | |
|
|
173 | if (SvOK (req->callback)) |
|
|
174 | { |
|
|
175 | PUTBACK; |
|
|
176 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
177 | SPAGAIN; |
|
|
178 | |
|
|
179 | if (SvTRUE (ERRSV)) |
|
|
180 | { |
|
|
181 | free_req (req); |
|
|
182 | croak (0); |
|
|
183 | } |
|
|
184 | } |
|
|
185 | |
|
|
186 | LEAVE; |
|
|
187 | |
|
|
188 | errno = errorno; |
|
|
189 | count++; |
494 | count++; |
190 | } |
495 | } |
191 | |
496 | |
192 | free_req (req); |
497 | req_free (req); |
193 | } |
498 | } |
194 | |
499 | |
195 | return count; |
500 | return count; |
196 | } |
501 | } |
197 | |
502 | |
198 | static void *aio_proc(void *arg); |
503 | static void *aio_proc(void *arg); |
199 | |
504 | |
200 | static void |
|
|
201 | start_thread (void) |
505 | static void start_thread (void) |
202 | { |
506 | { |
203 | sigset_t fullsigset, oldsigset; |
507 | sigset_t fullsigset, oldsigset; |
204 | pthread_t tid; |
508 | pthread_t tid; |
205 | pthread_attr_t attr; |
509 | pthread_attr_t attr; |
206 | |
510 | |
… | |
… | |
215 | started++; |
519 | started++; |
216 | |
520 | |
217 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
521 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
218 | } |
522 | } |
219 | |
523 | |
220 | static void |
524 | static void req_send (aio_req req) |
221 | send_req (aio_req req) |
|
|
222 | { |
525 | { |
|
|
526 | while (started < wanted && nreqs >= started) |
|
|
527 | start_thread (); |
|
|
528 | |
223 | nreqs++; |
529 | ++nreqs; |
224 | |
530 | |
225 | pthread_mutex_lock (&reqlock); |
531 | pthread_mutex_lock (&reqlock); |
226 | |
532 | reqq_push (&req_queue, req); |
227 | req->next = 0; |
|
|
228 | |
|
|
229 | if (reqe) |
|
|
230 | { |
|
|
231 | reqe->next = req; |
|
|
232 | reqe = req; |
|
|
233 | } |
|
|
234 | else |
|
|
235 | reqe = reqs = req; |
|
|
236 | |
|
|
237 | pthread_cond_signal (&reqwait); |
533 | pthread_cond_signal (&reqwait); |
238 | pthread_mutex_unlock (&reqlock); |
534 | pthread_mutex_unlock (&reqlock); |
239 | |
535 | |
240 | if (nreqs > max_outstanding) |
536 | if (nreqs > max_outstanding) |
241 | for (;;) |
537 | for (;;) |
… | |
… | |
247 | |
543 | |
248 | poll_wait (); |
544 | poll_wait (); |
249 | } |
545 | } |
250 | } |
546 | } |
251 | |
547 | |
252 | static void |
548 | static void end_thread (void) |
253 | end_thread (void) |
|
|
254 | { |
549 | { |
255 | aio_req req; |
550 | aio_req req; |
|
|
551 | |
256 | Newz (0, req, 1, aio_cb); |
552 | Newz (0, req, 1, aio_cb); |
|
|
553 | |
257 | req->type = REQ_QUIT; |
554 | req->type = REQ_QUIT; |
|
|
555 | req->pri = PRI_MAX + PRI_BIAS; |
258 | |
556 | |
259 | send_req (req); |
557 | req_send (req); |
260 | } |
558 | } |
261 | |
559 | |
262 | static void min_parallel (int nthreads) |
560 | static void min_parallel (int nthreads) |
263 | { |
561 | { |
264 | while (nthreads > started) |
562 | if (wanted < nthreads) |
265 | start_thread (); |
563 | wanted = nthreads; |
266 | } |
564 | } |
267 | |
565 | |
268 | static void max_parallel (int nthreads) |
566 | static void max_parallel (int nthreads) |
269 | { |
567 | { |
270 | int cur = started; |
568 | int cur = started; |
271 | |
569 | |
|
|
570 | if (wanted > nthreads) |
|
|
571 | wanted = nthreads; |
|
|
572 | |
272 | while (cur > nthreads) |
573 | while (cur > wanted) |
273 | { |
574 | { |
274 | end_thread (); |
575 | end_thread (); |
275 | cur--; |
576 | cur--; |
276 | } |
577 | } |
277 | |
578 | |
278 | while (started > nthreads) |
579 | while (started > wanted) |
279 | { |
580 | { |
280 | poll_wait (); |
581 | poll_wait (); |
281 | poll_cb (); |
582 | poll_cb (); |
282 | } |
583 | } |
283 | } |
584 | } |
… | |
… | |
290 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
591 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
291 | croak ("cannot set result pipe to nonblocking mode"); |
592 | croak ("cannot set result pipe to nonblocking mode"); |
292 | |
593 | |
293 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
594 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
294 | croak ("cannot set result pipe to nonblocking mode"); |
595 | croak ("cannot set result pipe to nonblocking mode"); |
295 | } |
|
|
296 | |
|
|
297 | static void atfork_prepare (void) |
|
|
298 | { |
|
|
299 | for (;;) { |
|
|
300 | |
|
|
301 | for (;;) |
|
|
302 | { |
|
|
303 | poll_cb (); |
|
|
304 | |
|
|
305 | if (!nreqs) |
|
|
306 | break; |
|
|
307 | |
|
|
308 | poll_wait (); |
|
|
309 | } |
|
|
310 | |
|
|
311 | pthread_mutex_lock (&reqlock); |
|
|
312 | |
|
|
313 | if (!nreqs) |
|
|
314 | break; |
|
|
315 | |
|
|
316 | pthread_mutex_unlock (&reqlock); |
|
|
317 | } |
|
|
318 | |
|
|
319 | pthread_mutex_lock (&reslock); |
|
|
320 | |
|
|
321 | assert (!nreqs && !reqs && !ress); |
|
|
322 | } |
|
|
323 | |
|
|
324 | static void atfork_parent (void) |
|
|
325 | { |
|
|
326 | pthread_mutex_unlock (&reslock); |
|
|
327 | pthread_mutex_unlock (&reqlock); |
|
|
328 | } |
|
|
329 | |
|
|
330 | static void atfork_child (void) |
|
|
331 | { |
|
|
332 | int restart = started; |
|
|
333 | started = 0; |
|
|
334 | |
|
|
335 | atfork_parent (); |
|
|
336 | |
|
|
337 | min_parallel (restart); |
|
|
338 | } |
596 | } |
339 | |
597 | |
340 | /*****************************************************************************/ |
598 | /*****************************************************************************/ |
341 | /* work around various missing functions */ |
599 | /* work around various missing functions */ |
342 | |
600 | |
… | |
… | |
347 | /* |
605 | /* |
348 | * make our pread/pwrite safe against themselves, but not against |
606 | * make our pread/pwrite safe against themselves, but not against |
349 | * normal read/write by using a mutex. slows down execution a lot, |
607 | * normal read/write by using a mutex. slows down execution a lot, |
350 | * but that's your problem, not mine. |
608 | * but that's your problem, not mine. |
351 | */ |
609 | */ |
352 | static pthread_mutex_t iolock = PTHREAD_MUTEX_INITIALIZER; |
610 | static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; |
353 | |
611 | |
354 | static ssize_t |
612 | static ssize_t pread (int fd, void *buf, size_t count, off_t offset) |
355 | pread (int fd, void *buf, size_t count, off_t offset) |
|
|
356 | { |
613 | { |
357 | ssize_t res; |
614 | ssize_t res; |
358 | off_t ooffset; |
615 | off_t ooffset; |
359 | |
616 | |
360 | pthread_mutex_lock (&iolock); |
617 | pthread_mutex_lock (&preadwritelock); |
361 | ooffset = lseek (fd, 0, SEEK_CUR); |
618 | ooffset = lseek (fd, 0, SEEK_CUR); |
362 | lseek (fd, offset, SEEK_SET); |
619 | lseek (fd, offset, SEEK_SET); |
363 | res = read (fd, buf, count); |
620 | res = read (fd, buf, count); |
364 | lseek (fd, ooffset, SEEK_SET); |
621 | lseek (fd, ooffset, SEEK_SET); |
365 | pthread_mutex_unlock (&iolock); |
622 | pthread_mutex_unlock (&preadwritelock); |
366 | |
623 | |
367 | return res; |
624 | return res; |
368 | } |
625 | } |
369 | |
626 | |
370 | static ssize_t |
|
|
371 | pwrite (int fd, void *buf, size_t count, off_t offset) |
627 | static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) |
372 | { |
628 | { |
373 | ssize_t res; |
629 | ssize_t res; |
374 | off_t ooffset; |
630 | off_t ooffset; |
375 | |
631 | |
376 | pthread_mutex_lock (&iolock); |
632 | pthread_mutex_lock (&preadwritelock); |
377 | ooffset = lseek (fd, 0, SEEK_CUR); |
633 | ooffset = lseek (fd, 0, SEEK_CUR); |
378 | lseek (fd, offset, SEEK_SET); |
634 | lseek (fd, offset, SEEK_SET); |
379 | res = write (fd, buf, count); |
635 | res = write (fd, buf, count); |
380 | lseek (fd, offset, SEEK_SET); |
636 | lseek (fd, offset, SEEK_SET); |
381 | pthread_mutex_unlock (&iolock); |
637 | pthread_mutex_unlock (&preadwritelock); |
382 | |
638 | |
383 | return res; |
639 | return res; |
384 | } |
640 | } |
385 | #endif |
641 | #endif |
386 | |
642 | |
… | |
… | |
389 | #endif |
645 | #endif |
390 | |
646 | |
391 | #if !HAVE_READAHEAD |
647 | #if !HAVE_READAHEAD |
392 | # define readahead aio_readahead |
648 | # define readahead aio_readahead |
393 | |
649 | |
394 | static char readahead_buf[4096]; |
|
|
395 | |
|
|
396 | static ssize_t |
|
|
397 | readahead (int fd, off_t offset, size_t count) |
650 | static ssize_t readahead (int fd, off_t offset, size_t count) |
398 | { |
651 | { |
|
|
652 | dBUF; |
|
|
653 | |
399 | while (count > 0) |
654 | while (count > 0) |
400 | { |
655 | { |
401 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
656 | size_t len = count < AIO_BUFSIZE ? count : AIO_BUFSIZE; |
402 | |
657 | |
403 | pread (fd, readahead_buf, len, offset); |
658 | pread (fd, aio_buf, len, offset); |
404 | offset += len; |
659 | offset += len; |
405 | count -= len; |
660 | count -= len; |
406 | } |
661 | } |
407 | |
662 | |
|
|
663 | fBUF; |
|
|
664 | |
408 | errno = 0; |
665 | errno = 0; |
409 | } |
666 | } |
410 | #endif |
667 | #endif |
411 | |
668 | |
|
|
669 | #if !HAVE_READDIR_R |
|
|
670 | # define readdir_r aio_readdir_r |
|
|
671 | |
|
|
672 | static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; |
|
|
673 | |
|
|
674 | static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
|
|
675 | { |
|
|
676 | struct dirent *e; |
|
|
677 | int errorno; |
|
|
678 | |
|
|
679 | pthread_mutex_lock (&readdirlock); |
|
|
680 | |
|
|
681 | e = readdir (dirp); |
|
|
682 | errorno = errno; |
|
|
683 | |
|
|
684 | if (e) |
|
|
685 | { |
|
|
686 | *res = ent; |
|
|
687 | strcpy (ent->d_name, e->d_name); |
|
|
688 | } |
|
|
689 | else |
|
|
690 | *res = 0; |
|
|
691 | |
|
|
692 | pthread_mutex_unlock (&readdirlock); |
|
|
693 | |
|
|
694 | errno = errorno; |
|
|
695 | return e ? 0 : -1; |
|
|
696 | } |
|
|
697 | #endif |
|
|
698 | |
|
|
699 | /* sendfile always needs emulation */ |
|
|
700 | static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
|
|
701 | { |
|
|
702 | ssize_t res; |
|
|
703 | |
|
|
704 | if (!count) |
|
|
705 | return 0; |
|
|
706 | |
|
|
707 | #if HAVE_SENDFILE |
|
|
708 | # if __linux |
|
|
709 | res = sendfile (ofd, ifd, &offset, count); |
|
|
710 | |
|
|
711 | # elif __freebsd |
|
|
712 | /* |
|
|
713 | * Of course, the freebsd sendfile is a dire hack with no thoughts |
|
|
714 | * wasted on making it similar to other I/O functions. |
|
|
715 | */ |
|
|
716 | { |
|
|
717 | off_t sbytes; |
|
|
718 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
|
|
719 | |
|
|
720 | if (res < 0 && sbytes) |
|
|
721 | /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ |
|
|
722 | res = sbytes; |
|
|
723 | } |
|
|
724 | |
|
|
725 | # elif __hpux |
|
|
726 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
|
|
727 | |
|
|
728 | # elif __solaris |
|
|
729 | { |
|
|
730 | struct sendfilevec vec; |
|
|
731 | size_t sbytes; |
|
|
732 | |
|
|
733 | vec.sfv_fd = ifd; |
|
|
734 | vec.sfv_flag = 0; |
|
|
735 | vec.sfv_off = offset; |
|
|
736 | vec.sfv_len = count; |
|
|
737 | |
|
|
738 | res = sendfilev (ofd, &vec, 1, &sbytes); |
|
|
739 | |
|
|
740 | if (res < 0 && sbytes) |
|
|
741 | res = sbytes; |
|
|
742 | } |
|
|
743 | |
|
|
744 | # endif |
|
|
745 | #else |
|
|
746 | res = -1; |
|
|
747 | errno = ENOSYS; |
|
|
748 | #endif |
|
|
749 | |
|
|
750 | if (res < 0 |
|
|
751 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
|
|
752 | #if __solaris |
|
|
753 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
|
|
754 | #endif |
|
|
755 | ) |
|
|
756 | ) |
|
|
757 | { |
|
|
758 | /* emulate sendfile. this is a major pain in the ass */ |
|
|
759 | dBUF; |
|
|
760 | |
|
|
761 | res = 0; |
|
|
762 | |
|
|
763 | while (count) |
|
|
764 | { |
|
|
765 | ssize_t cnt; |
|
|
766 | |
|
|
767 | cnt = pread (ifd, aio_buf, count > AIO_BUFSIZE ? AIO_BUFSIZE : count, offset); |
|
|
768 | |
|
|
769 | if (cnt <= 0) |
|
|
770 | { |
|
|
771 | if (cnt && !res) res = -1; |
|
|
772 | break; |
|
|
773 | } |
|
|
774 | |
|
|
775 | cnt = write (ofd, aio_buf, cnt); |
|
|
776 | |
|
|
777 | if (cnt <= 0) |
|
|
778 | { |
|
|
779 | if (cnt && !res) res = -1; |
|
|
780 | break; |
|
|
781 | } |
|
|
782 | |
|
|
783 | offset += cnt; |
|
|
784 | res += cnt; |
|
|
785 | count -= cnt; |
|
|
786 | } |
|
|
787 | |
|
|
788 | fBUF; |
|
|
789 | } |
|
|
790 | |
|
|
791 | return res; |
|
|
792 | } |
|
|
793 | |
|
|
794 | /* read a full directory */ |
|
|
795 | static int scandir_ (const char *path, void **namesp) |
|
|
796 | { |
|
|
797 | DIR *dirp; |
|
|
798 | union |
|
|
799 | { |
|
|
800 | struct dirent d; |
|
|
801 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
|
|
802 | } *u; |
|
|
803 | struct dirent *entp; |
|
|
804 | char *name, *names; |
|
|
805 | int memlen = 4096; |
|
|
806 | int memofs = 0; |
|
|
807 | int res = 0; |
|
|
808 | int errorno; |
|
|
809 | |
|
|
810 | dirp = opendir (path); |
|
|
811 | if (!dirp) |
|
|
812 | return -1; |
|
|
813 | |
|
|
814 | u = malloc (sizeof (*u)); |
|
|
815 | names = malloc (memlen); |
|
|
816 | |
|
|
817 | if (u && names) |
|
|
818 | for (;;) |
|
|
819 | { |
|
|
820 | errno = 0; |
|
|
821 | readdir_r (dirp, &u->d, &entp); |
|
|
822 | |
|
|
823 | if (!entp) |
|
|
824 | break; |
|
|
825 | |
|
|
826 | name = entp->d_name; |
|
|
827 | |
|
|
828 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
|
|
829 | { |
|
|
830 | int len = strlen (name) + 1; |
|
|
831 | |
|
|
832 | res++; |
|
|
833 | |
|
|
834 | while (memofs + len > memlen) |
|
|
835 | { |
|
|
836 | memlen *= 2; |
|
|
837 | names = realloc (names, memlen); |
|
|
838 | if (!names) |
|
|
839 | break; |
|
|
840 | } |
|
|
841 | |
|
|
842 | memcpy (names + memofs, name, len); |
|
|
843 | memofs += len; |
|
|
844 | } |
|
|
845 | } |
|
|
846 | |
|
|
847 | errorno = errno; |
|
|
848 | free (u); |
|
|
849 | closedir (dirp); |
|
|
850 | |
|
|
851 | if (errorno) |
|
|
852 | { |
|
|
853 | free (names); |
|
|
854 | errno = errorno; |
|
|
855 | res = -1; |
|
|
856 | } |
|
|
857 | |
|
|
858 | *namesp = (void *)names; |
|
|
859 | return res; |
|
|
860 | } |
|
|
861 | |
412 | /*****************************************************************************/ |
862 | /*****************************************************************************/ |
413 | |
863 | |
414 | static void * |
|
|
415 | aio_proc (void *thr_arg) |
864 | static void *aio_proc (void *thr_arg) |
416 | { |
865 | { |
417 | aio_req req; |
866 | aio_req req; |
418 | int type; |
867 | int type; |
419 | |
868 | |
420 | do |
869 | do |
421 | { |
870 | { |
422 | pthread_mutex_lock (&reqlock); |
871 | pthread_mutex_lock (&reqlock); |
423 | |
872 | |
424 | for (;;) |
873 | for (;;) |
425 | { |
874 | { |
426 | req = reqs; |
875 | req = reqq_shift (&req_queue); |
427 | |
|
|
428 | if (reqs) |
|
|
429 | { |
|
|
430 | reqs = reqs->next; |
|
|
431 | if (!reqs) reqe = 0; |
|
|
432 | } |
|
|
433 | |
876 | |
434 | if (req) |
877 | if (req) |
435 | break; |
878 | break; |
436 | |
879 | |
437 | pthread_cond_wait (&reqwait, &reqlock); |
880 | pthread_cond_wait (&reqwait, &reqlock); |
438 | } |
881 | } |
439 | |
882 | |
440 | pthread_mutex_unlock (&reqlock); |
883 | pthread_mutex_unlock (&reqlock); |
441 | |
884 | |
442 | errno = 0; /* strictly unnecessary */ |
885 | errno = 0; /* strictly unnecessary */ |
|
|
886 | type = req->type; /* remember type for QUIT check */ |
443 | |
887 | |
444 | type = req->type; |
888 | if (!(req->flags & FLAG_CANCELLED)) |
445 | |
|
|
446 | switch (type) |
889 | switch (type) |
447 | { |
890 | { |
448 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
891 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
449 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
892 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
450 | |
893 | |
451 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
894 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
|
|
895 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
452 | |
896 | |
453 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
897 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
454 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
898 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
455 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
899 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
456 | |
900 | |
457 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
901 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
458 | case REQ_CLOSE: req->result = close (req->fd); break; |
902 | case REQ_CLOSE: req->result = close (req->fd); break; |
459 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
903 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
460 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
904 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
|
|
905 | case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; |
|
|
906 | case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; |
461 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
907 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
462 | |
908 | |
463 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
909 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
464 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
910 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
|
|
911 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
465 | |
912 | |
|
|
913 | case REQ_BUSY: |
|
|
914 | { |
|
|
915 | struct timeval tv; |
|
|
916 | |
|
|
917 | tv.tv_sec = req->fd; |
|
|
918 | tv.tv_usec = req->fd2; |
|
|
919 | |
|
|
920 | req->result = select (0, 0, 0, 0, &tv); |
|
|
921 | } |
|
|
922 | |
|
|
923 | case REQ_GROUP: |
|
|
924 | case REQ_NOP: |
466 | case REQ_QUIT: |
925 | case REQ_QUIT: |
467 | break; |
926 | break; |
468 | |
927 | |
469 | default: |
928 | default: |
470 | req->result = ENOSYS; |
929 | req->result = ENOSYS; |
471 | break; |
930 | break; |
472 | } |
931 | } |
473 | |
932 | |
474 | req->errorno = errno; |
933 | req->errorno = errno; |
475 | |
934 | |
476 | pthread_mutex_lock (&reslock); |
935 | pthread_mutex_lock (&reslock); |
477 | |
936 | |
478 | req->next = 0; |
937 | if (!reqq_push (&res_queue, req)) |
479 | |
|
|
480 | if (rese) |
|
|
481 | { |
|
|
482 | rese->next = req; |
|
|
483 | rese = req; |
|
|
484 | } |
|
|
485 | else |
|
|
486 | { |
|
|
487 | rese = ress = req; |
|
|
488 | |
|
|
489 | /* write a dummy byte to the pipe so fh becomes ready */ |
938 | /* write a dummy byte to the pipe so fh becomes ready */ |
490 | write (respipe [1], &respipe, 1); |
939 | write (respipe [1], &respipe, 1); |
491 | } |
|
|
492 | |
940 | |
493 | pthread_mutex_unlock (&reslock); |
941 | pthread_mutex_unlock (&reslock); |
494 | } |
942 | } |
495 | while (type != REQ_QUIT); |
943 | while (type != REQ_QUIT); |
496 | |
944 | |
497 | return 0; |
945 | return 0; |
|
|
946 | } |
|
|
947 | |
|
|
948 | /*****************************************************************************/ |
|
|
949 | |
|
|
950 | static void atfork_prepare (void) |
|
|
951 | { |
|
|
952 | pthread_mutex_lock (&reqlock); |
|
|
953 | pthread_mutex_lock (&reslock); |
|
|
954 | #if !HAVE_PREADWRITE |
|
|
955 | pthread_mutex_lock (&preadwritelock); |
|
|
956 | #endif |
|
|
957 | #if !HAVE_READDIR_R |
|
|
958 | pthread_mutex_lock (&readdirlock); |
|
|
959 | #endif |
|
|
960 | } |
|
|
961 | |
|
|
962 | static void atfork_parent (void) |
|
|
963 | { |
|
|
964 | #if !HAVE_READDIR_R |
|
|
965 | pthread_mutex_unlock (&readdirlock); |
|
|
966 | #endif |
|
|
967 | #if !HAVE_PREADWRITE |
|
|
968 | pthread_mutex_unlock (&preadwritelock); |
|
|
969 | #endif |
|
|
970 | pthread_mutex_unlock (&reslock); |
|
|
971 | pthread_mutex_unlock (&reqlock); |
|
|
972 | } |
|
|
973 | |
|
|
974 | static void atfork_child (void) |
|
|
975 | { |
|
|
976 | aio_req prv; |
|
|
977 | |
|
|
978 | started = 0; |
|
|
979 | |
|
|
980 | while (prv = reqq_shift (&req_queue)) |
|
|
981 | req_free (prv); |
|
|
982 | |
|
|
983 | while (prv = reqq_shift (&res_queue)) |
|
|
984 | req_free (prv); |
|
|
985 | |
|
|
986 | close (respipe [0]); |
|
|
987 | close (respipe [1]); |
|
|
988 | create_pipe (); |
|
|
989 | |
|
|
990 | atfork_parent (); |
498 | } |
991 | } |
499 | |
992 | |
500 | #define dREQ \ |
993 | #define dREQ \ |
501 | aio_req req; \ |
994 | aio_req req; \ |
|
|
995 | int req_pri = next_pri; \ |
|
|
996 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
502 | \ |
997 | \ |
503 | if (SvOK (callback) && !SvROK (callback)) \ |
998 | if (SvOK (callback) && !SvROK (callback)) \ |
504 | croak ("clalback must be undef or of reference type"); \ |
999 | croak ("callback must be undef or of reference type"); \ |
505 | \ |
1000 | \ |
506 | Newz (0, req, 1, aio_cb); \ |
1001 | Newz (0, req, 1, aio_cb); \ |
507 | if (!req) \ |
1002 | if (!req) \ |
508 | croak ("out of memory during aio_req allocation"); \ |
1003 | croak ("out of memory during aio_req allocation"); \ |
509 | \ |
1004 | \ |
510 | req->callback = newSVsv (callback); |
1005 | req->callback = newSVsv (callback); \ |
|
|
1006 | req->pri = req_pri |
|
|
1007 | |
|
|
1008 | #define REQ_SEND \ |
|
|
1009 | req_send (req); \ |
|
|
1010 | \ |
|
|
1011 | if (GIMME_V != G_VOID) \ |
|
|
1012 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
511 | |
1013 | |
512 | MODULE = IO::AIO PACKAGE = IO::AIO |
1014 | MODULE = IO::AIO PACKAGE = IO::AIO |
513 | |
1015 | |
514 | PROTOTYPES: ENABLE |
1016 | PROTOTYPES: ENABLE |
515 | |
1017 | |
516 | BOOT: |
1018 | BOOT: |
517 | { |
1019 | { |
|
|
1020 | HV *stash = gv_stashpv ("IO::AIO", 1); |
|
|
1021 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
|
|
1022 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
|
|
1023 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
|
|
1024 | |
518 | create_pipe (); |
1025 | create_pipe (); |
519 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
1026 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
520 | } |
1027 | } |
521 | |
1028 | |
522 | void |
1029 | void |
523 | min_parallel(nthreads) |
1030 | min_parallel (nthreads) |
524 | int nthreads |
1031 | int nthreads |
525 | PROTOTYPE: $ |
1032 | PROTOTYPE: $ |
526 | |
1033 | |
527 | void |
1034 | void |
528 | max_parallel(nthreads) |
1035 | max_parallel (nthreads) |
529 | int nthreads |
1036 | int nthreads |
530 | PROTOTYPE: $ |
1037 | PROTOTYPE: $ |
531 | |
1038 | |
532 | int |
1039 | int |
533 | max_outstanding(nreqs) |
1040 | max_outstanding (nreqs) |
534 | int nreqs |
1041 | int nreqs |
535 | PROTOTYPE: $ |
1042 | PROTOTYPE: $ |
536 | CODE: |
1043 | CODE: |
537 | RETVAL = max_outstanding; |
1044 | RETVAL = max_outstanding; |
538 | max_outstanding = nreqs; |
1045 | max_outstanding = nreqs; |
539 | |
1046 | |
540 | void |
1047 | void |
541 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
1048 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
542 | SV * pathname |
1049 | SV * pathname |
543 | int flags |
1050 | int flags |
544 | int mode |
1051 | int mode |
545 | SV * callback |
1052 | SV * callback |
546 | PROTOTYPE: $$$;$ |
1053 | PROTOTYPE: $$$;$ |
547 | CODE: |
1054 | PPCODE: |
548 | { |
1055 | { |
549 | dREQ; |
1056 | dREQ; |
550 | |
1057 | |
551 | req->type = REQ_OPEN; |
1058 | req->type = REQ_OPEN; |
552 | req->data = newSVsv (pathname); |
1059 | req->data = newSVsv (pathname); |
553 | req->dataptr = SvPVbyte_nolen (req->data); |
1060 | req->dataptr = SvPVbyte_nolen (req->data); |
554 | req->fd = flags; |
1061 | req->fd = flags; |
555 | req->mode = mode; |
1062 | req->mode = mode; |
556 | |
1063 | |
557 | send_req (req); |
1064 | REQ_SEND; |
558 | } |
1065 | } |
559 | |
1066 | |
560 | void |
1067 | void |
561 | aio_close(fh,callback=&PL_sv_undef) |
1068 | aio_close (fh,callback=&PL_sv_undef) |
562 | SV * fh |
1069 | SV * fh |
563 | SV * callback |
1070 | SV * callback |
564 | PROTOTYPE: $;$ |
1071 | PROTOTYPE: $;$ |
565 | ALIAS: |
1072 | ALIAS: |
566 | aio_close = REQ_CLOSE |
1073 | aio_close = REQ_CLOSE |
567 | aio_fsync = REQ_FSYNC |
1074 | aio_fsync = REQ_FSYNC |
568 | aio_fdatasync = REQ_FDATASYNC |
1075 | aio_fdatasync = REQ_FDATASYNC |
569 | CODE: |
1076 | PPCODE: |
570 | { |
1077 | { |
571 | dREQ; |
1078 | dREQ; |
572 | |
1079 | |
573 | req->type = ix; |
1080 | req->type = ix; |
574 | req->fh = newSVsv (fh); |
1081 | req->fh = newSVsv (fh); |
575 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1082 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
576 | |
1083 | |
577 | send_req (req); |
1084 | REQ_SEND (req); |
578 | } |
1085 | } |
579 | |
1086 | |
580 | void |
1087 | void |
581 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
1088 | aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
582 | SV * fh |
1089 | SV * fh |
583 | UV offset |
1090 | UV offset |
584 | IV length |
1091 | UV length |
585 | SV * data |
1092 | SV * data |
586 | IV dataoffset |
1093 | UV dataoffset |
587 | SV * callback |
1094 | SV * callback |
588 | ALIAS: |
1095 | ALIAS: |
589 | aio_read = REQ_READ |
1096 | aio_read = REQ_READ |
590 | aio_write = REQ_WRITE |
1097 | aio_write = REQ_WRITE |
591 | PROTOTYPE: $$$$$;$ |
1098 | PROTOTYPE: $$$$$;$ |
592 | CODE: |
1099 | PPCODE: |
593 | { |
1100 | { |
594 | aio_req req; |
1101 | aio_req req; |
595 | STRLEN svlen; |
1102 | STRLEN svlen; |
596 | char *svptr = SvPVbyte (data, svlen); |
1103 | char *svptr = SvPVbyte (data, svlen); |
597 | |
1104 | |
… | |
… | |
629 | req->offset = offset; |
1136 | req->offset = offset; |
630 | req->length = length; |
1137 | req->length = length; |
631 | req->data = SvREFCNT_inc (data); |
1138 | req->data = SvREFCNT_inc (data); |
632 | req->dataptr = (char *)svptr + dataoffset; |
1139 | req->dataptr = (char *)svptr + dataoffset; |
633 | |
1140 | |
634 | send_req (req); |
1141 | if (!SvREADONLY (data)) |
|
|
1142 | { |
|
|
1143 | SvREADONLY_on (data); |
|
|
1144 | req->data2ptr = (void *)data; |
|
|
1145 | } |
|
|
1146 | |
|
|
1147 | REQ_SEND; |
635 | } |
1148 | } |
636 | } |
1149 | } |
637 | |
1150 | |
638 | void |
1151 | void |
|
|
1152 | aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
|
|
1153 | SV * out_fh |
|
|
1154 | SV * in_fh |
|
|
1155 | UV in_offset |
|
|
1156 | UV length |
|
|
1157 | SV * callback |
|
|
1158 | PROTOTYPE: $$$$;$ |
|
|
1159 | PPCODE: |
|
|
1160 | { |
|
|
1161 | dREQ; |
|
|
1162 | |
|
|
1163 | req->type = REQ_SENDFILE; |
|
|
1164 | req->fh = newSVsv (out_fh); |
|
|
1165 | req->fd = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
|
|
1166 | req->fh2 = newSVsv (in_fh); |
|
|
1167 | req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
|
|
1168 | req->offset = in_offset; |
|
|
1169 | req->length = length; |
|
|
1170 | |
|
|
1171 | REQ_SEND; |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | void |
639 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
1175 | aio_readahead (fh,offset,length,callback=&PL_sv_undef) |
640 | SV * fh |
1176 | SV * fh |
641 | UV offset |
1177 | UV offset |
642 | IV length |
1178 | IV length |
643 | SV * callback |
1179 | SV * callback |
644 | PROTOTYPE: $$$;$ |
1180 | PROTOTYPE: $$$;$ |
645 | CODE: |
1181 | PPCODE: |
646 | { |
1182 | { |
647 | dREQ; |
1183 | dREQ; |
648 | |
1184 | |
649 | req->type = REQ_READAHEAD; |
1185 | req->type = REQ_READAHEAD; |
650 | req->fh = newSVsv (fh); |
1186 | req->fh = newSVsv (fh); |
651 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1187 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
652 | req->offset = offset; |
1188 | req->offset = offset; |
653 | req->length = length; |
1189 | req->length = length; |
654 | |
1190 | |
655 | send_req (req); |
1191 | REQ_SEND; |
656 | } |
1192 | } |
657 | |
1193 | |
658 | void |
1194 | void |
659 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
1195 | aio_stat (fh_or_path,callback=&PL_sv_undef) |
660 | SV * fh_or_path |
1196 | SV * fh_or_path |
661 | SV * callback |
1197 | SV * callback |
662 | ALIAS: |
1198 | ALIAS: |
663 | aio_stat = REQ_STAT |
1199 | aio_stat = REQ_STAT |
664 | aio_lstat = REQ_LSTAT |
1200 | aio_lstat = REQ_LSTAT |
665 | CODE: |
1201 | PPCODE: |
666 | { |
1202 | { |
667 | dREQ; |
1203 | dREQ; |
668 | |
1204 | |
669 | New (0, req->statdata, 1, Stat_t); |
1205 | New (0, req->statdata, 1, Stat_t); |
670 | if (!req->statdata) |
1206 | if (!req->statdata) |
671 | { |
1207 | { |
672 | free_req (req); |
1208 | req_free (req); |
673 | croak ("out of memory during aio_req->statdata allocation"); |
1209 | croak ("out of memory during aio_req->statdata allocation"); |
674 | } |
1210 | } |
675 | |
1211 | |
676 | if (SvPOK (fh_or_path)) |
1212 | if (SvPOK (fh_or_path)) |
677 | { |
1213 | { |
… | |
… | |
684 | req->type = REQ_FSTAT; |
1220 | req->type = REQ_FSTAT; |
685 | req->fh = newSVsv (fh_or_path); |
1221 | req->fh = newSVsv (fh_or_path); |
686 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1222 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
687 | } |
1223 | } |
688 | |
1224 | |
689 | send_req (req); |
1225 | REQ_SEND; |
690 | } |
1226 | } |
691 | |
1227 | |
692 | void |
1228 | void |
693 | aio_unlink(pathname,callback=&PL_sv_undef) |
1229 | aio_unlink (pathname,callback=&PL_sv_undef) |
694 | SV * pathname |
1230 | SV * pathname |
695 | SV * callback |
1231 | SV * callback |
696 | ALIAS: |
1232 | ALIAS: |
697 | aio_unlink = REQ_UNLINK |
1233 | aio_unlink = REQ_UNLINK |
698 | aio_rmdir = REQ_RMDIR |
1234 | aio_rmdir = REQ_RMDIR |
|
|
1235 | aio_readdir = REQ_READDIR |
699 | CODE: |
1236 | PPCODE: |
700 | { |
1237 | { |
701 | dREQ; |
1238 | dREQ; |
702 | |
1239 | |
703 | req->type = ix; |
1240 | req->type = ix; |
704 | req->data = newSVsv (pathname); |
1241 | req->data = newSVsv (pathname); |
705 | req->dataptr = SvPVbyte_nolen (req->data); |
1242 | req->dataptr = SvPVbyte_nolen (req->data); |
706 | |
1243 | |
707 | send_req (req); |
1244 | REQ_SEND; |
708 | } |
1245 | } |
709 | |
1246 | |
710 | void |
1247 | void |
711 | aio_symlink(oldpath,newpath,callback=&PL_sv_undef) |
1248 | aio_link (oldpath,newpath,callback=&PL_sv_undef) |
712 | SV * oldpath |
1249 | SV * oldpath |
713 | SV * newpath |
1250 | SV * newpath |
714 | SV * callback |
1251 | SV * callback |
|
|
1252 | ALIAS: |
|
|
1253 | aio_link = REQ_LINK |
|
|
1254 | aio_symlink = REQ_SYMLINK |
|
|
1255 | aio_rename = REQ_RENAME |
715 | CODE: |
1256 | PPCODE: |
716 | { |
1257 | { |
717 | dREQ; |
1258 | dREQ; |
718 | |
1259 | |
719 | req->type = REQ_SYMLINK; |
1260 | req->type = ix; |
720 | req->fh = newSVsv (oldpath); |
1261 | req->fh = newSVsv (oldpath); |
721 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1262 | req->data2ptr = SvPVbyte_nolen (req->fh); |
722 | req->data = newSVsv (newpath); |
1263 | req->data = newSVsv (newpath); |
723 | req->dataptr = SvPVbyte_nolen (req->data); |
1264 | req->dataptr = SvPVbyte_nolen (req->data); |
724 | |
1265 | |
725 | send_req (req); |
1266 | REQ_SEND; |
726 | } |
1267 | } |
727 | |
1268 | |
728 | void |
1269 | void |
|
|
1270 | aio_busy (delay,callback=&PL_sv_undef) |
|
|
1271 | double delay |
|
|
1272 | SV * callback |
|
|
1273 | PPCODE: |
|
|
1274 | { |
|
|
1275 | dREQ; |
|
|
1276 | |
|
|
1277 | req->type = REQ_BUSY; |
|
|
1278 | req->fd = delay < 0. ? 0 : delay; |
|
|
1279 | req->fd2 = delay < 0. ? 0 : 1000. * (delay - req->fd); |
|
|
1280 | |
|
|
1281 | REQ_SEND; |
|
|
1282 | } |
|
|
1283 | |
|
|
1284 | void |
|
|
1285 | aio_group (callback=&PL_sv_undef) |
|
|
1286 | SV * callback |
|
|
1287 | PROTOTYPE: ;$ |
|
|
1288 | PPCODE: |
|
|
1289 | { |
|
|
1290 | dREQ; |
|
|
1291 | |
|
|
1292 | req->type = REQ_GROUP; |
|
|
1293 | req_send (req); |
|
|
1294 | |
|
|
1295 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
|
|
1296 | } |
|
|
1297 | |
|
|
1298 | void |
|
|
1299 | aio_nop (callback=&PL_sv_undef) |
|
|
1300 | SV * callback |
|
|
1301 | PPCODE: |
|
|
1302 | { |
|
|
1303 | dREQ; |
|
|
1304 | |
|
|
1305 | req->type = REQ_NOP; |
|
|
1306 | |
|
|
1307 | REQ_SEND; |
|
|
1308 | } |
|
|
1309 | |
|
|
1310 | void |
|
|
1311 | aioreq_pri (int pri = DEFAULT_PRI) |
|
|
1312 | CODE: |
|
|
1313 | if (pri < PRI_MIN) pri = PRI_MIN; |
|
|
1314 | if (pri > PRI_MAX) pri = PRI_MAX; |
|
|
1315 | next_pri = pri + PRI_BIAS; |
|
|
1316 | |
|
|
1317 | void |
|
|
1318 | aioreq_nice (int nice = 0) |
|
|
1319 | CODE: |
|
|
1320 | nice = next_pri - nice; |
|
|
1321 | if (nice < PRI_MIN) nice = PRI_MIN; |
|
|
1322 | if (nice > PRI_MAX) nice = PRI_MAX; |
|
|
1323 | next_pri = nice + PRI_BIAS; |
|
|
1324 | |
|
|
1325 | void |
729 | flush() |
1326 | flush () |
730 | PROTOTYPE: |
1327 | PROTOTYPE: |
731 | CODE: |
1328 | CODE: |
732 | while (nreqs) |
1329 | while (nreqs) |
733 | { |
1330 | { |
734 | poll_wait (); |
1331 | poll_wait (); |
… | |
… | |
774 | CODE: |
1371 | CODE: |
775 | RETVAL = nreqs; |
1372 | RETVAL = nreqs; |
776 | OUTPUT: |
1373 | OUTPUT: |
777 | RETVAL |
1374 | RETVAL |
778 | |
1375 | |
|
|
1376 | PROTOTYPES: DISABLE |
|
|
1377 | |
|
|
1378 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
|
|
1379 | |
|
|
1380 | void |
|
|
1381 | cancel (aio_req_ornot req) |
|
|
1382 | CODE: |
|
|
1383 | req_cancel (req); |
|
|
1384 | |
|
|
1385 | void |
|
|
1386 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
|
|
1387 | CODE: |
|
|
1388 | SvREFCNT_dec (req->callback); |
|
|
1389 | req->callback = newSVsv (callback); |
|
|
1390 | |
|
|
1391 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
|
|
1392 | |
|
|
1393 | void |
|
|
1394 | add (aio_req grp, ...) |
|
|
1395 | PPCODE: |
|
|
1396 | { |
|
|
1397 | int i; |
|
|
1398 | aio_req req; |
|
|
1399 | |
|
|
1400 | if (grp->fd == 2) |
|
|
1401 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
|
|
1402 | |
|
|
1403 | for (i = 1; i < items; ++i ) |
|
|
1404 | { |
|
|
1405 | if (GIMME_V != G_VOID) |
|
|
1406 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
|
|
1407 | |
|
|
1408 | req = SvAIO_REQ (ST (i)); |
|
|
1409 | |
|
|
1410 | if (req) |
|
|
1411 | { |
|
|
1412 | ++grp->length; |
|
|
1413 | req->grp = grp; |
|
|
1414 | |
|
|
1415 | req->grp_prev = 0; |
|
|
1416 | req->grp_next = grp->grp_first; |
|
|
1417 | |
|
|
1418 | if (grp->grp_first) |
|
|
1419 | grp->grp_first->grp_prev = req; |
|
|
1420 | |
|
|
1421 | grp->grp_first = req; |
|
|
1422 | } |
|
|
1423 | } |
|
|
1424 | } |
|
|
1425 | |
|
|
1426 | void |
|
|
1427 | result (aio_req grp, ...) |
|
|
1428 | CODE: |
|
|
1429 | { |
|
|
1430 | int i; |
|
|
1431 | AV *av = newAV (); |
|
|
1432 | |
|
|
1433 | for (i = 1; i < items; ++i ) |
|
|
1434 | av_push (av, newSVsv (ST (i))); |
|
|
1435 | |
|
|
1436 | SvREFCNT_dec (grp->data); |
|
|
1437 | grp->data = (SV *)av; |
|
|
1438 | } |
|
|
1439 | |
|
|
1440 | void |
|
|
1441 | limit (aio_req grp, int limit) |
|
|
1442 | CODE: |
|
|
1443 | grp->fd2 = limit; |
|
|
1444 | aio_grp_feed (grp); |
|
|
1445 | |
|
|
1446 | void |
|
|
1447 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
|
|
1448 | CODE: |
|
|
1449 | { |
|
|
1450 | SvREFCNT_dec (grp->fh2); |
|
|
1451 | grp->fh2 = newSVsv (callback); |
|
|
1452 | |
|
|
1453 | if (grp->fd2 <= 0) |
|
|
1454 | grp->fd2 = 2; |
|
|
1455 | |
|
|
1456 | aio_grp_feed (grp); |
|
|
1457 | } |
|
|
1458 | |