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.118 by root, Sun May 11 00:01:03 2008 UTC

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
103typedef eio_req *aio_req; 106typedef eio_req *aio_req;
104typedef eio_req *aio_req_ornot; 107typedef eio_req *aio_req_ornot;
105 108
106static unsigned int max_outstanding = 0x7fffffff; 109static SV *on_next_submit;
107
108static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; 110static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS;
111static int max_outstanding;
109 112
110static int respipe_osf [2], respipe [2] = { -1, -1 }; 113static int respipe_osf [2], respipe [2] = { -1, -1 };
111 114
112static void req_destroy (aio_req req); 115static void req_destroy (aio_req req);
113static void req_cancel (aio_req req); 116static void req_cancel (aio_req req);
166 FREETMPS; 169 FREETMPS;
167 LEAVE; 170 LEAVE;
168 } 171 }
169} 172}
170 173
174static 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
171static int req_invoke (eio_req *req) 191static 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
408static int poll_cb (void) 428static 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
444static 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
439MODULE = IO::AIO PACKAGE = IO::AIO 470MODULE = 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
471void 505void
472max_poll_reqs (int nreqs) 506max_poll_reqs (int nreqs)
473 PROTOTYPE: $ 507 PROTOTYPE: $
918 952
919void 953void
920flush () 954flush ()
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
1028void _on_next_submit (SV *cb)
1029 CODE:
1030 SvREFCNT_dec (on_next_submit);
1031 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1032
994PROTOTYPES: DISABLE 1033PROTOTYPES: DISABLE
995 1034
996MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1035MODULE = IO::AIO PACKAGE = IO::AIO::REQ
997 1036
998void 1037void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines