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.124 by root, Thu May 29 03:20:40 2008 UTC vs.
Revision 1.129 by root, Tue Sep 30 17:03:53 2008 UTC

65# include <signal.h> 65# include <signal.h>
66# define EIO_STRUCT_DIRENT struct dirent 66# define EIO_STRUCT_DIRENT struct dirent
67 67
68#endif 68#endif
69 69
70/* perl stupidly overrides readdir and maybe others */
71/* with thread-unsafe versions, imagine that :( */
72#undef readdir
73#undef opendir
74#undef closedir
75
70#define EIO_STRUCT_STAT Stat_t 76#define EIO_STRUCT_STAT Stat_t
71 77
72/* use NV for 32 bit perls as it allows larger offsets */ 78/* use NV for 32 bit perls as it allows larger offsets */
73#if IVSIZE >= 8 79#if IVSIZE >= 8
74# define SvVAL64 SvIV 80# define SvVAL64 SvIV
75#else 81#else
76# define SvVAL64 SvNV 82# define SvVAL64 SvNV
77#endif 83#endif
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/*****************************************************************************/
78 97
79static HV *stash; 98static HV *stash;
80typedef SV SV8; /* byte-sv, used for argument-checking */ 99typedef SV SV8; /* byte-sv, used for argument-checking */
81 100
82#define AIO_REQ_KLASS "IO::AIO::REQ" 101#define AIO_REQ_KLASS "IO::AIO::REQ"
175 194
176static void req_submit (eio_req *req) 195static void req_submit (eio_req *req)
177{ 196{
178 eio_submit (req); 197 eio_submit (req);
179 198
180 if (on_next_submit) 199 if (expect_false (on_next_submit))
181 { 200 {
182 dSP; 201 dSP;
183 SV *cb = sv_2mortal (on_next_submit); 202 SV *cb = sv_2mortal (on_next_submit);
184 203
185 on_next_submit = 0; 204 on_next_submit = 0;
195 dSP; 214 dSP;
196 215
197 if (req->flags & FLAG_SV2_RO_OFF) 216 if (req->flags & FLAG_SV2_RO_OFF)
198 SvREADONLY_off (req->sv2); 217 SvREADONLY_off (req->sv2);
199 218
200 if (!EIO_CANCELLED (req) && SvOK (req->callback)) 219 if (!EIO_CANCELLED (req) && req->callback)
201 { 220 {
202 ENTER; 221 ENTER;
203 SAVETMPS; 222 SAVETMPS;
204 PUSHMARK (SP); 223 PUSHMARK (SP);
205 EXTEND (SP, 1); 224 EXTEND (SP, 1);
442static void atfork_child (void) 461static void atfork_child (void)
443{ 462{
444 create_respipe (); 463 create_respipe ();
445} 464}
446 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
447#define dREQ \ 484#define dREQ \
485 SV *cb_cv; \
448 aio_req req; \ 486 aio_req req; \
449 int req_pri = next_pri; \ 487 int req_pri = next_pri; \
450 next_pri = EIO_PRI_DEFAULT; \ 488 next_pri = EIO_PRI_DEFAULT; \
451 \ 489 \
452 if (SvOK (callback) && !SvROK (callback)) \ 490 cb_cv = get_cb (callback); \
453 croak ("callback must be undef or of reference type"); \
454 \ 491 \
455 Newz (0, req, 1, eio_req); \ 492 Newz (0, req, 1, eio_req); \
456 if (!req) \ 493 if (!req) \
457 croak ("out of memory during eio_req allocation"); \ 494 croak ("out of memory during eio_req allocation"); \
458 \ 495 \
459 req->callback = newSVsv (callback); \ 496 req->callback = SvREFCNT_inc (cb_cv); \
460 req->pri = req_pri 497 req->pri = req_pri
461 498
462#define REQ_SEND \ 499#define REQ_SEND \
500 PUTBACK; \
463 req_submit (req); \ 501 req_submit (req); \
502 SPAGAIN; \
464 \ 503 \
465 if (GIMME_V != G_VOID) \ 504 if (GIMME_V != G_VOID) \
466 XPUSHs (req_sv (req, AIO_REQ_KLASS)); 505 XPUSHs (req_sv (req, AIO_REQ_KLASS));
467 506
468MODULE = IO::AIO PACKAGE = IO::AIO 507MODULE = IO::AIO PACKAGE = IO::AIO
888{ 927{
889 dREQ; 928 dREQ;
890 929
891 req->type = EIO_GROUP; 930 req->type = EIO_GROUP;
892 931
893 eio_submit (req); 932 req_submit (req);
894 XPUSHs (req_sv (req, AIO_GRP_KLASS)); 933 XPUSHs (req_sv (req, AIO_GRP_KLASS));
895} 934}
896 935
897void 936void
898aio_nop (SV *callback=&PL_sv_undef) 937aio_nop (SV *callback=&PL_sv_undef)
1017 CODE: 1056 CODE:
1018 eio_cancel (req); 1057 eio_cancel (req);
1019 1058
1020void 1059void
1021cb (aio_req_ornot req, SV *callback=&PL_sv_undef) 1060cb (aio_req_ornot req, SV *callback=&PL_sv_undef)
1022 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
1023 SvREFCNT_dec (req->callback); 1070 SvREFCNT_dec (req->callback);
1024 req->callback = newSVsv (callback); 1071 req->callback = SvREFCNT_inc (cb_cv);
1072 }
1073}
1025 1074
1026MODULE = IO::AIO PACKAGE = IO::AIO::GRP 1075MODULE = IO::AIO PACKAGE = IO::AIO::GRP
1027 1076
1028void 1077void
1029add (aio_req grp, ...) 1078add (aio_req grp, ...)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines