… | |
… | |
33 | |
33 | |
34 | #ifndef _WIN32 |
34 | #ifndef _WIN32 |
35 | # include <pthread.h> |
35 | # include <pthread.h> |
36 | #endif |
36 | #endif |
37 | |
37 | |
38 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
38 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
|
|
39 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
|
|
40 | #define e_self(w) ((ev_watcher *)(w))->self |
|
|
41 | #define e_fh(w) ((ev_watcher *)(w))->fh |
|
|
42 | #define e_data(w) ((ev_watcher *)(w))->data |
39 | |
43 | |
40 | #define WFLAG_KEEPALIVE 1 |
44 | #define WFLAG_KEEPALIVE 1 |
41 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
45 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
42 | |
46 | |
43 | #define UNREF(w) \ |
47 | #define UNREF(w) \ |
44 | if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ |
48 | if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ |
45 | && ev_is_active (w)) \ |
49 | && ev_is_active (w)) \ |
46 | { \ |
50 | { \ |
47 | ev_unref (e_loop (w)); \ |
51 | ev_unref (e_loop (w)); \ |
48 | (w)->e_flags |= WFLAG_UNREFED; \ |
52 | e_flags (w) |= WFLAG_UNREFED; \ |
49 | } |
53 | } |
50 | |
54 | |
51 | #define REF(w) \ |
55 | #define REF(w) \ |
52 | if ((w)->e_flags & WFLAG_UNREFED) \ |
56 | if (e_flags (w) & WFLAG_UNREFED) \ |
53 | { \ |
57 | { \ |
54 | (w)->e_flags &= ~WFLAG_UNREFED; \ |
58 | e_flags (w) &= ~WFLAG_UNREFED; \ |
55 | ev_ref (e_loop (w)); \ |
59 | ev_ref (e_loop (w)); \ |
56 | } |
60 | } |
57 | |
61 | |
58 | #define START(type,w) \ |
62 | #define START(type,w) \ |
59 | do { \ |
63 | do { \ |
… | |
… | |
123 | ///////////////////////////////////////////////////////////////////////////// |
127 | ///////////////////////////////////////////////////////////////////////////// |
124 | // Event |
128 | // Event |
125 | |
129 | |
126 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
130 | static void e_cb (EV_P_ ev_watcher *w, int revents); |
127 | |
131 | |
128 | static void * |
132 | void * |
129 | e_new (int size, SV *cb_sv, SV *loop) |
133 | e_new (int size, SV *cb_sv, SV *loop) |
130 | { |
134 | { |
131 | SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; |
135 | SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; |
132 | ev_watcher *w; |
136 | ev_watcher *w; |
133 | SV *self = NEWSV (0, size); |
137 | SV *self = NEWSV (0, size); |
… | |
… | |
195 | sv_self = sv_self_cache; sv_self_cache = 0; |
199 | sv_self = sv_self_cache; sv_self_cache = 0; |
196 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
200 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
197 | } |
201 | } |
198 | else |
202 | else |
199 | { |
203 | { |
200 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
204 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
201 | SvREADONLY_on (sv_self); |
205 | SvREADONLY_on (sv_self); |
202 | } |
206 | } |
203 | |
207 | |
204 | if (expect_true (sv_events_cache)) |
208 | if (expect_true (sv_events_cache)) |
205 | { |
209 | { |
… | |
… | |
296 | ENTER; |
300 | ENTER; |
297 | SAVETMPS; |
301 | SAVETMPS; |
298 | |
302 | |
299 | PUSHMARK (SP); |
303 | PUSHMARK (SP); |
300 | EXTEND (SP, 2); |
304 | EXTEND (SP, 2); |
301 | PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ |
305 | PUSHs (newRV_inc (e_self (w))); /* e_self (w) MUST be blessed by now */ |
302 | PUSHs (newSVnv (now)); |
306 | PUSHs (newSVnv (now)); |
303 | |
307 | |
304 | PUTBACK; |
308 | PUTBACK; |
305 | count = call_sv (w->fh, G_SCALAR | G_EVAL); |
309 | count = call_sv (w->fh, G_SCALAR | G_EVAL); |
306 | SPAGAIN; |
310 | SPAGAIN; |
… | |
… | |
598 | ix = 0; |
602 | ix = 0; |
599 | events = events ? EV_WRITE : EV_READ; |
603 | events = events ? EV_WRITE : EV_READ; |
600 | } |
604 | } |
601 | |
605 | |
602 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
606 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
603 | RETVAL->fh = newSVsv (fh); |
607 | e_fh (RETVAL) = newSVsv (fh); |
604 | ev_io_set (RETVAL, fd, events); |
608 | ev_io_set (RETVAL, fd, events); |
605 | if (!ix) START (io, RETVAL); |
609 | if (!ix) START (io, RETVAL); |
606 | } |
610 | } |
607 | OUTPUT: |
611 | OUTPUT: |
608 | RETVAL |
612 | RETVAL |
… | |
… | |
626 | CHECK_REPEAT (interval); |
630 | CHECK_REPEAT (interval); |
627 | CODE: |
631 | CODE: |
628 | { |
632 | { |
629 | ev_periodic *w; |
633 | ev_periodic *w; |
630 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
634 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
631 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
635 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
632 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
636 | ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); |
633 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
637 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
634 | if (!ix) START (periodic, w); |
638 | if (!ix) START (periodic, w); |
635 | } |
639 | } |
636 | OUTPUT: |
640 | OUTPUT: |
637 | RETVAL |
641 | RETVAL |
… | |
… | |
704 | ev_stat *stat (SV *path, NV interval, SV *cb) |
708 | ev_stat *stat (SV *path, NV interval, SV *cb) |
705 | ALIAS: |
709 | ALIAS: |
706 | stat_ns = 1 |
710 | stat_ns = 1 |
707 | CODE: |
711 | CODE: |
708 | RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); |
712 | RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv); |
709 | RETVAL->fh = newSVsv (path); |
713 | e_fh (RETVAL) = newSVsv (path); |
710 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
714 | ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval); |
711 | if (!ix) START (stat, RETVAL); |
715 | if (!ix) START (stat, RETVAL); |
712 | OUTPUT: |
716 | OUTPUT: |
713 | RETVAL |
717 | RETVAL |
714 | |
718 | |
715 | ev_embed *embed (struct ev_loop *loop, SV *cb = 0) |
719 | ev_embed *embed (struct ev_loop *loop, SV *cb = 0) |
… | |
… | |
719 | { |
723 | { |
720 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
724 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
721 | croak ("passed loop is not embeddable via EV::embed,"); |
725 | croak ("passed loop is not embeddable via EV::embed,"); |
722 | |
726 | |
723 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
727 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
724 | RETVAL->fh = newSVsv (ST (0)); |
728 | e_fh (RETVAL) = newSVsv (ST (0)); |
725 | ev_embed_set (RETVAL, loop); |
729 | ev_embed_set (RETVAL, loop); |
726 | if (!ix) START (embed, RETVAL); |
730 | if (!ix) START (embed, RETVAL); |
727 | } |
731 | } |
728 | OUTPUT: |
732 | OUTPUT: |
729 | RETVAL |
733 | RETVAL |
… | |
… | |
867 | CODE: |
871 | CODE: |
868 | { |
872 | { |
869 | int fd = s_fileno (fh, events & EV_WRITE); |
873 | int fd = s_fileno (fh, events & EV_WRITE); |
870 | CHECK_FD (fh, fd); |
874 | CHECK_FD (fh, fd); |
871 | |
875 | |
872 | sv_setsv (w->fh, fh); |
876 | sv_setsv (e_fh (w), fh); |
873 | RESET (io, w, (w, fd, events)); |
877 | RESET (io, w, (w, fd, events)); |
874 | } |
878 | } |
875 | |
879 | |
876 | SV *fh (ev_io *w, SV *new_fh = 0) |
880 | SV *fh (ev_io *w, SV *new_fh = 0) |
877 | CODE: |
881 | CODE: |
… | |
… | |
879 | if (items > 1) |
883 | if (items > 1) |
880 | { |
884 | { |
881 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
885 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
882 | CHECK_FD (new_fh, fd); |
886 | CHECK_FD (new_fh, fd); |
883 | |
887 | |
884 | RETVAL = w->fh; |
888 | RETVAL = e_fh (w); |
885 | w->fh = newSVsv (new_fh); |
889 | e_fh (w) = newSVsv (new_fh); |
886 | |
890 | |
887 | RESET (io, w, (w, fd, w->events)); |
891 | RESET (io, w, (w, fd, w->events)); |
888 | } |
892 | } |
889 | else |
893 | else |
890 | RETVAL = newSVsv (w->fh); |
894 | RETVAL = newSVsv (e_fh (w)); |
891 | } |
895 | } |
892 | OUTPUT: |
896 | OUTPUT: |
893 | RETVAL |
897 | RETVAL |
894 | |
898 | |
895 | int events (ev_io *w, int new_events = EV_UNDEF) |
899 | int events (ev_io *w, int new_events = EV_UNDEF) |
… | |
… | |
1001 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
1005 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
1002 | INIT: |
1006 | INIT: |
1003 | CHECK_REPEAT (interval); |
1007 | CHECK_REPEAT (interval); |
1004 | CODE: |
1008 | CODE: |
1005 | { |
1009 | { |
1006 | SvREFCNT_dec (w->fh); |
1010 | SvREFCNT_dec (e_fh (w)); |
1007 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
1011 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
1008 | |
1012 | |
1009 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
1013 | RESET (periodic, w, (w, at, interval, e_fh (w) ? e_periodic_cb : 0)); |
1010 | } |
1014 | } |
1011 | |
1015 | |
1012 | NV at (ev_periodic *w) |
1016 | NV at (ev_periodic *w) |
1013 | CODE: |
1017 | CODE: |
1014 | RETVAL = ev_periodic_at (w); |
1018 | RETVAL = ev_periodic_at (w); |
… | |
… | |
1121 | e_destroy (w); |
1125 | e_destroy (w); |
1122 | |
1126 | |
1123 | void set (ev_stat *w, SV *path, NV interval) |
1127 | void set (ev_stat *w, SV *path, NV interval) |
1124 | CODE: |
1128 | CODE: |
1125 | { |
1129 | { |
1126 | sv_setsv (w->fh, path); |
1130 | sv_setsv (e_fh (w), path); |
1127 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), interval)); |
1131 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval)); |
1128 | } |
1132 | } |
1129 | |
1133 | |
1130 | SV *path (ev_stat *w, SV *new_path = 0) |
1134 | SV *path (ev_stat *w, SV *new_path = 0) |
1131 | CODE: |
1135 | CODE: |
1132 | { |
1136 | { |
1133 | RETVAL = SvREFCNT_inc (w->fh); |
1137 | RETVAL = SvREFCNT_inc (e_fh (w)); |
1134 | |
1138 | |
1135 | if (items > 1) |
1139 | if (items > 1) |
1136 | { |
1140 | { |
1137 | SvREFCNT_dec (w->fh); |
1141 | SvREFCNT_dec (e_fh (w)); |
1138 | w->fh = newSVsv (new_path); |
1142 | e_fh (w) = newSVsv (new_path); |
1139 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), w->interval)); |
1143 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval)); |
1140 | } |
1144 | } |
1141 | } |
1145 | } |
1142 | OUTPUT: |
1146 | OUTPUT: |
1143 | RETVAL |
1147 | RETVAL |
1144 | |
1148 | |
… | |
… | |
1146 | CODE: |
1150 | CODE: |
1147 | { |
1151 | { |
1148 | RETVAL = w->interval; |
1152 | RETVAL = w->interval; |
1149 | |
1153 | |
1150 | if (items > 1) |
1154 | if (items > 1) |
1151 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
1155 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval)); |
1152 | } |
1156 | } |
1153 | OUTPUT: |
1157 | OUTPUT: |
1154 | RETVAL |
1158 | RETVAL |
1155 | |
1159 | |
1156 | void prev (ev_stat *w) |
1160 | void prev (ev_stat *w) |
… | |
… | |
1215 | e_destroy (w); |
1219 | e_destroy (w); |
1216 | |
1220 | |
1217 | void set (ev_embed *w, struct ev_loop *loop) |
1221 | void set (ev_embed *w, struct ev_loop *loop) |
1218 | CODE: |
1222 | CODE: |
1219 | { |
1223 | { |
1220 | sv_setsv (w->fh, ST (1)); |
1224 | sv_setsv (e_fh (w), ST (1)); |
1221 | RESET (embed, w, (w, loop)); |
1225 | RESET (embed, w, (w, loop)); |
1222 | } |
1226 | } |
1223 | |
1227 | |
1224 | SV *other (ev_embed *w) |
1228 | SV *other (ev_embed *w) |
1225 | CODE: |
1229 | CODE: |
1226 | RETVAL = newSVsv (w->fh); |
1230 | RETVAL = newSVsv (e_fh (w)); |
1227 | OUTPUT: |
1231 | OUTPUT: |
1228 | RETVAL |
1232 | RETVAL |
1229 | |
1233 | |
1230 | void ev_embed_sweep (ev_embed *w) |
1234 | void ev_embed_sweep (ev_embed *w) |
1231 | C_ARGS: e_loop (w), w |
1235 | C_ARGS: e_loop (w), w |
… | |
… | |
1326 | { |
1330 | { |
1327 | int fd = s_fileno (fh, events & EV_WRITE); |
1331 | int fd = s_fileno (fh, events & EV_WRITE); |
1328 | CHECK_FD (fh, fd); |
1332 | CHECK_FD (fh, fd); |
1329 | |
1333 | |
1330 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
1334 | RETVAL = e_new (sizeof (ev_io), cb, ST (0)); |
1331 | RETVAL->fh = newSVsv (fh); |
1335 | e_fh (RETVAL) = newSVsv (fh); |
1332 | ev_io_set (RETVAL, fd, events); |
1336 | ev_io_set (RETVAL, fd, events); |
1333 | if (!ix) START (io, RETVAL); |
1337 | if (!ix) START (io, RETVAL); |
1334 | } |
1338 | } |
1335 | OUTPUT: |
1339 | OUTPUT: |
1336 | RETVAL |
1340 | RETVAL |
… | |
… | |
1354 | CHECK_REPEAT (interval); |
1358 | CHECK_REPEAT (interval); |
1355 | CODE: |
1359 | CODE: |
1356 | { |
1360 | { |
1357 | ev_periodic *w; |
1361 | ev_periodic *w; |
1358 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
1362 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
1359 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
1363 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
1360 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
1364 | ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); |
1361 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
1365 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
1362 | if (!ix) START (periodic, w); |
1366 | if (!ix) START (periodic, w); |
1363 | } |
1367 | } |
1364 | OUTPUT: |
1368 | OUTPUT: |
1365 | RETVAL |
1369 | RETVAL |
… | |
… | |
1432 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |
1436 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |
1433 | ALIAS: |
1437 | ALIAS: |
1434 | stat_ns = 1 |
1438 | stat_ns = 1 |
1435 | CODE: |
1439 | CODE: |
1436 | RETVAL = e_new (sizeof (ev_stat), cb, ST (0)); |
1440 | RETVAL = e_new (sizeof (ev_stat), cb, ST (0)); |
1437 | RETVAL->fh = newSVsv (path); |
1441 | e_fh (RETVAL) = newSVsv (path); |
1438 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
1442 | ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval); |
1439 | if (!ix) START (stat, RETVAL); |
1443 | if (!ix) START (stat, RETVAL); |
1440 | OUTPUT: |
1444 | OUTPUT: |
1441 | RETVAL |
1445 | RETVAL |
1442 | |
1446 | |
1443 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0) |
1447 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0) |
… | |
… | |
1447 | { |
1451 | { |
1448 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
1452 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
1449 | croak ("passed loop is not embeddable via EV::embed,"); |
1453 | croak ("passed loop is not embeddable via EV::embed,"); |
1450 | |
1454 | |
1451 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
1455 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
1452 | RETVAL->fh = newSVsv (ST (1)); |
1456 | e_fh (RETVAL) = newSVsv (ST (1)); |
1453 | ev_embed_set (RETVAL, other); |
1457 | ev_embed_set (RETVAL, other); |
1454 | if (!ix) START (embed, RETVAL); |
1458 | if (!ix) START (embed, RETVAL); |
1455 | } |
1459 | } |
1456 | OUTPUT: |
1460 | OUTPUT: |
1457 | RETVAL |
1461 | RETVAL |