|
|
1 | /* solaris */ |
|
|
2 | #define _POSIX_PTHREAD_SEMANTICS 1 |
|
|
3 | |
|
|
4 | #if __linux && !defined(_GNU_SOURCE) |
|
|
5 | # define _GNU_SOURCE |
|
|
6 | #endif |
|
|
7 | |
|
|
8 | /* just in case */ |
1 | #define _REENTRANT 1 |
9 | #define _REENTRANT 1 |
|
|
10 | |
2 | #include <errno.h> |
11 | #include <errno.h> |
3 | |
12 | |
4 | #include "EXTERN.h" |
13 | #include "EXTERN.h" |
5 | #include "perl.h" |
14 | #include "perl.h" |
6 | #include "XSUB.h" |
15 | #include "XSUB.h" |
… | |
… | |
34 | # else |
43 | # else |
35 | # error sendfile support requested but not available |
44 | # error sendfile support requested but not available |
36 | # endif |
45 | # endif |
37 | #endif |
46 | #endif |
38 | |
47 | |
|
|
48 | /* number of seconds after which idle threads exit */ |
|
|
49 | #define IDLE_TIMEOUT 10 |
|
|
50 | |
39 | /* used for struct dirent, AIX doesn't provide it */ |
51 | /* used for struct dirent, AIX doesn't provide it */ |
40 | #ifndef NAME_MAX |
52 | #ifndef NAME_MAX |
41 | # define NAME_MAX 4096 |
53 | # define NAME_MAX 4096 |
42 | #endif |
54 | #endif |
43 | |
55 | |
|
|
56 | #ifndef PTHREAD_STACK_MIN |
|
|
57 | /* care for broken platforms, e.g. windows */ |
|
|
58 | # define PTHREAD_STACK_MIN 16384 |
|
|
59 | #endif |
|
|
60 | |
44 | #if __ia64 |
61 | #if __ia64 |
45 | # define STACKSIZE 65536 |
62 | # define STACKSIZE 65536 |
|
|
63 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
|
|
64 | # define STACKSIZE PTHREAD_STACK_MIN |
46 | #else |
65 | #else |
47 | # define STACKSIZE 8192 |
66 | # define STACKSIZE 16384 |
|
|
67 | #endif |
|
|
68 | |
|
|
69 | /* wether word reads are potentially non-atomic. |
|
|
70 | * this is conservatice, likely most arches this runs |
|
|
71 | * on have atomic word read/writes. |
|
|
72 | */ |
|
|
73 | #ifndef WORDREAD_UNSAFE |
|
|
74 | # if __i386 || __x86_64 |
|
|
75 | # define WORDREAD_UNSAFE 0 |
|
|
76 | # else |
|
|
77 | # define WORDREAD_UNSAFE 1 |
48 | #endif |
78 | # endif |
|
|
79 | #endif |
|
|
80 | |
|
|
81 | /* buffer size for various temporary buffers */ |
|
|
82 | #define AIO_BUFSIZE 65536 |
|
|
83 | |
|
|
84 | #define dBUF \ |
|
|
85 | char *aio_buf; \ |
|
|
86 | LOCK (wrklock); \ |
|
|
87 | self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \ |
|
|
88 | UNLOCK (wrklock); \ |
|
|
89 | if (!aio_buf) \ |
|
|
90 | return -1; |
49 | |
91 | |
50 | enum { |
92 | enum { |
51 | REQ_QUIT, |
93 | REQ_QUIT, |
52 | REQ_OPEN, REQ_CLOSE, |
94 | REQ_OPEN, REQ_CLOSE, |
53 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
95 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
54 | REQ_SENDFILE, |
96 | REQ_SENDFILE, |
55 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
97 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
56 | REQ_FSYNC, REQ_FDATASYNC, |
98 | REQ_FSYNC, REQ_FDATASYNC, |
57 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
99 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
58 | REQ_READDIR, |
100 | REQ_MKNOD, REQ_READDIR, |
59 | REQ_LINK, REQ_SYMLINK, |
101 | REQ_LINK, REQ_SYMLINK, |
60 | REQ_GROUP, REQ_NOP, |
102 | REQ_GROUP, REQ_NOP, |
61 | REQ_SLEEP, |
103 | REQ_BUSY, |
62 | }; |
104 | }; |
63 | |
105 | |
64 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
106 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
65 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
107 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
66 | |
108 | |
… | |
… | |
100 | PRI_MIN = -4, |
142 | PRI_MIN = -4, |
101 | PRI_MAX = 4, |
143 | PRI_MAX = 4, |
102 | |
144 | |
103 | DEFAULT_PRI = 0, |
145 | DEFAULT_PRI = 0, |
104 | PRI_BIAS = -PRI_MIN, |
146 | PRI_BIAS = -PRI_MIN, |
|
|
147 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
105 | }; |
148 | }; |
106 | |
149 | |
107 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
150 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
108 | |
151 | |
109 | static int started, wanted; |
152 | static unsigned int started, idle, wanted; |
110 | static volatile int nreqs; |
153 | |
111 | static int max_outstanding = 1<<30; |
154 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
|
|
155 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
|
|
156 | #else |
|
|
157 | # define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|
|
158 | #endif |
|
|
159 | |
|
|
160 | #define LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|
|
161 | #define UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
|
|
162 | |
|
|
163 | /* worker threads management */ |
|
|
164 | static pthread_mutex_t wrklock = AIO_MUTEX_INIT; |
|
|
165 | |
|
|
166 | typedef struct worker { |
|
|
167 | /* locked by wrklock */ |
|
|
168 | struct worker *prev, *next; |
|
|
169 | |
|
|
170 | pthread_t tid; |
|
|
171 | |
|
|
172 | /* locked by reslock, reqlock or wrklock */ |
|
|
173 | aio_req req; /* currently processed request */ |
|
|
174 | void *dbuf; |
|
|
175 | DIR *dirp; |
|
|
176 | } worker; |
|
|
177 | |
|
|
178 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; |
|
|
179 | |
|
|
180 | static void worker_clear (worker *wrk) |
|
|
181 | { |
|
|
182 | if (wrk->dirp) |
|
|
183 | { |
|
|
184 | closedir (wrk->dirp); |
|
|
185 | wrk->dirp = 0; |
|
|
186 | } |
|
|
187 | |
|
|
188 | if (wrk->dbuf) |
|
|
189 | { |
|
|
190 | free (wrk->dbuf); |
|
|
191 | wrk->dbuf = 0; |
|
|
192 | } |
|
|
193 | } |
|
|
194 | |
|
|
195 | static void worker_free (worker *wrk) |
|
|
196 | { |
|
|
197 | wrk->next->prev = wrk->prev; |
|
|
198 | wrk->prev->next = wrk->next; |
|
|
199 | |
|
|
200 | free (wrk); |
|
|
201 | } |
|
|
202 | |
|
|
203 | static volatile unsigned int nreqs, nready, npending; |
|
|
204 | static volatile unsigned int max_idle = 4; |
|
|
205 | static volatile unsigned int max_outstanding = 0xffffffff; |
112 | static int respipe [2]; |
206 | static int respipe [2]; |
113 | |
207 | |
114 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
208 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
115 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
209 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
116 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
210 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
117 | |
211 | |
118 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
212 | #if WORDREAD_UNSAFE |
119 | static volatile aio_req ress, rese; /* queue start, queue end */ |
|
|
120 | |
213 | |
|
|
214 | static unsigned int get_nready () |
|
|
215 | { |
|
|
216 | unsigned int retval; |
|
|
217 | |
|
|
218 | LOCK (reqlock); |
|
|
219 | retval = nready; |
|
|
220 | UNLOCK (reqlock); |
|
|
221 | |
|
|
222 | return retval; |
|
|
223 | } |
|
|
224 | |
|
|
225 | static unsigned int get_npending () |
|
|
226 | { |
|
|
227 | unsigned int retval; |
|
|
228 | |
|
|
229 | LOCK (reslock); |
|
|
230 | retval = npending; |
|
|
231 | UNLOCK (reslock); |
|
|
232 | |
|
|
233 | return retval; |
|
|
234 | } |
|
|
235 | |
|
|
236 | #else |
|
|
237 | |
|
|
238 | # define get_nready() nready |
|
|
239 | # define get_npending() npending |
|
|
240 | |
|
|
241 | #endif |
|
|
242 | |
|
|
243 | /* |
|
|
244 | * a somewhat faster data structure might be nice, but |
|
|
245 | * with 8 priorities this actually needs <20 insns |
|
|
246 | * per shift, the most expensive operation. |
|
|
247 | */ |
|
|
248 | typedef struct { |
|
|
249 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
|
|
250 | int size; |
|
|
251 | } reqq; |
|
|
252 | |
|
|
253 | static reqq req_queue; |
|
|
254 | static reqq res_queue; |
|
|
255 | |
|
|
256 | int reqq_push (reqq *q, aio_req req) |
|
|
257 | { |
|
|
258 | int pri = req->pri; |
|
|
259 | req->next = 0; |
|
|
260 | |
|
|
261 | if (q->qe[pri]) |
|
|
262 | { |
|
|
263 | q->qe[pri]->next = req; |
|
|
264 | q->qe[pri] = req; |
|
|
265 | } |
|
|
266 | else |
|
|
267 | q->qe[pri] = q->qs[pri] = req; |
|
|
268 | |
|
|
269 | return q->size++; |
|
|
270 | } |
|
|
271 | |
|
|
272 | aio_req reqq_shift (reqq *q) |
|
|
273 | { |
|
|
274 | int pri; |
|
|
275 | |
|
|
276 | if (!q->size) |
|
|
277 | return 0; |
|
|
278 | |
|
|
279 | --q->size; |
|
|
280 | |
|
|
281 | for (pri = NUM_PRI; pri--; ) |
|
|
282 | { |
|
|
283 | aio_req req = q->qs[pri]; |
|
|
284 | |
|
|
285 | if (req) |
|
|
286 | { |
|
|
287 | if (!(q->qs[pri] = req->next)) |
|
|
288 | q->qe[pri] = 0; |
|
|
289 | |
|
|
290 | return req; |
|
|
291 | } |
|
|
292 | } |
|
|
293 | |
|
|
294 | abort (); |
|
|
295 | } |
|
|
296 | |
|
|
297 | static int poll_cb (int max); |
121 | static void req_invoke (aio_req req); |
298 | static void req_invoke (aio_req req); |
122 | static void req_free (aio_req req); |
299 | static void req_free (aio_req req); |
|
|
300 | static void req_cancel (aio_req req); |
123 | |
301 | |
124 | /* must be called at most once */ |
302 | /* must be called at most once */ |
125 | static SV *req_sv (aio_req req, const char *klass) |
303 | static SV *req_sv (aio_req req, const char *klass) |
126 | { |
304 | { |
127 | if (!req->self) |
305 | if (!req->self) |
… | |
… | |
158 | ENTER; |
336 | ENTER; |
159 | SAVETMPS; |
337 | SAVETMPS; |
160 | PUSHMARK (SP); |
338 | PUSHMARK (SP); |
161 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
339 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
162 | PUTBACK; |
340 | PUTBACK; |
163 | call_sv (grp->fh2, G_VOID | G_EVAL); |
341 | call_sv (grp->fh2, G_VOID | G_EVAL | G_KEEPERR); |
164 | SPAGAIN; |
342 | SPAGAIN; |
165 | FREETMPS; |
343 | FREETMPS; |
166 | LEAVE; |
344 | LEAVE; |
167 | } |
345 | } |
168 | |
346 | |
… | |
… | |
189 | req_invoke (grp); |
367 | req_invoke (grp); |
190 | req_free (grp); |
368 | req_free (grp); |
191 | } |
369 | } |
192 | } |
370 | } |
193 | |
371 | |
194 | static void poll_wait () |
|
|
195 | { |
|
|
196 | while (nreqs) |
|
|
197 | { |
|
|
198 | aio_req req; |
|
|
199 | pthread_mutex_lock (&reslock); |
|
|
200 | req = ress; |
|
|
201 | pthread_mutex_unlock (&reslock); |
|
|
202 | |
|
|
203 | if (req) |
|
|
204 | return; |
|
|
205 | |
|
|
206 | fd_set rfd; |
|
|
207 | FD_ZERO(&rfd); |
|
|
208 | FD_SET(respipe [0], &rfd); |
|
|
209 | |
|
|
210 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
211 | } |
|
|
212 | } |
|
|
213 | |
|
|
214 | static void req_invoke (aio_req req) |
372 | static void req_invoke (aio_req req) |
215 | { |
373 | { |
216 | dSP; |
374 | dSP; |
217 | int errorno = errno; |
|
|
218 | |
375 | |
219 | if (req->flags & FLAG_CANCELLED || !SvOK (req->callback)) |
376 | if (!(req->flags & FLAG_CANCELLED) && SvOK (req->callback)) |
220 | return; |
377 | { |
221 | |
|
|
222 | errno = req->errorno; |
|
|
223 | |
|
|
224 | ENTER; |
378 | ENTER; |
225 | SAVETMPS; |
379 | SAVETMPS; |
226 | PUSHMARK (SP); |
380 | PUSHMARK (SP); |
227 | EXTEND (SP, 1); |
381 | EXTEND (SP, 1); |
228 | |
382 | |
229 | switch (req->type) |
383 | switch (req->type) |
230 | { |
|
|
231 | case REQ_READDIR: |
|
|
232 | { |
384 | { |
233 | SV *rv = &PL_sv_undef; |
385 | case REQ_READDIR: |
234 | |
|
|
235 | if (req->result >= 0) |
|
|
236 | { |
386 | { |
237 | char *buf = req->data2ptr; |
387 | SV *rv = &PL_sv_undef; |
238 | AV *av = newAV (); |
|
|
239 | |
388 | |
240 | while (req->result) |
389 | if (req->result >= 0) |
241 | { |
390 | { |
|
|
391 | int i; |
|
|
392 | char *buf = req->data2ptr; |
|
|
393 | AV *av = newAV (); |
|
|
394 | |
|
|
395 | av_extend (av, req->result - 1); |
|
|
396 | |
|
|
397 | for (i = 0; i < req->result; ++i) |
|
|
398 | { |
242 | SV *sv = newSVpv (buf, 0); |
399 | SV *sv = newSVpv (buf, 0); |
243 | |
400 | |
244 | av_push (av, sv); |
401 | av_store (av, i, sv); |
245 | buf += SvCUR (sv) + 1; |
402 | buf += SvCUR (sv) + 1; |
246 | req->result--; |
403 | } |
|
|
404 | |
|
|
405 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
247 | } |
406 | } |
248 | |
407 | |
249 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
408 | PUSHs (rv); |
250 | } |
409 | } |
|
|
410 | break; |
251 | |
411 | |
252 | PUSHs (rv); |
412 | case REQ_OPEN: |
|
|
413 | { |
|
|
414 | /* convert fd to fh */ |
|
|
415 | SV *fh; |
|
|
416 | |
|
|
417 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
418 | PUTBACK; |
|
|
419 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
420 | SPAGAIN; |
|
|
421 | |
|
|
422 | fh = SvREFCNT_inc (POPs); |
|
|
423 | |
|
|
424 | PUSHMARK (SP); |
|
|
425 | XPUSHs (sv_2mortal (fh)); |
|
|
426 | } |
|
|
427 | break; |
|
|
428 | |
|
|
429 | case REQ_GROUP: |
|
|
430 | req->fd = 2; /* mark group as finished */ |
|
|
431 | |
|
|
432 | if (req->data) |
|
|
433 | { |
|
|
434 | int i; |
|
|
435 | AV *av = (AV *)req->data; |
|
|
436 | |
|
|
437 | EXTEND (SP, AvFILL (av) + 1); |
|
|
438 | for (i = 0; i <= AvFILL (av); ++i) |
|
|
439 | PUSHs (*av_fetch (av, i, 0)); |
|
|
440 | } |
|
|
441 | break; |
|
|
442 | |
|
|
443 | case REQ_NOP: |
|
|
444 | case REQ_BUSY: |
|
|
445 | break; |
|
|
446 | |
|
|
447 | default: |
|
|
448 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
449 | break; |
253 | } |
450 | } |
254 | break; |
|
|
255 | |
451 | |
256 | case REQ_OPEN: |
452 | errno = req->errorno; |
257 | { |
|
|
258 | /* convert fd to fh */ |
|
|
259 | SV *fh; |
|
|
260 | |
453 | |
261 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
262 | PUTBACK; |
454 | PUTBACK; |
263 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
264 | SPAGAIN; |
|
|
265 | |
|
|
266 | fh = SvREFCNT_inc (POPs); |
|
|
267 | |
|
|
268 | PUSHMARK (SP); |
|
|
269 | XPUSHs (sv_2mortal (fh)); |
|
|
270 | } |
|
|
271 | break; |
|
|
272 | |
|
|
273 | case REQ_GROUP: |
|
|
274 | req->fd = 2; /* mark group as finished */ |
|
|
275 | |
|
|
276 | if (req->data) |
|
|
277 | { |
|
|
278 | int i; |
|
|
279 | AV *av = (AV *)req->data; |
|
|
280 | |
|
|
281 | EXTEND (SP, AvFILL (av) + 1); |
|
|
282 | for (i = 0; i <= AvFILL (av); ++i) |
|
|
283 | PUSHs (*av_fetch (av, i, 0)); |
|
|
284 | } |
|
|
285 | break; |
|
|
286 | |
|
|
287 | case REQ_NOP: |
|
|
288 | case REQ_SLEEP: |
|
|
289 | break; |
|
|
290 | |
|
|
291 | default: |
|
|
292 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
293 | break; |
|
|
294 | } |
|
|
295 | |
|
|
296 | |
|
|
297 | PUTBACK; |
|
|
298 | call_sv (req->callback, G_VOID | G_EVAL); |
455 | call_sv (req->callback, G_VOID | G_EVAL); |
299 | SPAGAIN; |
456 | SPAGAIN; |
300 | |
457 | |
301 | FREETMPS; |
458 | FREETMPS; |
302 | LEAVE; |
459 | LEAVE; |
303 | |
|
|
304 | errno = errorno; |
|
|
305 | |
|
|
306 | if (SvTRUE (ERRSV)) |
|
|
307 | { |
460 | } |
308 | req_free (req); |
|
|
309 | croak (0); |
|
|
310 | } |
|
|
311 | } |
|
|
312 | |
461 | |
313 | static void req_free (aio_req req) |
|
|
314 | { |
|
|
315 | if (req->grp) |
462 | if (req->grp) |
316 | { |
463 | { |
317 | aio_req grp = req->grp; |
464 | aio_req grp = req->grp; |
318 | |
465 | |
319 | /* unlink request */ |
466 | /* unlink request */ |
… | |
… | |
324 | grp->grp_first = req->grp_next; |
471 | grp->grp_first = req->grp_next; |
325 | |
472 | |
326 | aio_grp_dec (grp); |
473 | aio_grp_dec (grp); |
327 | } |
474 | } |
328 | |
475 | |
|
|
476 | if (SvTRUE (ERRSV)) |
|
|
477 | { |
|
|
478 | req_free (req); |
|
|
479 | croak (0); |
|
|
480 | } |
|
|
481 | } |
|
|
482 | |
|
|
483 | static void req_free (aio_req req) |
|
|
484 | { |
329 | if (req->self) |
485 | if (req->self) |
330 | { |
486 | { |
331 | sv_unmagic (req->self, PERL_MAGIC_ext); |
487 | sv_unmagic (req->self, PERL_MAGIC_ext); |
332 | SvREFCNT_dec (req->self); |
488 | SvREFCNT_dec (req->self); |
333 | } |
489 | } |
… | |
… | |
336 | SvREFCNT_dec (req->fh); |
492 | SvREFCNT_dec (req->fh); |
337 | SvREFCNT_dec (req->fh2); |
493 | SvREFCNT_dec (req->fh2); |
338 | SvREFCNT_dec (req->callback); |
494 | SvREFCNT_dec (req->callback); |
339 | Safefree (req->statdata); |
495 | Safefree (req->statdata); |
340 | |
496 | |
341 | if (req->type == REQ_READDIR && req->result >= 0) |
497 | if (req->type == REQ_READDIR) |
342 | free (req->data2ptr); |
498 | free (req->data2ptr); |
343 | |
499 | |
344 | Safefree (req); |
500 | Safefree (req); |
345 | } |
501 | } |
346 | |
502 | |
|
|
503 | static void req_cancel_subs (aio_req grp) |
|
|
504 | { |
|
|
505 | aio_req sub; |
|
|
506 | |
|
|
507 | if (grp->type != REQ_GROUP) |
|
|
508 | return; |
|
|
509 | |
|
|
510 | SvREFCNT_dec (grp->fh2); |
|
|
511 | grp->fh2 = 0; |
|
|
512 | |
|
|
513 | for (sub = grp->grp_first; sub; sub = sub->grp_next) |
|
|
514 | req_cancel (sub); |
|
|
515 | } |
|
|
516 | |
347 | static void req_cancel (aio_req req) |
517 | static void req_cancel (aio_req req) |
348 | { |
518 | { |
349 | req->flags |= FLAG_CANCELLED; |
519 | req->flags |= FLAG_CANCELLED; |
350 | |
520 | |
351 | if (req->type == REQ_GROUP) |
521 | req_cancel_subs (req); |
352 | { |
522 | } |
353 | aio_req sub; |
|
|
354 | |
523 | |
355 | for (sub = req->grp_first; sub; sub = sub->grp_next) |
524 | static void *aio_proc(void *arg); |
356 | req_cancel (sub); |
525 | |
|
|
526 | static void start_thread (void) |
|
|
527 | { |
|
|
528 | sigset_t fullsigset, oldsigset; |
|
|
529 | pthread_attr_t attr; |
|
|
530 | |
|
|
531 | worker *wrk = calloc (1, sizeof (worker)); |
|
|
532 | |
|
|
533 | if (!wrk) |
|
|
534 | croak ("unable to allocate worker thread data"); |
|
|
535 | |
|
|
536 | pthread_attr_init (&attr); |
|
|
537 | pthread_attr_setstacksize (&attr, STACKSIZE); |
|
|
538 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|
|
539 | #ifdef PTHREAD_SCOPE_PROCESS |
|
|
540 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
|
|
541 | #endif |
|
|
542 | |
|
|
543 | sigfillset (&fullsigset); |
|
|
544 | |
|
|
545 | LOCK (wrklock); |
|
|
546 | sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset); |
|
|
547 | |
|
|
548 | if (pthread_create (&wrk->tid, &attr, aio_proc, (void *)wrk) == 0) |
357 | } |
549 | { |
358 | } |
550 | wrk->prev = &wrk_first; |
|
|
551 | wrk->next = wrk_first.next; |
|
|
552 | wrk_first.next->prev = wrk; |
|
|
553 | wrk_first.next = wrk; |
|
|
554 | ++started; |
|
|
555 | } |
|
|
556 | else |
|
|
557 | free (wrk); |
359 | |
558 | |
|
|
559 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
|
|
560 | UNLOCK (wrklock); |
|
|
561 | } |
|
|
562 | |
|
|
563 | static void maybe_start_thread () |
|
|
564 | { |
|
|
565 | if (started >= wanted) |
|
|
566 | return; |
|
|
567 | |
|
|
568 | /* todo: maybe use idle here, but might be less exact */ |
|
|
569 | if ((int)nready <= (int)started - (int)(nreqs - get_nready () - get_npending ())) |
|
|
570 | return; |
|
|
571 | |
|
|
572 | start_thread (); |
|
|
573 | } |
|
|
574 | |
|
|
575 | static void req_send (aio_req req) |
|
|
576 | { |
|
|
577 | ++nreqs; |
|
|
578 | |
|
|
579 | LOCK (reqlock); |
|
|
580 | ++nready; |
|
|
581 | reqq_push (&req_queue, req); |
|
|
582 | pthread_cond_signal (&reqwait); |
|
|
583 | UNLOCK (reqlock); |
|
|
584 | |
|
|
585 | maybe_start_thread (); |
|
|
586 | } |
|
|
587 | |
|
|
588 | static void end_thread (void) |
|
|
589 | { |
|
|
590 | aio_req req; |
|
|
591 | |
|
|
592 | Newz (0, req, 1, aio_cb); |
|
|
593 | |
|
|
594 | req->type = REQ_QUIT; |
|
|
595 | req->pri = PRI_MAX + PRI_BIAS; |
|
|
596 | |
|
|
597 | LOCK (reqlock); |
|
|
598 | reqq_push (&req_queue, req); |
|
|
599 | pthread_cond_signal (&reqwait); |
|
|
600 | UNLOCK (reqlock); |
|
|
601 | |
|
|
602 | LOCK (wrklock); |
|
|
603 | --started; |
|
|
604 | UNLOCK (wrklock); |
|
|
605 | } |
|
|
606 | |
|
|
607 | static void min_parallel (int nthreads) |
|
|
608 | { |
|
|
609 | if (wanted < nthreads) |
|
|
610 | wanted = nthreads; |
|
|
611 | } |
|
|
612 | |
|
|
613 | static void max_parallel (int nthreads) |
|
|
614 | { |
|
|
615 | if (wanted > nthreads) |
|
|
616 | wanted = nthreads; |
|
|
617 | |
|
|
618 | while (started > wanted) |
|
|
619 | end_thread (); |
|
|
620 | } |
|
|
621 | |
|
|
622 | static void poll_wait () |
|
|
623 | { |
|
|
624 | fd_set rfd; |
|
|
625 | |
|
|
626 | while (nreqs) |
|
|
627 | { |
|
|
628 | int size; |
|
|
629 | if (WORDREAD_UNSAFE) LOCK (reslock); |
|
|
630 | size = res_queue.size; |
|
|
631 | if (WORDREAD_UNSAFE) UNLOCK (reslock); |
|
|
632 | |
|
|
633 | if (size) |
|
|
634 | return; |
|
|
635 | |
|
|
636 | maybe_start_thread (); |
|
|
637 | |
|
|
638 | FD_ZERO(&rfd); |
|
|
639 | FD_SET(respipe [0], &rfd); |
|
|
640 | |
|
|
641 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
642 | } |
|
|
643 | } |
|
|
644 | |
360 | static int poll_cb () |
645 | static int poll_cb (int max) |
361 | { |
646 | { |
362 | dSP; |
647 | dSP; |
363 | int count = 0; |
648 | int count = 0; |
364 | int do_croak = 0; |
649 | int do_croak = 0; |
365 | aio_req req; |
650 | aio_req req; |
366 | |
651 | |
367 | for (;;) |
652 | for (;;) |
368 | { |
653 | { |
369 | pthread_mutex_lock (&reslock); |
654 | while (max <= 0 || count < max) |
370 | req = ress; |
|
|
371 | |
|
|
372 | if (req) |
|
|
373 | { |
655 | { |
374 | ress = req->next; |
656 | maybe_start_thread (); |
375 | |
657 | |
|
|
658 | LOCK (reslock); |
|
|
659 | req = reqq_shift (&res_queue); |
|
|
660 | |
376 | if (!ress) |
661 | if (req) |
377 | { |
662 | { |
|
|
663 | --npending; |
|
|
664 | |
|
|
665 | if (!res_queue.size) |
|
|
666 | { |
378 | /* read any signals sent by the worker threads */ |
667 | /* read any signals sent by the worker threads */ |
379 | char buf [32]; |
668 | char buf [32]; |
380 | while (read (respipe [0], buf, 32) == 32) |
669 | while (read (respipe [0], buf, 32) == 32) |
|
|
670 | ; |
381 | ; |
671 | } |
382 | |
|
|
383 | rese = 0; |
|
|
384 | } |
672 | } |
|
|
673 | |
|
|
674 | UNLOCK (reslock); |
|
|
675 | |
|
|
676 | if (!req) |
|
|
677 | break; |
|
|
678 | |
|
|
679 | --nreqs; |
|
|
680 | |
|
|
681 | if (req->type == REQ_GROUP && req->length) |
|
|
682 | { |
|
|
683 | req->fd = 1; /* mark request as delayed */ |
|
|
684 | continue; |
|
|
685 | } |
|
|
686 | else |
|
|
687 | { |
|
|
688 | if (req->type == REQ_READ) |
|
|
689 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
|
|
690 | |
|
|
691 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
|
|
692 | SvREADONLY_off (req->data); |
|
|
693 | |
|
|
694 | if (req->statdata) |
|
|
695 | { |
|
|
696 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
697 | PL_laststatval = req->result; |
|
|
698 | PL_statcache = *(req->statdata); |
|
|
699 | } |
|
|
700 | |
|
|
701 | req_invoke (req); |
|
|
702 | |
|
|
703 | count++; |
|
|
704 | } |
|
|
705 | |
|
|
706 | req_free (req); |
385 | } |
707 | } |
386 | |
708 | |
387 | pthread_mutex_unlock (&reslock); |
709 | if (nreqs <= max_outstanding) |
388 | |
|
|
389 | if (!req) |
|
|
390 | break; |
710 | break; |
391 | |
711 | |
392 | --nreqs; |
712 | poll_wait (); |
393 | |
713 | |
394 | if (req->type == REQ_QUIT) |
714 | max = 0; |
395 | started--; |
|
|
396 | else if (req->type == REQ_GROUP && req->length) |
|
|
397 | { |
|
|
398 | req->fd = 1; /* mark request as delayed */ |
|
|
399 | continue; |
|
|
400 | } |
|
|
401 | else |
|
|
402 | { |
|
|
403 | if (req->type == REQ_READ) |
|
|
404 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
|
|
405 | |
|
|
406 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
|
|
407 | SvREADONLY_off (req->data); |
|
|
408 | |
|
|
409 | if (req->statdata) |
|
|
410 | { |
|
|
411 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
412 | PL_laststatval = req->result; |
|
|
413 | PL_statcache = *(req->statdata); |
|
|
414 | } |
|
|
415 | |
|
|
416 | req_invoke (req); |
|
|
417 | |
|
|
418 | count++; |
|
|
419 | } |
|
|
420 | |
|
|
421 | req_free (req); |
|
|
422 | } |
715 | } |
423 | |
716 | |
424 | return count; |
717 | return count; |
425 | } |
|
|
426 | |
|
|
427 | static void *aio_proc(void *arg); |
|
|
428 | |
|
|
429 | static void start_thread (void) |
|
|
430 | { |
|
|
431 | sigset_t fullsigset, oldsigset; |
|
|
432 | pthread_t tid; |
|
|
433 | pthread_attr_t attr; |
|
|
434 | |
|
|
435 | pthread_attr_init (&attr); |
|
|
436 | pthread_attr_setstacksize (&attr, STACKSIZE); |
|
|
437 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|
|
438 | |
|
|
439 | sigfillset (&fullsigset); |
|
|
440 | sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset); |
|
|
441 | |
|
|
442 | if (pthread_create (&tid, &attr, aio_proc, 0) == 0) |
|
|
443 | started++; |
|
|
444 | |
|
|
445 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
|
|
446 | } |
|
|
447 | |
|
|
448 | static void req_send (aio_req req) |
|
|
449 | { |
|
|
450 | while (started < wanted && nreqs >= started) |
|
|
451 | start_thread (); |
|
|
452 | |
|
|
453 | ++nreqs; |
|
|
454 | |
|
|
455 | pthread_mutex_lock (&reqlock); |
|
|
456 | |
|
|
457 | req->next = 0; |
|
|
458 | |
|
|
459 | if (reqe) |
|
|
460 | { |
|
|
461 | reqe->next = req; |
|
|
462 | reqe = req; |
|
|
463 | } |
|
|
464 | else |
|
|
465 | reqe = reqs = req; |
|
|
466 | |
|
|
467 | pthread_cond_signal (&reqwait); |
|
|
468 | pthread_mutex_unlock (&reqlock); |
|
|
469 | |
|
|
470 | if (nreqs > max_outstanding) |
|
|
471 | for (;;) |
|
|
472 | { |
|
|
473 | poll_cb (); |
|
|
474 | |
|
|
475 | if (nreqs <= max_outstanding) |
|
|
476 | break; |
|
|
477 | |
|
|
478 | poll_wait (); |
|
|
479 | } |
|
|
480 | } |
|
|
481 | |
|
|
482 | static void end_thread (void) |
|
|
483 | { |
|
|
484 | aio_req req; |
|
|
485 | Newz (0, req, 1, aio_cb); |
|
|
486 | req->type = REQ_QUIT; |
|
|
487 | |
|
|
488 | req_send (req); |
|
|
489 | } |
|
|
490 | |
|
|
491 | static void min_parallel (int nthreads) |
|
|
492 | { |
|
|
493 | if (wanted < nthreads) |
|
|
494 | wanted = nthreads; |
|
|
495 | } |
|
|
496 | |
|
|
497 | static void max_parallel (int nthreads) |
|
|
498 | { |
|
|
499 | int cur = started; |
|
|
500 | |
|
|
501 | if (wanted > nthreads) |
|
|
502 | wanted = nthreads; |
|
|
503 | |
|
|
504 | while (cur > wanted) |
|
|
505 | { |
|
|
506 | end_thread (); |
|
|
507 | cur--; |
|
|
508 | } |
|
|
509 | |
|
|
510 | while (started > wanted) |
|
|
511 | { |
|
|
512 | poll_wait (); |
|
|
513 | poll_cb (); |
|
|
514 | } |
|
|
515 | } |
718 | } |
516 | |
719 | |
517 | static void create_pipe () |
720 | static void create_pipe () |
518 | { |
721 | { |
519 | if (pipe (respipe)) |
722 | if (pipe (respipe)) |
… | |
… | |
543 | static ssize_t pread (int fd, void *buf, size_t count, off_t offset) |
746 | static ssize_t pread (int fd, void *buf, size_t count, off_t offset) |
544 | { |
747 | { |
545 | ssize_t res; |
748 | ssize_t res; |
546 | off_t ooffset; |
749 | off_t ooffset; |
547 | |
750 | |
548 | pthread_mutex_lock (&preadwritelock); |
751 | LOCK (preadwritelock); |
549 | ooffset = lseek (fd, 0, SEEK_CUR); |
752 | ooffset = lseek (fd, 0, SEEK_CUR); |
550 | lseek (fd, offset, SEEK_SET); |
753 | lseek (fd, offset, SEEK_SET); |
551 | res = read (fd, buf, count); |
754 | res = read (fd, buf, count); |
552 | lseek (fd, ooffset, SEEK_SET); |
755 | lseek (fd, ooffset, SEEK_SET); |
553 | pthread_mutex_unlock (&preadwritelock); |
756 | UNLOCK (preadwritelock); |
554 | |
757 | |
555 | return res; |
758 | return res; |
556 | } |
759 | } |
557 | |
760 | |
558 | static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) |
761 | static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) |
559 | { |
762 | { |
560 | ssize_t res; |
763 | ssize_t res; |
561 | off_t ooffset; |
764 | off_t ooffset; |
562 | |
765 | |
563 | pthread_mutex_lock (&preadwritelock); |
766 | LOCK (preadwritelock); |
564 | ooffset = lseek (fd, 0, SEEK_CUR); |
767 | ooffset = lseek (fd, 0, SEEK_CUR); |
565 | lseek (fd, offset, SEEK_SET); |
768 | lseek (fd, offset, SEEK_SET); |
566 | res = write (fd, buf, count); |
769 | res = write (fd, buf, count); |
567 | lseek (fd, offset, SEEK_SET); |
770 | lseek (fd, offset, SEEK_SET); |
568 | pthread_mutex_unlock (&preadwritelock); |
771 | UNLOCK (preadwritelock); |
569 | |
772 | |
570 | return res; |
773 | return res; |
571 | } |
774 | } |
572 | #endif |
775 | #endif |
573 | |
776 | |
574 | #if !HAVE_FDATASYNC |
777 | #if !HAVE_FDATASYNC |
575 | # define fdatasync fsync |
778 | # define fdatasync fsync |
576 | #endif |
779 | #endif |
577 | |
780 | |
578 | #if !HAVE_READAHEAD |
781 | #if !HAVE_READAHEAD |
579 | # define readahead aio_readahead |
782 | # define readahead(fd,offset,count) aio_readahead (fd, offset, count, self) |
580 | |
783 | |
581 | static ssize_t readahead (int fd, off_t offset, size_t count) |
784 | static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self) |
582 | { |
785 | { |
583 | char readahead_buf[4096]; |
786 | dBUF; |
584 | |
787 | |
585 | while (count > 0) |
788 | while (count > 0) |
586 | { |
789 | { |
587 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
790 | size_t len = count < AIO_BUFSIZE ? count : AIO_BUFSIZE; |
588 | |
791 | |
589 | pread (fd, readahead_buf, len, offset); |
792 | pread (fd, aio_buf, len, offset); |
590 | offset += len; |
793 | offset += len; |
591 | count -= len; |
794 | count -= len; |
592 | } |
795 | } |
593 | |
796 | |
594 | errno = 0; |
797 | errno = 0; |
595 | } |
798 | } |
|
|
799 | |
596 | #endif |
800 | #endif |
597 | |
801 | |
598 | #if !HAVE_READDIR_R |
802 | #if !HAVE_READDIR_R |
599 | # define readdir_r aio_readdir_r |
803 | # define readdir_r aio_readdir_r |
600 | |
804 | |
… | |
… | |
603 | static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
807 | static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
604 | { |
808 | { |
605 | struct dirent *e; |
809 | struct dirent *e; |
606 | int errorno; |
810 | int errorno; |
607 | |
811 | |
608 | pthread_mutex_lock (&readdirlock); |
812 | LOCK (readdirlock); |
609 | |
813 | |
610 | e = readdir (dirp); |
814 | e = readdir (dirp); |
611 | errorno = errno; |
815 | errorno = errno; |
612 | |
816 | |
613 | if (e) |
817 | if (e) |
… | |
… | |
616 | strcpy (ent->d_name, e->d_name); |
820 | strcpy (ent->d_name, e->d_name); |
617 | } |
821 | } |
618 | else |
822 | else |
619 | *res = 0; |
823 | *res = 0; |
620 | |
824 | |
621 | pthread_mutex_unlock (&readdirlock); |
825 | UNLOCK (readdirlock); |
622 | |
826 | |
623 | errno = errorno; |
827 | errno = errorno; |
624 | return e ? 0 : -1; |
828 | return e ? 0 : -1; |
625 | } |
829 | } |
626 | #endif |
830 | #endif |
627 | |
831 | |
628 | /* sendfile always needs emulation */ |
832 | /* sendfile always needs emulation */ |
629 | static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
833 | static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count, worker *self) |
630 | { |
834 | { |
631 | ssize_t res; |
835 | ssize_t res; |
632 | |
836 | |
633 | if (!count) |
837 | if (!count) |
634 | return 0; |
838 | return 0; |
… | |
… | |
645 | { |
849 | { |
646 | off_t sbytes; |
850 | off_t sbytes; |
647 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
851 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
648 | |
852 | |
649 | if (res < 0 && sbytes) |
853 | if (res < 0 && sbytes) |
650 | /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ |
854 | /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */ |
651 | res = sbytes; |
855 | res = sbytes; |
652 | } |
856 | } |
653 | |
857 | |
654 | # elif __hpux |
858 | # elif __hpux |
655 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
859 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
… | |
… | |
683 | #endif |
887 | #endif |
684 | ) |
888 | ) |
685 | ) |
889 | ) |
686 | { |
890 | { |
687 | /* emulate sendfile. this is a major pain in the ass */ |
891 | /* emulate sendfile. this is a major pain in the ass */ |
688 | char buf[4096]; |
892 | dBUF; |
|
|
893 | |
689 | res = 0; |
894 | res = 0; |
690 | |
895 | |
691 | while (count) |
896 | while (count) |
692 | { |
897 | { |
693 | ssize_t cnt; |
898 | ssize_t cnt; |
694 | |
899 | |
695 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
900 | cnt = pread (ifd, aio_buf, count > AIO_BUFSIZE ? AIO_BUFSIZE : count, offset); |
696 | |
901 | |
697 | if (cnt <= 0) |
902 | if (cnt <= 0) |
698 | { |
903 | { |
699 | if (cnt && !res) res = -1; |
904 | if (cnt && !res) res = -1; |
700 | break; |
905 | break; |
701 | } |
906 | } |
702 | |
907 | |
703 | cnt = write (ofd, buf, cnt); |
908 | cnt = write (ofd, aio_buf, cnt); |
704 | |
909 | |
705 | if (cnt <= 0) |
910 | if (cnt <= 0) |
706 | { |
911 | { |
707 | if (cnt && !res) res = -1; |
912 | if (cnt && !res) res = -1; |
708 | break; |
913 | break; |
… | |
… | |
716 | |
921 | |
717 | return res; |
922 | return res; |
718 | } |
923 | } |
719 | |
924 | |
720 | /* read a full directory */ |
925 | /* read a full directory */ |
721 | static int scandir_ (const char *path, void **namesp) |
926 | static void scandir_ (aio_req req, worker *self) |
722 | { |
927 | { |
723 | DIR *dirp = opendir (path); |
928 | DIR *dirp; |
724 | union |
929 | union |
725 | { |
930 | { |
726 | struct dirent d; |
931 | struct dirent d; |
727 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
932 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
728 | } u; |
933 | } *u; |
729 | struct dirent *entp; |
934 | struct dirent *entp; |
730 | char *name, *names; |
935 | char *name, *names; |
731 | int memlen = 4096; |
936 | int memlen = 4096; |
732 | int memofs = 0; |
937 | int memofs = 0; |
733 | int res = 0; |
938 | int res = 0; |
734 | int errorno; |
939 | int errorno; |
735 | |
940 | |
736 | if (!dirp) |
941 | LOCK (wrklock); |
737 | return -1; |
942 | self->dirp = dirp = opendir (req->dataptr); |
738 | |
943 | self->dbuf = u = malloc (sizeof (*u)); |
739 | names = malloc (memlen); |
944 | req->data2ptr = names = malloc (memlen); |
|
|
945 | UNLOCK (wrklock); |
|
|
946 | |
|
|
947 | if (dirp && u && names) |
|
|
948 | for (;;) |
|
|
949 | { |
|
|
950 | errno = 0; |
|
|
951 | readdir_r (dirp, &u->d, &entp); |
|
|
952 | |
|
|
953 | if (!entp) |
|
|
954 | break; |
|
|
955 | |
|
|
956 | name = entp->d_name; |
|
|
957 | |
|
|
958 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
|
|
959 | { |
|
|
960 | int len = strlen (name) + 1; |
|
|
961 | |
|
|
962 | res++; |
|
|
963 | |
|
|
964 | while (memofs + len > memlen) |
|
|
965 | { |
|
|
966 | memlen *= 2; |
|
|
967 | LOCK (wrklock); |
|
|
968 | req->data2ptr = names = realloc (names, memlen); |
|
|
969 | UNLOCK (wrklock); |
|
|
970 | |
|
|
971 | if (!names) |
|
|
972 | break; |
|
|
973 | } |
|
|
974 | |
|
|
975 | memcpy (names + memofs, name, len); |
|
|
976 | memofs += len; |
|
|
977 | } |
|
|
978 | } |
|
|
979 | |
|
|
980 | if (errno) |
|
|
981 | res = -1; |
|
|
982 | |
|
|
983 | req->result = res; |
|
|
984 | } |
|
|
985 | |
|
|
986 | /*****************************************************************************/ |
|
|
987 | |
|
|
988 | static void *aio_proc (void *thr_arg) |
|
|
989 | { |
|
|
990 | aio_req req; |
|
|
991 | struct timespec ts; |
|
|
992 | worker *self = (worker *)thr_arg; |
|
|
993 | |
|
|
994 | /* try to distribute timeouts somewhat evenly */ |
|
|
995 | ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL) |
|
|
996 | * (1000000000UL / 1024UL); |
740 | |
997 | |
741 | for (;;) |
998 | for (;;) |
742 | { |
999 | { |
743 | errno = 0, readdir_r (dirp, &u.d, &entp); |
1000 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
744 | |
1001 | |
745 | if (!entp) |
1002 | LOCK (reqlock); |
746 | break; |
|
|
747 | |
|
|
748 | name = entp->d_name; |
|
|
749 | |
|
|
750 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
|
|
751 | { |
|
|
752 | int len = strlen (name) + 1; |
|
|
753 | |
|
|
754 | res++; |
|
|
755 | |
|
|
756 | while (memofs + len > memlen) |
|
|
757 | { |
|
|
758 | memlen *= 2; |
|
|
759 | names = realloc (names, memlen); |
|
|
760 | if (!names) |
|
|
761 | break; |
|
|
762 | } |
|
|
763 | |
|
|
764 | memcpy (names + memofs, name, len); |
|
|
765 | memofs += len; |
|
|
766 | } |
|
|
767 | } |
|
|
768 | |
|
|
769 | errorno = errno; |
|
|
770 | closedir (dirp); |
|
|
771 | |
|
|
772 | if (errorno) |
|
|
773 | { |
|
|
774 | free (names); |
|
|
775 | errno = errorno; |
|
|
776 | res = -1; |
|
|
777 | } |
|
|
778 | |
|
|
779 | *namesp = (void *)names; |
|
|
780 | return res; |
|
|
781 | } |
|
|
782 | |
|
|
783 | /*****************************************************************************/ |
|
|
784 | |
|
|
785 | static void *aio_proc (void *thr_arg) |
|
|
786 | { |
|
|
787 | aio_req req; |
|
|
788 | int type; |
|
|
789 | |
|
|
790 | do |
|
|
791 | { |
|
|
792 | pthread_mutex_lock (&reqlock); |
|
|
793 | |
1003 | |
794 | for (;;) |
1004 | for (;;) |
795 | { |
1005 | { |
796 | req = reqs; |
1006 | self->req = req = reqq_shift (&req_queue); |
797 | |
|
|
798 | if (reqs) |
|
|
799 | { |
|
|
800 | reqs = reqs->next; |
|
|
801 | if (!reqs) reqe = 0; |
|
|
802 | } |
|
|
803 | |
1007 | |
804 | if (req) |
1008 | if (req) |
805 | break; |
1009 | break; |
806 | |
1010 | |
|
|
1011 | ++idle; |
|
|
1012 | |
|
|
1013 | if (pthread_cond_timedwait (&reqwait, &reqlock, &ts) |
|
|
1014 | == ETIMEDOUT) |
|
|
1015 | { |
|
|
1016 | if (idle > max_idle) |
|
|
1017 | { |
|
|
1018 | --idle; |
|
|
1019 | UNLOCK (reqlock); |
|
|
1020 | LOCK (wrklock); |
|
|
1021 | --started; |
|
|
1022 | UNLOCK (wrklock); |
|
|
1023 | goto quit; |
|
|
1024 | } |
|
|
1025 | |
|
|
1026 | /* we are allowed to idle, so do so without any timeout */ |
807 | pthread_cond_wait (&reqwait, &reqlock); |
1027 | pthread_cond_wait (&reqwait, &reqlock); |
|
|
1028 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
|
|
1029 | } |
|
|
1030 | |
|
|
1031 | --idle; |
808 | } |
1032 | } |
809 | |
1033 | |
810 | pthread_mutex_unlock (&reqlock); |
1034 | --nready; |
|
|
1035 | |
|
|
1036 | UNLOCK (reqlock); |
811 | |
1037 | |
812 | errno = 0; /* strictly unnecessary */ |
1038 | errno = 0; /* strictly unnecessary */ |
813 | type = req->type; /* remember type for QUIT check */ |
|
|
814 | |
1039 | |
815 | if (!(req->flags & FLAG_CANCELLED)) |
1040 | if (!(req->flags & FLAG_CANCELLED)) |
816 | switch (type) |
1041 | switch (req->type) |
817 | { |
1042 | { |
818 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
1043 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
819 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
1044 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
820 | |
1045 | |
821 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
1046 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
822 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
1047 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length, self); break; |
823 | |
1048 | |
824 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
1049 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
825 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
1050 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
826 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
1051 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
827 | |
1052 | |
… | |
… | |
830 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
1055 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
831 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
1056 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
832 | case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; |
1057 | case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; |
833 | case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; |
1058 | case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; |
834 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
1059 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
|
|
1060 | case REQ_MKNOD: req->result = mknod (req->data2ptr, req->mode, (dev_t)req->offset); break; |
835 | |
1061 | |
836 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
1062 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
837 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
1063 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
838 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
1064 | case REQ_READDIR: scandir_ (req, self); break; |
839 | |
1065 | |
840 | case REQ_SLEEP: |
1066 | case REQ_BUSY: |
841 | { |
1067 | { |
842 | struct timeval tv; |
1068 | struct timeval tv; |
843 | |
1069 | |
844 | tv.tv_sec = req->fd; |
1070 | tv.tv_sec = req->fd; |
845 | tv.tv_usec = req->fd2; |
1071 | tv.tv_usec = req->fd2; |
… | |
… | |
847 | req->result = select (0, 0, 0, 0, &tv); |
1073 | req->result = select (0, 0, 0, 0, &tv); |
848 | } |
1074 | } |
849 | |
1075 | |
850 | case REQ_GROUP: |
1076 | case REQ_GROUP: |
851 | case REQ_NOP: |
1077 | case REQ_NOP: |
|
|
1078 | break; |
|
|
1079 | |
852 | case REQ_QUIT: |
1080 | case REQ_QUIT: |
853 | break; |
1081 | goto quit; |
854 | |
1082 | |
855 | default: |
1083 | default: |
856 | req->result = ENOSYS; |
1084 | req->result = ENOSYS; |
857 | break; |
1085 | break; |
858 | } |
1086 | } |
859 | |
1087 | |
860 | req->errorno = errno; |
1088 | req->errorno = errno; |
861 | |
1089 | |
862 | pthread_mutex_lock (&reslock); |
1090 | LOCK (reslock); |
863 | |
1091 | |
864 | req->next = 0; |
1092 | ++npending; |
865 | |
1093 | |
866 | if (rese) |
1094 | if (!reqq_push (&res_queue, req)) |
867 | { |
|
|
868 | rese->next = req; |
|
|
869 | rese = req; |
|
|
870 | } |
|
|
871 | else |
|
|
872 | { |
|
|
873 | rese = ress = req; |
|
|
874 | |
|
|
875 | /* write a dummy byte to the pipe so fh becomes ready */ |
1095 | /* write a dummy byte to the pipe so fh becomes ready */ |
876 | write (respipe [1], &respipe, 1); |
1096 | write (respipe [1], &respipe, 1); |
877 | } |
|
|
878 | |
1097 | |
879 | pthread_mutex_unlock (&reslock); |
1098 | self->req = 0; |
|
|
1099 | worker_clear (self); |
|
|
1100 | |
|
|
1101 | UNLOCK (reslock); |
880 | } |
1102 | } |
881 | while (type != REQ_QUIT); |
1103 | |
|
|
1104 | quit: |
|
|
1105 | LOCK (wrklock); |
|
|
1106 | worker_free (self); |
|
|
1107 | UNLOCK (wrklock); |
882 | |
1108 | |
883 | return 0; |
1109 | return 0; |
884 | } |
1110 | } |
885 | |
1111 | |
886 | /*****************************************************************************/ |
1112 | /*****************************************************************************/ |
887 | |
1113 | |
888 | static void atfork_prepare (void) |
1114 | static void atfork_prepare (void) |
889 | { |
1115 | { |
890 | pthread_mutex_lock (&reqlock); |
1116 | LOCK (wrklock); |
891 | pthread_mutex_lock (&reslock); |
1117 | LOCK (reqlock); |
|
|
1118 | LOCK (reslock); |
892 | #if !HAVE_PREADWRITE |
1119 | #if !HAVE_PREADWRITE |
893 | pthread_mutex_lock (&preadwritelock); |
1120 | LOCK (preadwritelock); |
894 | #endif |
1121 | #endif |
895 | #if !HAVE_READDIR_R |
1122 | #if !HAVE_READDIR_R |
896 | pthread_mutex_lock (&readdirlock); |
1123 | LOCK (readdirlock); |
897 | #endif |
1124 | #endif |
898 | } |
1125 | } |
899 | |
1126 | |
900 | static void atfork_parent (void) |
1127 | static void atfork_parent (void) |
901 | { |
1128 | { |
902 | #if !HAVE_READDIR_R |
1129 | #if !HAVE_READDIR_R |
903 | pthread_mutex_unlock (&readdirlock); |
1130 | UNLOCK (readdirlock); |
904 | #endif |
1131 | #endif |
905 | #if !HAVE_PREADWRITE |
1132 | #if !HAVE_PREADWRITE |
906 | pthread_mutex_unlock (&preadwritelock); |
1133 | UNLOCK (preadwritelock); |
907 | #endif |
1134 | #endif |
908 | pthread_mutex_unlock (&reslock); |
1135 | UNLOCK (reslock); |
909 | pthread_mutex_unlock (&reqlock); |
1136 | UNLOCK (reqlock); |
|
|
1137 | UNLOCK (wrklock); |
910 | } |
1138 | } |
911 | |
1139 | |
912 | static void atfork_child (void) |
1140 | static void atfork_child (void) |
913 | { |
1141 | { |
914 | aio_req prv; |
1142 | aio_req prv; |
915 | |
1143 | |
|
|
1144 | while (prv = reqq_shift (&req_queue)) |
|
|
1145 | req_free (prv); |
|
|
1146 | |
|
|
1147 | while (prv = reqq_shift (&res_queue)) |
|
|
1148 | req_free (prv); |
|
|
1149 | |
|
|
1150 | while (wrk_first.next != &wrk_first) |
|
|
1151 | { |
|
|
1152 | worker *wrk = wrk_first.next; |
|
|
1153 | |
|
|
1154 | if (wrk->req) |
|
|
1155 | req_free (wrk->req); |
|
|
1156 | |
|
|
1157 | worker_clear (wrk); |
|
|
1158 | worker_free (wrk); |
|
|
1159 | } |
|
|
1160 | |
916 | started = 0; |
1161 | started = 0; |
917 | |
1162 | idle = 0; |
918 | while (reqs) |
1163 | nreqs = 0; |
919 | { |
1164 | nready = 0; |
920 | prv = reqs; |
1165 | npending = 0; |
921 | reqs = prv->next; |
|
|
922 | req_free (prv); |
|
|
923 | } |
|
|
924 | |
|
|
925 | reqs = reqe = 0; |
|
|
926 | |
|
|
927 | while (ress) |
|
|
928 | { |
|
|
929 | prv = ress; |
|
|
930 | ress = prv->next; |
|
|
931 | req_free (prv); |
|
|
932 | } |
|
|
933 | |
|
|
934 | ress = rese = 0; |
|
|
935 | |
1166 | |
936 | close (respipe [0]); |
1167 | close (respipe [0]); |
937 | close (respipe [1]); |
1168 | close (respipe [1]); |
938 | create_pipe (); |
1169 | create_pipe (); |
939 | |
1170 | |
… | |
… | |
966 | PROTOTYPES: ENABLE |
1197 | PROTOTYPES: ENABLE |
967 | |
1198 | |
968 | BOOT: |
1199 | BOOT: |
969 | { |
1200 | { |
970 | HV *stash = gv_stashpv ("IO::AIO", 1); |
1201 | HV *stash = gv_stashpv ("IO::AIO", 1); |
|
|
1202 | |
971 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
1203 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
972 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
1204 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
973 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
1205 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
|
|
1206 | newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
|
|
1207 | newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
|
|
1208 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
974 | |
1209 | |
975 | create_pipe (); |
1210 | create_pipe (); |
976 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
1211 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
977 | } |
1212 | } |
978 | |
1213 | |
979 | void |
1214 | void |
980 | min_parallel (nthreads) |
1215 | min_parallel (int nthreads) |
981 | int nthreads |
|
|
982 | PROTOTYPE: $ |
1216 | PROTOTYPE: $ |
983 | |
1217 | |
984 | void |
1218 | void |
985 | max_parallel (nthreads) |
1219 | max_parallel (int nthreads) |
986 | int nthreads |
|
|
987 | PROTOTYPE: $ |
1220 | PROTOTYPE: $ |
988 | |
1221 | |
989 | int |
1222 | int |
990 | max_outstanding (nreqs) |
1223 | max_outstanding (int maxreqs) |
991 | int nreqs |
1224 | PROTOTYPE: $ |
992 | PROTOTYPE: $ |
|
|
993 | CODE: |
1225 | CODE: |
994 | RETVAL = max_outstanding; |
1226 | RETVAL = max_outstanding; |
995 | max_outstanding = nreqs; |
1227 | max_outstanding = maxreqs; |
|
|
1228 | OUTPUT: |
|
|
1229 | RETVAL |
996 | |
1230 | |
997 | void |
1231 | void |
998 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
1232 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
999 | SV * pathname |
1233 | SV * pathname |
1000 | int flags |
1234 | int flags |
… | |
… | |
1215 | |
1449 | |
1216 | REQ_SEND; |
1450 | REQ_SEND; |
1217 | } |
1451 | } |
1218 | |
1452 | |
1219 | void |
1453 | void |
|
|
1454 | aio_mknod (pathname,mode,dev,callback=&PL_sv_undef) |
|
|
1455 | SV * pathname |
|
|
1456 | SV * callback |
|
|
1457 | UV mode |
|
|
1458 | UV dev |
|
|
1459 | PPCODE: |
|
|
1460 | { |
|
|
1461 | dREQ; |
|
|
1462 | |
|
|
1463 | req->type = REQ_MKNOD; |
|
|
1464 | req->data = newSVsv (pathname); |
|
|
1465 | req->dataptr = SvPVbyte_nolen (req->data); |
|
|
1466 | req->mode = (mode_t)mode; |
|
|
1467 | req->offset = dev; |
|
|
1468 | |
|
|
1469 | REQ_SEND; |
|
|
1470 | } |
|
|
1471 | |
|
|
1472 | void |
1220 | aio_sleep (delay,callback=&PL_sv_undef) |
1473 | aio_busy (delay,callback=&PL_sv_undef) |
1221 | double delay |
1474 | double delay |
1222 | SV * callback |
1475 | SV * callback |
1223 | PPCODE: |
1476 | PPCODE: |
1224 | { |
1477 | { |
1225 | dREQ; |
1478 | dREQ; |
1226 | |
1479 | |
1227 | req->type = REQ_SLEEP; |
1480 | req->type = REQ_BUSY; |
1228 | req->fd = delay < 0. ? 0 : delay; |
1481 | req->fd = delay < 0. ? 0 : delay; |
1229 | req->fd2 = delay < 0. ? 0 : 1000. * (delay - req->fd); |
1482 | req->fd2 = delay < 0. ? 0 : 1000. * (delay - req->fd); |
1230 | |
1483 | |
1231 | REQ_SEND; |
1484 | REQ_SEND; |
1232 | } |
1485 | } |
… | |
… | |
1255 | req->type = REQ_NOP; |
1508 | req->type = REQ_NOP; |
1256 | |
1509 | |
1257 | REQ_SEND; |
1510 | REQ_SEND; |
1258 | } |
1511 | } |
1259 | |
1512 | |
1260 | #if 0 |
1513 | int |
1261 | |
1514 | aioreq_pri (int pri = 0) |
1262 | void |
1515 | PROTOTYPE: ;$ |
1263 | aio_pri (int pri = DEFAULT_PRI) |
|
|
1264 | CODE: |
1516 | CODE: |
|
|
1517 | RETVAL = next_pri - PRI_BIAS; |
|
|
1518 | if (items > 0) |
|
|
1519 | { |
1265 | if (pri < PRI_MIN) pri = PRI_MIN; |
1520 | if (pri < PRI_MIN) pri = PRI_MIN; |
1266 | if (pri > PRI_MAX) pri = PRI_MAX; |
1521 | if (pri > PRI_MAX) pri = PRI_MAX; |
1267 | next_pri = pri + PRI_BIAS; |
1522 | next_pri = pri + PRI_BIAS; |
|
|
1523 | } |
|
|
1524 | OUTPUT: |
|
|
1525 | RETVAL |
1268 | |
1526 | |
1269 | #endif |
1527 | void |
|
|
1528 | aioreq_nice (int nice = 0) |
|
|
1529 | CODE: |
|
|
1530 | nice = next_pri - nice; |
|
|
1531 | if (nice < PRI_MIN) nice = PRI_MIN; |
|
|
1532 | if (nice > PRI_MAX) nice = PRI_MAX; |
|
|
1533 | next_pri = nice + PRI_BIAS; |
1270 | |
1534 | |
1271 | void |
1535 | void |
1272 | flush () |
1536 | flush () |
1273 | PROTOTYPE: |
1537 | PROTOTYPE: |
1274 | CODE: |
1538 | CODE: |
1275 | while (nreqs) |
1539 | while (nreqs) |
1276 | { |
1540 | { |
1277 | poll_wait (); |
1541 | poll_wait (); |
1278 | poll_cb (); |
1542 | poll_cb (0); |
1279 | } |
1543 | } |
1280 | |
1544 | |
1281 | void |
1545 | void |
1282 | poll() |
1546 | poll() |
1283 | PROTOTYPE: |
1547 | PROTOTYPE: |
1284 | CODE: |
1548 | CODE: |
1285 | if (nreqs) |
1549 | if (nreqs) |
1286 | { |
1550 | { |
1287 | poll_wait (); |
1551 | poll_wait (); |
1288 | poll_cb (); |
1552 | poll_cb (0); |
1289 | } |
1553 | } |
1290 | |
1554 | |
1291 | int |
1555 | int |
1292 | poll_fileno() |
1556 | poll_fileno() |
1293 | PROTOTYPE: |
1557 | PROTOTYPE: |
… | |
… | |
1298 | |
1562 | |
1299 | int |
1563 | int |
1300 | poll_cb(...) |
1564 | poll_cb(...) |
1301 | PROTOTYPE: |
1565 | PROTOTYPE: |
1302 | CODE: |
1566 | CODE: |
1303 | RETVAL = poll_cb (); |
1567 | RETVAL = poll_cb (0); |
|
|
1568 | OUTPUT: |
|
|
1569 | RETVAL |
|
|
1570 | |
|
|
1571 | int |
|
|
1572 | poll_some(int max = 0) |
|
|
1573 | PROTOTYPE: $ |
|
|
1574 | CODE: |
|
|
1575 | RETVAL = poll_cb (max); |
1304 | OUTPUT: |
1576 | OUTPUT: |
1305 | RETVAL |
1577 | RETVAL |
1306 | |
1578 | |
1307 | void |
1579 | void |
1308 | poll_wait() |
1580 | poll_wait() |
… | |
… | |
1317 | CODE: |
1589 | CODE: |
1318 | RETVAL = nreqs; |
1590 | RETVAL = nreqs; |
1319 | OUTPUT: |
1591 | OUTPUT: |
1320 | RETVAL |
1592 | RETVAL |
1321 | |
1593 | |
|
|
1594 | int |
|
|
1595 | nready() |
|
|
1596 | PROTOTYPE: |
|
|
1597 | CODE: |
|
|
1598 | RETVAL = get_nready (); |
|
|
1599 | OUTPUT: |
|
|
1600 | RETVAL |
|
|
1601 | |
|
|
1602 | int |
|
|
1603 | npending() |
|
|
1604 | PROTOTYPE: |
|
|
1605 | CODE: |
|
|
1606 | RETVAL = get_npending (); |
|
|
1607 | OUTPUT: |
|
|
1608 | RETVAL |
|
|
1609 | |
1322 | PROTOTYPES: DISABLE |
1610 | PROTOTYPES: DISABLE |
1323 | |
1611 | |
1324 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1612 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1325 | |
1613 | |
1326 | void |
1614 | void |
1327 | cancel (aio_req_ornot req) |
1615 | cancel (aio_req_ornot req) |
1328 | PROTOTYPE: |
|
|
1329 | CODE: |
1616 | CODE: |
1330 | req_cancel (req); |
1617 | req_cancel (req); |
1331 | |
1618 | |
1332 | void |
1619 | void |
1333 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1620 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
… | |
… | |
1369 | } |
1656 | } |
1370 | } |
1657 | } |
1371 | } |
1658 | } |
1372 | |
1659 | |
1373 | void |
1660 | void |
|
|
1661 | cancel_subs (aio_req_ornot req) |
|
|
1662 | CODE: |
|
|
1663 | req_cancel_subs (req); |
|
|
1664 | |
|
|
1665 | void |
1374 | result (aio_req grp, ...) |
1666 | result (aio_req grp, ...) |
1375 | CODE: |
1667 | CODE: |
1376 | { |
1668 | { |
1377 | int i; |
1669 | int i; |
|
|
1670 | AV *av; |
|
|
1671 | |
|
|
1672 | grp->errorno = errno; |
|
|
1673 | |
1378 | AV *av = newAV (); |
1674 | av = newAV (); |
1379 | |
1675 | |
1380 | for (i = 1; i < items; ++i ) |
1676 | for (i = 1; i < items; ++i ) |
1381 | av_push (av, newSVsv (ST (i))); |
1677 | av_push (av, newSVsv (ST (i))); |
1382 | |
1678 | |
1383 | SvREFCNT_dec (grp->data); |
1679 | SvREFCNT_dec (grp->data); |
1384 | grp->data = (SV *)av; |
1680 | grp->data = (SV *)av; |
1385 | } |
1681 | } |
1386 | |
1682 | |
1387 | void |
1683 | void |
|
|
1684 | errno (aio_req grp, int errorno = errno) |
|
|
1685 | CODE: |
|
|
1686 | grp->errorno = errorno; |
|
|
1687 | |
|
|
1688 | void |
1388 | feed_limit (aio_req grp, int limit) |
1689 | limit (aio_req grp, int limit) |
1389 | CODE: |
1690 | CODE: |
1390 | grp->fd2 = limit; |
1691 | grp->fd2 = limit; |
1391 | aio_grp_feed (grp); |
1692 | aio_grp_feed (grp); |
1392 | |
1693 | |
1393 | void |
1694 | void |