… | |
… | |
46 | # define NAME_MAX 4096 |
46 | # define NAME_MAX 4096 |
47 | #endif |
47 | #endif |
48 | |
48 | |
49 | #if __ia64 |
49 | #if __ia64 |
50 | # define STACKSIZE 65536 |
50 | # define STACKSIZE 65536 |
|
|
51 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
|
|
52 | # define STACKSIZE PTHREAD_STACK_MIN |
51 | #else |
53 | #else |
52 | # define STACKSIZE 8192 |
54 | # define STACKSIZE 16384 |
53 | #endif |
55 | #endif |
|
|
56 | |
|
|
57 | /* buffer size for various temporary buffers */ |
|
|
58 | #define AIO_BUFSIZE 65536 |
|
|
59 | |
|
|
60 | #define dBUF \ |
|
|
61 | char *aio_buf = malloc (AIO_BUFSIZE); \ |
|
|
62 | if (!aio_buf) \ |
|
|
63 | return -1; |
|
|
64 | |
|
|
65 | #define fBUF free (aio_buf) |
54 | |
66 | |
55 | enum { |
67 | enum { |
56 | REQ_QUIT, |
68 | REQ_QUIT, |
57 | REQ_OPEN, REQ_CLOSE, |
69 | REQ_OPEN, REQ_CLOSE, |
58 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
70 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
… | |
… | |
105 | PRI_MIN = -4, |
117 | PRI_MIN = -4, |
106 | PRI_MAX = 4, |
118 | PRI_MAX = 4, |
107 | |
119 | |
108 | DEFAULT_PRI = 0, |
120 | DEFAULT_PRI = 0, |
109 | PRI_BIAS = -PRI_MIN, |
121 | PRI_BIAS = -PRI_MIN, |
|
|
122 | NUM_PRI = PRI_MAX + PRI_BIAS + 1, |
110 | }; |
123 | }; |
111 | |
124 | |
112 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
125 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
113 | |
126 | |
114 | static int started, wanted; |
127 | static int started, wanted; |
… | |
… | |
124 | |
137 | |
125 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
138 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
126 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
139 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
127 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
140 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
128 | |
141 | |
129 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
142 | /* |
130 | static volatile aio_req ress, rese; /* queue start, queue end */ |
143 | * a somewhat faster data structure might be nice, but |
|
|
144 | * with 8 priorities this actually needs <20 insns |
|
|
145 | * per shift, the most expensive operation. |
|
|
146 | */ |
|
|
147 | typedef struct { |
|
|
148 | aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ |
|
|
149 | int size; |
|
|
150 | } reqq; |
|
|
151 | |
|
|
152 | static reqq req_queue; |
|
|
153 | static reqq res_queue; |
|
|
154 | |
|
|
155 | int reqq_push (reqq *q, aio_req req) |
|
|
156 | { |
|
|
157 | int pri = req->pri; |
|
|
158 | req->next = 0; |
|
|
159 | |
|
|
160 | if (q->qe[pri]) |
|
|
161 | { |
|
|
162 | q->qe[pri]->next = req; |
|
|
163 | q->qe[pri] = req; |
|
|
164 | } |
|
|
165 | else |
|
|
166 | q->qe[pri] = q->qs[pri] = req; |
|
|
167 | |
|
|
168 | return q->size++; |
|
|
169 | } |
|
|
170 | |
|
|
171 | aio_req reqq_shift (reqq *q) |
|
|
172 | { |
|
|
173 | int pri; |
|
|
174 | |
|
|
175 | if (!q->size) |
|
|
176 | return 0; |
|
|
177 | |
|
|
178 | --q->size; |
|
|
179 | |
|
|
180 | for (pri = NUM_PRI; pri--; ) |
|
|
181 | { |
|
|
182 | aio_req req = q->qs[pri]; |
|
|
183 | |
|
|
184 | if (req) |
|
|
185 | { |
|
|
186 | if (!(q->qs[pri] = req->next)) |
|
|
187 | q->qe[pri] = 0; |
|
|
188 | |
|
|
189 | return req; |
|
|
190 | } |
|
|
191 | } |
|
|
192 | |
|
|
193 | abort (); |
|
|
194 | } |
131 | |
195 | |
132 | static void req_invoke (aio_req req); |
196 | static void req_invoke (aio_req req); |
133 | static void req_free (aio_req req); |
197 | static void req_free (aio_req req); |
134 | |
198 | |
135 | /* must be called at most once */ |
199 | /* must be called at most once */ |
… | |
… | |
169 | ENTER; |
233 | ENTER; |
170 | SAVETMPS; |
234 | SAVETMPS; |
171 | PUSHMARK (SP); |
235 | PUSHMARK (SP); |
172 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
236 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
173 | PUTBACK; |
237 | PUTBACK; |
174 | call_sv (grp->fh2, G_VOID | G_EVAL); |
238 | call_sv (grp->fh2, G_VOID | G_EVAL | G_KEEPERR); |
175 | SPAGAIN; |
239 | SPAGAIN; |
176 | FREETMPS; |
240 | FREETMPS; |
177 | LEAVE; |
241 | LEAVE; |
178 | } |
242 | } |
179 | |
243 | |
… | |
… | |
206 | { |
270 | { |
207 | fd_set rfd; |
271 | fd_set rfd; |
208 | |
272 | |
209 | while (nreqs) |
273 | while (nreqs) |
210 | { |
274 | { |
211 | aio_req req; |
275 | int size; |
212 | #if !(__x86 || __x86_64) /* safe without sempahore on this archs */ |
276 | #if !(__i386 || __x86_64) /* safe without sempahore on this archs */ |
213 | pthread_mutex_lock (&reslock); |
277 | pthread_mutex_lock (&reslock); |
214 | #endif |
278 | #endif |
215 | req = ress; |
279 | size = res_queue.size; |
216 | #if !(__x86 || __x86_64) /* safe without sempahore on this archs */ |
280 | #if !(__i386 || __x86_64) /* safe without sempahore on this archs */ |
217 | pthread_mutex_unlock (&reslock); |
281 | pthread_mutex_unlock (&reslock); |
218 | #endif |
282 | #endif |
219 | |
283 | |
220 | if (req) |
284 | if (size) |
221 | return; |
285 | return; |
222 | |
286 | |
223 | FD_ZERO(&rfd); |
287 | FD_ZERO(&rfd); |
224 | FD_SET(respipe [0], &rfd); |
288 | FD_SET(respipe [0], &rfd); |
225 | |
289 | |
… | |
… | |
228 | } |
292 | } |
229 | |
293 | |
230 | static void req_invoke (aio_req req) |
294 | static void req_invoke (aio_req req) |
231 | { |
295 | { |
232 | dSP; |
296 | dSP; |
233 | int errorno = errno; |
|
|
234 | |
297 | |
235 | if (req->flags & FLAG_CANCELLED || !SvOK (req->callback)) |
298 | if (!(req->flags & FLAG_CANCELLED) && SvOK (req->callback)) |
236 | return; |
299 | { |
237 | |
|
|
238 | errno = req->errorno; |
300 | errno = req->errorno; |
239 | |
301 | |
240 | ENTER; |
302 | ENTER; |
241 | SAVETMPS; |
303 | SAVETMPS; |
242 | PUSHMARK (SP); |
304 | PUSHMARK (SP); |
243 | EXTEND (SP, 1); |
305 | EXTEND (SP, 1); |
244 | |
306 | |
245 | switch (req->type) |
307 | switch (req->type) |
246 | { |
|
|
247 | case REQ_READDIR: |
|
|
248 | { |
308 | { |
249 | SV *rv = &PL_sv_undef; |
309 | case REQ_READDIR: |
250 | |
|
|
251 | if (req->result >= 0) |
|
|
252 | { |
310 | { |
253 | char *buf = req->data2ptr; |
311 | SV *rv = &PL_sv_undef; |
254 | AV *av = newAV (); |
|
|
255 | |
312 | |
256 | while (req->result) |
313 | if (req->result >= 0) |
257 | { |
314 | { |
|
|
315 | char *buf = req->data2ptr; |
|
|
316 | AV *av = newAV (); |
|
|
317 | |
|
|
318 | while (req->result) |
|
|
319 | { |
258 | SV *sv = newSVpv (buf, 0); |
320 | SV *sv = newSVpv (buf, 0); |
259 | |
321 | |
260 | av_push (av, sv); |
322 | av_push (av, sv); |
261 | buf += SvCUR (sv) + 1; |
323 | buf += SvCUR (sv) + 1; |
262 | req->result--; |
324 | req->result--; |
|
|
325 | } |
|
|
326 | |
|
|
327 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
263 | } |
328 | } |
264 | |
329 | |
265 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
330 | PUSHs (rv); |
266 | } |
331 | } |
|
|
332 | break; |
267 | |
333 | |
268 | PUSHs (rv); |
334 | case REQ_OPEN: |
|
|
335 | { |
|
|
336 | /* convert fd to fh */ |
|
|
337 | SV *fh; |
|
|
338 | |
|
|
339 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
340 | PUTBACK; |
|
|
341 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
342 | SPAGAIN; |
|
|
343 | |
|
|
344 | fh = SvREFCNT_inc (POPs); |
|
|
345 | |
|
|
346 | PUSHMARK (SP); |
|
|
347 | XPUSHs (sv_2mortal (fh)); |
|
|
348 | } |
|
|
349 | break; |
|
|
350 | |
|
|
351 | case REQ_GROUP: |
|
|
352 | req->fd = 2; /* mark group as finished */ |
|
|
353 | |
|
|
354 | if (req->data) |
|
|
355 | { |
|
|
356 | int i; |
|
|
357 | AV *av = (AV *)req->data; |
|
|
358 | |
|
|
359 | EXTEND (SP, AvFILL (av) + 1); |
|
|
360 | for (i = 0; i <= AvFILL (av); ++i) |
|
|
361 | PUSHs (*av_fetch (av, i, 0)); |
|
|
362 | } |
|
|
363 | break; |
|
|
364 | |
|
|
365 | case REQ_NOP: |
|
|
366 | case REQ_SLEEP: |
|
|
367 | break; |
|
|
368 | |
|
|
369 | default: |
|
|
370 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
371 | break; |
269 | } |
372 | } |
270 | break; |
|
|
271 | |
373 | |
272 | case REQ_OPEN: |
|
|
273 | { |
|
|
274 | /* convert fd to fh */ |
|
|
275 | SV *fh; |
|
|
276 | |
374 | |
277 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
278 | PUTBACK; |
375 | PUTBACK; |
279 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
280 | SPAGAIN; |
|
|
281 | |
|
|
282 | fh = SvREFCNT_inc (POPs); |
|
|
283 | |
|
|
284 | PUSHMARK (SP); |
|
|
285 | XPUSHs (sv_2mortal (fh)); |
|
|
286 | } |
|
|
287 | break; |
|
|
288 | |
|
|
289 | case REQ_GROUP: |
|
|
290 | req->fd = 2; /* mark group as finished */ |
|
|
291 | |
|
|
292 | if (req->data) |
|
|
293 | { |
|
|
294 | int i; |
|
|
295 | AV *av = (AV *)req->data; |
|
|
296 | |
|
|
297 | EXTEND (SP, AvFILL (av) + 1); |
|
|
298 | for (i = 0; i <= AvFILL (av); ++i) |
|
|
299 | PUSHs (*av_fetch (av, i, 0)); |
|
|
300 | } |
|
|
301 | break; |
|
|
302 | |
|
|
303 | case REQ_NOP: |
|
|
304 | case REQ_SLEEP: |
|
|
305 | break; |
|
|
306 | |
|
|
307 | default: |
|
|
308 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
309 | break; |
|
|
310 | } |
|
|
311 | |
|
|
312 | |
|
|
313 | PUTBACK; |
|
|
314 | call_sv (req->callback, G_VOID | G_EVAL); |
376 | call_sv (req->callback, G_VOID | G_EVAL); |
315 | SPAGAIN; |
377 | SPAGAIN; |
316 | |
378 | |
317 | FREETMPS; |
379 | FREETMPS; |
318 | LEAVE; |
380 | LEAVE; |
319 | |
|
|
320 | errno = errorno; |
|
|
321 | |
|
|
322 | if (SvTRUE (ERRSV)) |
|
|
323 | { |
381 | } |
324 | req_free (req); |
|
|
325 | croak (0); |
|
|
326 | } |
|
|
327 | } |
|
|
328 | |
382 | |
329 | static void req_free (aio_req req) |
|
|
330 | { |
|
|
331 | if (req->grp) |
383 | if (req->grp) |
332 | { |
384 | { |
333 | aio_req grp = req->grp; |
385 | aio_req grp = req->grp; |
334 | |
386 | |
335 | /* unlink request */ |
387 | /* unlink request */ |
… | |
… | |
340 | grp->grp_first = req->grp_next; |
392 | grp->grp_first = req->grp_next; |
341 | |
393 | |
342 | aio_grp_dec (grp); |
394 | aio_grp_dec (grp); |
343 | } |
395 | } |
344 | |
396 | |
|
|
397 | if (SvTRUE (ERRSV)) |
|
|
398 | { |
|
|
399 | req_free (req); |
|
|
400 | croak (0); |
|
|
401 | } |
|
|
402 | } |
|
|
403 | |
|
|
404 | static void req_free (aio_req req) |
|
|
405 | { |
345 | if (req->self) |
406 | if (req->self) |
346 | { |
407 | { |
347 | sv_unmagic (req->self, PERL_MAGIC_ext); |
408 | sv_unmagic (req->self, PERL_MAGIC_ext); |
348 | SvREFCNT_dec (req->self); |
409 | SvREFCNT_dec (req->self); |
349 | } |
410 | } |
… | |
… | |
381 | aio_req req; |
442 | aio_req req; |
382 | |
443 | |
383 | for (;;) |
444 | for (;;) |
384 | { |
445 | { |
385 | pthread_mutex_lock (&reslock); |
446 | pthread_mutex_lock (&reslock); |
386 | req = ress; |
447 | req = reqq_shift (&res_queue); |
387 | |
448 | |
388 | if (req) |
449 | if (req) |
389 | { |
450 | { |
390 | ress = req->next; |
|
|
391 | |
|
|
392 | if (!ress) |
451 | if (!res_queue.size) |
393 | { |
452 | { |
394 | /* read any signals sent by the worker threads */ |
453 | /* read any signals sent by the worker threads */ |
395 | char buf [32]; |
454 | char buf [32]; |
396 | while (read (respipe [0], buf, 32) == 32) |
455 | while (read (respipe [0], buf, 32) == 32) |
397 | ; |
456 | ; |
398 | |
|
|
399 | rese = 0; |
|
|
400 | } |
457 | } |
401 | } |
458 | } |
402 | |
459 | |
403 | pthread_mutex_unlock (&reslock); |
460 | pthread_mutex_unlock (&reslock); |
404 | |
461 | |
… | |
… | |
467 | start_thread (); |
524 | start_thread (); |
468 | |
525 | |
469 | ++nreqs; |
526 | ++nreqs; |
470 | |
527 | |
471 | pthread_mutex_lock (&reqlock); |
528 | pthread_mutex_lock (&reqlock); |
472 | |
529 | reqq_push (&req_queue, req); |
473 | req->next = 0; |
|
|
474 | |
|
|
475 | if (reqe) |
|
|
476 | { |
|
|
477 | reqe->next = req; |
|
|
478 | reqe = req; |
|
|
479 | } |
|
|
480 | else |
|
|
481 | reqe = reqs = req; |
|
|
482 | |
|
|
483 | pthread_cond_signal (&reqwait); |
530 | pthread_cond_signal (&reqwait); |
484 | pthread_mutex_unlock (&reqlock); |
531 | pthread_mutex_unlock (&reqlock); |
485 | |
532 | |
486 | if (nreqs > max_outstanding) |
533 | if (nreqs > max_outstanding) |
487 | for (;;) |
534 | for (;;) |
… | |
… | |
496 | } |
543 | } |
497 | |
544 | |
498 | static void end_thread (void) |
545 | static void end_thread (void) |
499 | { |
546 | { |
500 | aio_req req; |
547 | aio_req req; |
|
|
548 | |
501 | Newz (0, req, 1, aio_cb); |
549 | Newz (0, req, 1, aio_cb); |
|
|
550 | |
502 | req->type = REQ_QUIT; |
551 | req->type = REQ_QUIT; |
|
|
552 | req->pri = PRI_MAX + PRI_BIAS; |
503 | |
553 | |
504 | req_send (req); |
554 | req_send (req); |
505 | } |
555 | } |
506 | |
556 | |
507 | static void min_parallel (int nthreads) |
557 | static void min_parallel (int nthreads) |
… | |
… | |
594 | #if !HAVE_READAHEAD |
644 | #if !HAVE_READAHEAD |
595 | # define readahead aio_readahead |
645 | # define readahead aio_readahead |
596 | |
646 | |
597 | static ssize_t readahead (int fd, off_t offset, size_t count) |
647 | static ssize_t readahead (int fd, off_t offset, size_t count) |
598 | { |
648 | { |
599 | char readahead_buf[4096]; |
649 | dBUF; |
600 | |
650 | |
601 | while (count > 0) |
651 | while (count > 0) |
602 | { |
652 | { |
603 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
653 | size_t len = count < AIO_BUFSIZE ? count : AIO_BUFSIZE; |
604 | |
654 | |
605 | pread (fd, readahead_buf, len, offset); |
655 | pread (fd, aio_buf, len, offset); |
606 | offset += len; |
656 | offset += len; |
607 | count -= len; |
657 | count -= len; |
608 | } |
658 | } |
|
|
659 | |
|
|
660 | fBUF; |
609 | |
661 | |
610 | errno = 0; |
662 | errno = 0; |
611 | } |
663 | } |
612 | #endif |
664 | #endif |
613 | |
665 | |
… | |
… | |
699 | #endif |
751 | #endif |
700 | ) |
752 | ) |
701 | ) |
753 | ) |
702 | { |
754 | { |
703 | /* emulate sendfile. this is a major pain in the ass */ |
755 | /* emulate sendfile. this is a major pain in the ass */ |
704 | char buf[4096]; |
756 | dBUF; |
|
|
757 | |
705 | res = 0; |
758 | res = 0; |
706 | |
759 | |
707 | while (count) |
760 | while (count) |
708 | { |
761 | { |
709 | ssize_t cnt; |
762 | ssize_t cnt; |
710 | |
763 | |
711 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
764 | cnt = pread (ifd, aio_buf, count > AIO_BUFSIZE ? AIO_BUFSIZE : count, offset); |
712 | |
765 | |
713 | if (cnt <= 0) |
766 | if (cnt <= 0) |
714 | { |
767 | { |
715 | if (cnt && !res) res = -1; |
768 | if (cnt && !res) res = -1; |
716 | break; |
769 | break; |
717 | } |
770 | } |
718 | |
771 | |
719 | cnt = write (ofd, buf, cnt); |
772 | cnt = write (ofd, aio_buf, cnt); |
720 | |
773 | |
721 | if (cnt <= 0) |
774 | if (cnt <= 0) |
722 | { |
775 | { |
723 | if (cnt && !res) res = -1; |
776 | if (cnt && !res) res = -1; |
724 | break; |
777 | break; |
… | |
… | |
726 | |
779 | |
727 | offset += cnt; |
780 | offset += cnt; |
728 | res += cnt; |
781 | res += cnt; |
729 | count -= cnt; |
782 | count -= cnt; |
730 | } |
783 | } |
|
|
784 | |
|
|
785 | fBUF; |
731 | } |
786 | } |
732 | |
787 | |
733 | return res; |
788 | return res; |
734 | } |
789 | } |
735 | |
790 | |
736 | /* read a full directory */ |
791 | /* read a full directory */ |
737 | static int scandir_ (const char *path, void **namesp) |
792 | static int scandir_ (const char *path, void **namesp) |
738 | { |
793 | { |
739 | DIR *dirp = opendir (path); |
794 | DIR *dirp; |
740 | union |
795 | union |
741 | { |
796 | { |
742 | struct dirent d; |
797 | struct dirent d; |
743 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
798 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
744 | } u; |
799 | } *u; |
745 | struct dirent *entp; |
800 | struct dirent *entp; |
746 | char *name, *names; |
801 | char *name, *names; |
747 | int memlen = 4096; |
802 | int memlen = 4096; |
748 | int memofs = 0; |
803 | int memofs = 0; |
749 | int res = 0; |
804 | int res = 0; |
750 | int errorno; |
805 | int errorno; |
751 | |
806 | |
|
|
807 | dirp = opendir (path); |
752 | if (!dirp) |
808 | if (!dirp) |
753 | return -1; |
809 | return -1; |
754 | |
810 | |
|
|
811 | u = malloc (sizeof (*u)); |
755 | names = malloc (memlen); |
812 | names = malloc (memlen); |
756 | |
813 | |
|
|
814 | if (u && names) |
757 | for (;;) |
815 | for (;;) |
758 | { |
816 | { |
|
|
817 | errno = 0; |
759 | errno = 0, readdir_r (dirp, &u.d, &entp); |
818 | readdir_r (dirp, &u->d, &entp); |
760 | |
819 | |
761 | if (!entp) |
820 | if (!entp) |
762 | break; |
821 | break; |
763 | |
822 | |
764 | name = entp->d_name; |
823 | name = entp->d_name; |
765 | |
824 | |
766 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
825 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
767 | { |
826 | { |
768 | int len = strlen (name) + 1; |
827 | int len = strlen (name) + 1; |
769 | |
828 | |
770 | res++; |
829 | res++; |
771 | |
830 | |
772 | while (memofs + len > memlen) |
831 | while (memofs + len > memlen) |
773 | { |
832 | { |
774 | memlen *= 2; |
833 | memlen *= 2; |
775 | names = realloc (names, memlen); |
834 | names = realloc (names, memlen); |
776 | if (!names) |
835 | if (!names) |
777 | break; |
836 | break; |
778 | } |
837 | } |
779 | |
838 | |
780 | memcpy (names + memofs, name, len); |
839 | memcpy (names + memofs, name, len); |
781 | memofs += len; |
840 | memofs += len; |
782 | } |
841 | } |
783 | } |
842 | } |
784 | |
843 | |
785 | errorno = errno; |
844 | errorno = errno; |
|
|
845 | free (u); |
786 | closedir (dirp); |
846 | closedir (dirp); |
787 | |
847 | |
788 | if (errorno) |
848 | if (errorno) |
789 | { |
849 | { |
790 | free (names); |
850 | free (names); |
… | |
… | |
807 | { |
867 | { |
808 | pthread_mutex_lock (&reqlock); |
868 | pthread_mutex_lock (&reqlock); |
809 | |
869 | |
810 | for (;;) |
870 | for (;;) |
811 | { |
871 | { |
812 | req = reqs; |
872 | req = reqq_shift (&req_queue); |
813 | |
|
|
814 | if (reqs) |
|
|
815 | { |
|
|
816 | reqs = reqs->next; |
|
|
817 | if (!reqs) reqe = 0; |
|
|
818 | } |
|
|
819 | |
873 | |
820 | if (req) |
874 | if (req) |
821 | break; |
875 | break; |
822 | |
876 | |
823 | pthread_cond_wait (&reqwait, &reqlock); |
877 | pthread_cond_wait (&reqwait, &reqlock); |
… | |
… | |
875 | |
929 | |
876 | req->errorno = errno; |
930 | req->errorno = errno; |
877 | |
931 | |
878 | pthread_mutex_lock (&reslock); |
932 | pthread_mutex_lock (&reslock); |
879 | |
933 | |
880 | req->next = 0; |
934 | if (!reqq_push (&res_queue, req)) |
881 | |
|
|
882 | if (rese) |
|
|
883 | { |
|
|
884 | rese->next = req; |
|
|
885 | rese = req; |
|
|
886 | } |
|
|
887 | else |
|
|
888 | { |
|
|
889 | rese = ress = req; |
|
|
890 | |
|
|
891 | /* write a dummy byte to the pipe so fh becomes ready */ |
935 | /* write a dummy byte to the pipe so fh becomes ready */ |
892 | write (respipe [1], &respipe, 1); |
936 | write (respipe [1], &respipe, 1); |
893 | } |
|
|
894 | |
937 | |
895 | pthread_mutex_unlock (&reslock); |
938 | pthread_mutex_unlock (&reslock); |
896 | } |
939 | } |
897 | while (type != REQ_QUIT); |
940 | while (type != REQ_QUIT); |
898 | |
941 | |
… | |
… | |
929 | { |
972 | { |
930 | aio_req prv; |
973 | aio_req prv; |
931 | |
974 | |
932 | started = 0; |
975 | started = 0; |
933 | |
976 | |
934 | while (reqs) |
977 | while (prv = reqq_shift (&req_queue)) |
935 | { |
|
|
936 | prv = reqs; |
|
|
937 | reqs = prv->next; |
|
|
938 | req_free (prv); |
978 | req_free (prv); |
939 | } |
|
|
940 | |
979 | |
941 | reqs = reqe = 0; |
980 | while (prv = reqq_shift (&res_queue)) |
942 | |
|
|
943 | while (ress) |
|
|
944 | { |
|
|
945 | prv = ress; |
|
|
946 | ress = prv->next; |
|
|
947 | req_free (prv); |
981 | req_free (prv); |
948 | } |
982 | |
949 | |
|
|
950 | ress = rese = 0; |
|
|
951 | |
|
|
952 | close (respipe [0]); |
983 | close (respipe [0]); |
953 | close (respipe [1]); |
984 | close (respipe [1]); |
954 | create_pipe (); |
985 | create_pipe (); |
955 | |
986 | |
956 | atfork_parent (); |
987 | atfork_parent (); |
… | |
… | |
1271 | req->type = REQ_NOP; |
1302 | req->type = REQ_NOP; |
1272 | |
1303 | |
1273 | REQ_SEND; |
1304 | REQ_SEND; |
1274 | } |
1305 | } |
1275 | |
1306 | |
1276 | #if 0 |
|
|
1277 | |
|
|
1278 | void |
1307 | void |
1279 | aio_pri (int pri = DEFAULT_PRI) |
1308 | aioreq_pri (int pri = DEFAULT_PRI) |
1280 | CODE: |
1309 | CODE: |
1281 | if (pri < PRI_MIN) pri = PRI_MIN; |
1310 | if (pri < PRI_MIN) pri = PRI_MIN; |
1282 | if (pri > PRI_MAX) pri = PRI_MAX; |
1311 | if (pri > PRI_MAX) pri = PRI_MAX; |
1283 | next_pri = pri + PRI_BIAS; |
1312 | next_pri = pri + PRI_BIAS; |
1284 | |
1313 | |
1285 | #endif |
1314 | void |
|
|
1315 | aioreq_nice (int nice = 0) |
|
|
1316 | CODE: |
|
|
1317 | nice = next_pri - nice; |
|
|
1318 | if (nice < PRI_MIN) nice = PRI_MIN; |
|
|
1319 | if (nice > PRI_MAX) nice = PRI_MAX; |
|
|
1320 | next_pri = nice + PRI_BIAS; |
1286 | |
1321 | |
1287 | void |
1322 | void |
1288 | flush () |
1323 | flush () |
1289 | PROTOTYPE: |
1324 | PROTOTYPE: |
1290 | CODE: |
1325 | CODE: |
… | |
… | |
1339 | |
1374 | |
1340 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1375 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1341 | |
1376 | |
1342 | void |
1377 | void |
1343 | cancel (aio_req_ornot req) |
1378 | cancel (aio_req_ornot req) |
1344 | PROTOTYPE: |
|
|
1345 | CODE: |
1379 | CODE: |
1346 | req_cancel (req); |
1380 | req_cancel (req); |
1347 | |
1381 | |
1348 | void |
1382 | void |
1349 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1383 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
… | |
… | |
1399 | SvREFCNT_dec (grp->data); |
1433 | SvREFCNT_dec (grp->data); |
1400 | grp->data = (SV *)av; |
1434 | grp->data = (SV *)av; |
1401 | } |
1435 | } |
1402 | |
1436 | |
1403 | void |
1437 | void |
1404 | feed_limit (aio_req grp, int limit) |
1438 | limit (aio_req grp, int limit) |
1405 | CODE: |
1439 | CODE: |
1406 | grp->fd2 = limit; |
1440 | grp->fd2 = limit; |
1407 | aio_grp_feed (grp); |
1441 | aio_grp_feed (grp); |
1408 | |
1442 | |
1409 | void |
1443 | void |