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