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.126 by root, Thu Sep 25 07:56:07 2008 UTC vs.
Revision 1.130 by root, Thu Oct 2 11:35:03 2008 UTC

80# define SvVAL64 SvIV 80# define SvVAL64 SvIV
81#else 81#else
82# define SvVAL64 SvNV 82# define SvVAL64 SvNV
83#endif 83#endif
84 84
85/*****************************************************************************/
86
87#if __GNUC__ >= 3
88# define expect(expr,value) __builtin_expect ((expr),(value))
89#else
90# define expect(expr,value) (expr)
91#endif
92
93#define expect_false(expr) expect ((expr) != 0, 0)
94#define expect_true(expr) expect ((expr) != 0, 1)
95
96/*****************************************************************************/
97
85static HV *stash; 98static HV *stash;
86typedef SV SV8; /* byte-sv, used for argument-checking */ 99typedef SV SV8; /* byte-sv, used for argument-checking */
87 100
88#define AIO_REQ_KLASS "IO::AIO::REQ" 101#define AIO_REQ_KLASS "IO::AIO::REQ"
89#define AIO_GRP_KLASS "IO::AIO::GRP" 102#define AIO_GRP_KLASS "IO::AIO::GRP"
181 194
182static void req_submit (eio_req *req) 195static void req_submit (eio_req *req)
183{ 196{
184 eio_submit (req); 197 eio_submit (req);
185 198
186 if (on_next_submit) 199 if (expect_false (on_next_submit))
187 { 200 {
188 dSP; 201 dSP;
189 SV *cb = sv_2mortal (on_next_submit); 202 SV *cb = sv_2mortal (on_next_submit);
190 203
191 on_next_submit = 0; 204 on_next_submit = 0;
201 dSP; 214 dSP;
202 215
203 if (req->flags & FLAG_SV2_RO_OFF) 216 if (req->flags & FLAG_SV2_RO_OFF)
204 SvREADONLY_off (req->sv2); 217 SvREADONLY_off (req->sv2);
205 218
206 if (!EIO_CANCELLED (req) && SvOK (req->callback)) 219 if (!EIO_CANCELLED (req) && req->callback)
207 { 220 {
208 ENTER; 221 ENTER;
209 SAVETMPS; 222 SAVETMPS;
210 PUSHMARK (SP); 223 PUSHMARK (SP);
211 EXTEND (SP, 1); 224 EXTEND (SP, 1);
448static void atfork_child (void) 461static void atfork_child (void)
449{ 462{
450 create_respipe (); 463 create_respipe ();
451} 464}
452 465
466static SV *
467get_cb (SV *cb_sv)
468{
469 HV *st;
470 GV *gvp;
471 CV *cv;
472
473 if (!SvOK (cb_sv))
474 return 0;
475
476 cv = sv_2cv (cb_sv, &st, &gvp, 0);
477
478 if (!cv)
479 croak ("IO::AIO callback must be undef or a CODE reference");
480
481 return (SV *)cv;
482}
483
453#define dREQ \ 484#define dREQ \
485 SV *cb_cv; \
454 aio_req req; \ 486 aio_req req; \
455 int req_pri = next_pri; \ 487 int req_pri = next_pri; \
456 next_pri = EIO_PRI_DEFAULT; \ 488 next_pri = EIO_PRI_DEFAULT; \
457 \ 489 \
458 if (SvOK (callback) && !SvROK (callback)) \ 490 cb_cv = get_cb (callback); \
459 croak ("callback must be undef or of reference type"); \
460 \ 491 \
461 Newz (0, req, 1, eio_req); \ 492 Newz (0, req, 1, eio_req); \
462 if (!req) \ 493 if (!req) \
463 croak ("out of memory during eio_req allocation"); \ 494 croak ("out of memory during eio_req allocation"); \
464 \ 495 \
465 req->callback = newSVsv (callback); \ 496 req->callback = SvREFCNT_inc (cb_cv); \
466 req->pri = req_pri 497 req->pri = req_pri
467 498
468#define REQ_SEND \ 499#define REQ_SEND \
469 PUTBACK; \ 500 PUTBACK; \
470 req_submit (req); \ 501 req_submit (req); \
639 req->sv1 = newSVsv (fh); 670 req->sv1 = newSVsv (fh);
640 req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) 671 req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh))
641 : IoOFP (sv_2io (fh))); 672 : IoOFP (sv_2io (fh)));
642 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 673 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
643 req->size = len; 674 req->size = len;
644 req->sv2 = SvREFCNT_inc (data); 675 req->sv2 = SvREFCNT_inc_NN (data);
645 req->ptr2 = (char *)svptr + dataoffset; 676 req->ptr2 = (char *)svptr + dataoffset;
646 req->stroffset = dataoffset; 677 req->stroffset = dataoffset;
647 678
648 if (!SvREADONLY (data)) 679 if (!SvREADONLY (data))
649 { 680 {
896{ 927{
897 dREQ; 928 dREQ;
898 929
899 req->type = EIO_GROUP; 930 req->type = EIO_GROUP;
900 931
901 eio_submit (req); 932 req_submit (req);
902 XPUSHs (req_sv (req, AIO_GRP_KLASS)); 933 XPUSHs (req_sv (req, AIO_GRP_KLASS));
903} 934}
904 935
905void 936void
906aio_nop (SV *callback=&PL_sv_undef) 937aio_nop (SV *callback=&PL_sv_undef)
1025 CODE: 1056 CODE:
1026 eio_cancel (req); 1057 eio_cancel (req);
1027 1058
1028void 1059void
1029cb (aio_req_ornot req, SV *callback=&PL_sv_undef) 1060cb (aio_req_ornot req, SV *callback=&PL_sv_undef)
1030 CODE: 1061 PPCODE:
1062{
1063 if (GIMME_V != G_VOID)
1064 XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef);
1065
1066 if (items > 1)
1067 {
1068 SV *cb_cv = get_cb (callback);
1069
1031 SvREFCNT_dec (req->callback); 1070 SvREFCNT_dec (req->callback);
1032 req->callback = newSVsv (callback); 1071 req->callback = SvREFCNT_inc (cb_cv);
1072 }
1073}
1033 1074
1034MODULE = IO::AIO PACKAGE = IO::AIO::GRP 1075MODULE = IO::AIO PACKAGE = IO::AIO::GRP
1035 1076
1036void 1077void
1037add (aio_req grp, ...) 1078add (aio_req grp, ...)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines