ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.115 by root, Sat May 10 18:06:41 2008 UTC vs.
Revision 1.117 by root, Sat May 10 20:02:09 2008 UTC

101#include "libeio/eio.c" 101#include "libeio/eio.c"
102 102
103typedef eio_req *aio_req; 103typedef eio_req *aio_req;
104typedef eio_req *aio_req_ornot; 104typedef eio_req *aio_req_ornot;
105 105
106static unsigned int max_outstanding = 0x7fffffff; 106static SV *on_next_submit;
107
108static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; 107static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS;
108static int max_outstanding;
109 109
110static int respipe_osf [2], respipe [2] = { -1, -1 }; 110static int respipe_osf [2], respipe [2] = { -1, -1 };
111 111
112static void req_destroy (aio_req req); 112static void req_destroy (aio_req req);
113static void req_cancel (aio_req req); 113static void req_cancel (aio_req req);
166 FREETMPS; 166 FREETMPS;
167 LEAVE; 167 LEAVE;
168 } 168 }
169} 169}
170 170
171static 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
171static int req_invoke (eio_req *req) 188static 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
408static int poll_cb (void) 425static 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
441static 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
439MODULE = IO::AIO PACKAGE = IO::AIO 467MODULE = 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
471void 502void
472max_poll_reqs (int nreqs) 503max_poll_reqs (int nreqs)
473 PROTOTYPE: $ 504 PROTOTYPE: $
918 949
919void 950void
920flush () 951flush ()
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
1025void _on_next_submit (SV *cb)
1026 CODE:
1027 SvREFCNT_dec (on_next_submit);
1028 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1029
994PROTOTYPES: DISABLE 1030PROTOTYPES: DISABLE
995 1031
996MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1032MODULE = IO::AIO PACKAGE = IO::AIO::REQ
997 1033
998void 1034void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines