… | |
… | |
101 | #include "libeio/eio.c" |
101 | #include "libeio/eio.c" |
102 | |
102 | |
103 | typedef eio_req *aio_req; |
103 | typedef eio_req *aio_req; |
104 | typedef eio_req *aio_req_ornot; |
104 | typedef eio_req *aio_req_ornot; |
105 | |
105 | |
106 | static unsigned int max_outstanding = 0x7fffffff; |
106 | static SV *on_next_submit; |
107 | |
|
|
108 | static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; |
107 | static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; |
|
|
108 | static int max_outstanding; |
109 | |
109 | |
110 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
110 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
111 | |
111 | |
112 | static void req_destroy (aio_req req); |
112 | static void req_destroy (aio_req req); |
113 | static void req_cancel (aio_req req); |
113 | static void req_cancel (aio_req req); |
… | |
… | |
166 | FREETMPS; |
166 | FREETMPS; |
167 | LEAVE; |
167 | LEAVE; |
168 | } |
168 | } |
169 | } |
169 | } |
170 | |
170 | |
|
|
171 | static void req_submit (eio_req *req) |
|
|
172 | { |
|
|
173 | eio_submit (req); |
|
|
174 | |
|
|
175 | if (on_next_submit) |
|
|
176 | { |
|
|
177 | dSP; |
|
|
178 | SV *cb = sv_2mortal (on_next_submit); |
|
|
179 | |
|
|
180 | on_next_submit = 0; |
|
|
181 | |
|
|
182 | PUSHMARK (SP); |
|
|
183 | PUTBACK; |
|
|
184 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
185 | } |
|
|
186 | } |
|
|
187 | |
171 | static int req_invoke (eio_req *req) |
188 | static int req_invoke (eio_req *req) |
172 | { |
189 | { |
173 | dSP; |
190 | dSP; |
174 | |
191 | |
175 | if (req->flags & FLAG_SV2_RO_OFF) |
192 | if (req->flags & FLAG_SV2_RO_OFF) |
… | |
… | |
405 | } |
422 | } |
406 | } |
423 | } |
407 | |
424 | |
408 | static int poll_cb (void) |
425 | static int poll_cb (void) |
409 | { |
426 | { |
|
|
427 | int res; |
|
|
428 | |
|
|
429 | do |
|
|
430 | { |
410 | int res = eio_poll (); |
431 | res = eio_poll (); |
411 | |
432 | |
412 | if (res > 0) |
433 | if (res > 0) |
413 | croak (0); |
434 | croak (0); |
|
|
435 | } |
|
|
436 | while (max_outstanding && max_outstanding <= eio_nreqs ()); |
414 | |
437 | |
415 | return res; |
438 | return res; |
|
|
439 | } |
|
|
440 | |
|
|
441 | static void atfork_child (void) |
|
|
442 | { |
|
|
443 | create_respipe (); |
416 | } |
444 | } |
417 | |
445 | |
418 | #define dREQ \ |
446 | #define dREQ \ |
419 | aio_req req; \ |
447 | aio_req req; \ |
420 | int req_pri = next_pri; \ |
448 | int req_pri = next_pri; \ |
… | |
… | |
429 | \ |
457 | \ |
430 | req->callback = newSVsv (callback); \ |
458 | req->callback = newSVsv (callback); \ |
431 | req->pri = req_pri |
459 | req->pri = req_pri |
432 | |
460 | |
433 | #define REQ_SEND \ |
461 | #define REQ_SEND \ |
434 | eio_submit (req); \ |
462 | req_submit (req); \ |
435 | \ |
463 | \ |
436 | if (GIMME_V != G_VOID) \ |
464 | if (GIMME_V != G_VOID) \ |
437 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
465 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
438 | |
466 | |
439 | MODULE = IO::AIO PACKAGE = IO::AIO |
467 | MODULE = IO::AIO PACKAGE = IO::AIO |
… | |
… | |
464 | |
492 | |
465 | create_respipe (); |
493 | create_respipe (); |
466 | |
494 | |
467 | if (eio_init (want_poll, done_poll) < 0) |
495 | if (eio_init (want_poll, done_poll) < 0) |
468 | croak ("IO::AIO: unable to initialise eio library"); |
496 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
497 | |
|
|
498 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
499 | X_THREAD_ATFORK (0, 0, atfork_child); |
469 | } |
500 | } |
470 | |
501 | |
471 | void |
502 | void |
472 | max_poll_reqs (int nreqs) |
503 | max_poll_reqs (int nreqs) |
473 | PROTOTYPE: $ |
504 | PROTOTYPE: $ |
… | |
… | |
918 | |
949 | |
919 | void |
950 | void |
920 | flush () |
951 | flush () |
921 | PROTOTYPE: |
952 | PROTOTYPE: |
922 | CODE: |
953 | CODE: |
923 | while (nreqs) |
954 | while (eio_nreqs ()) |
924 | { |
955 | { |
925 | poll_wait (); |
956 | poll_wait (); |
926 | poll_cb (); |
957 | poll_cb (); |
927 | } |
958 | } |
928 | |
959 | |
… | |
… | |
989 | RETVAL = started; |
1020 | RETVAL = started; |
990 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
1021 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
991 | OUTPUT: |
1022 | OUTPUT: |
992 | RETVAL |
1023 | RETVAL |
993 | |
1024 | |
|
|
1025 | void _on_next_submit (SV *cb) |
|
|
1026 | CODE: |
|
|
1027 | SvREFCNT_dec (on_next_submit); |
|
|
1028 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1029 | |
994 | PROTOTYPES: DISABLE |
1030 | PROTOTYPES: DISABLE |
995 | |
1031 | |
996 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1032 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
997 | |
1033 | |
998 | void |
1034 | void |