… | |
… | |
17 | return s_fileno (fh, 0); |
17 | return s_fileno (fh, 0); |
18 | } |
18 | } |
19 | |
19 | |
20 | #ifndef GvCV_set |
20 | #ifndef GvCV_set |
21 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
21 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
|
|
22 | #endif |
|
|
23 | |
|
|
24 | #if EV_ENABLE_ASSERTIONS |
|
|
25 | # undef NDEBUG |
|
|
26 | # include <assert.h> |
22 | #endif |
27 | #endif |
23 | |
28 | |
24 | #define EV_STANDALONE 1 |
29 | #define EV_STANDALONE 1 |
25 | #define EV_PROTOTYPES 1 |
30 | #define EV_PROTOTYPES 1 |
26 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
31 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
27 | #define EV_USE_FLOOR 1 |
32 | #define EV_USE_FLOOR 1 |
28 | #define EV_API_STATIC |
33 | #define EV_API_STATIC |
29 | #define EV_H <ev.h> |
34 | #define EV_H "../libev/ev.h" |
30 | #define EV_CONFIG_H error |
35 | #define EV_CONFIG_H error |
31 | #include "EV/EVAPI.h" |
36 | #include "EV/EVAPI.h" |
32 | |
37 | |
33 | #define EV_SELECT_IS_WINSOCKET 0 |
38 | #define EV_SELECT_IS_WINSOCKET 0 |
34 | #ifdef _WIN32 |
39 | #ifdef _WIN32 |
… | |
… | |
37 | # define fd_mask Perl_fd_mask |
42 | # define fd_mask Perl_fd_mask |
38 | #endif |
43 | #endif |
39 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
44 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
40 | #include "libev/ev.c" |
45 | #include "libev/ev.c" |
41 | |
46 | |
42 | #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK |
47 | #if !defined _WIN32 && !defined __minix && !EV_NO_ATFORK |
43 | # include <pthread.h> |
48 | # include <pthread.h> |
44 | #endif |
49 | #endif |
45 | |
50 | |
46 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
51 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
47 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
52 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
… | |
… | |
77 | do { \ |
82 | do { \ |
78 | REF (w); \ |
83 | REF (w); \ |
79 | ev_ ## type ## _stop (e_loop (w), w); \ |
84 | ev_ ## type ## _stop (e_loop (w), w); \ |
80 | } while (0) |
85 | } while (0) |
81 | |
86 | |
|
|
87 | #define PAUSE(type) \ |
|
|
88 | do { \ |
|
|
89 | int active = ev_is_active (w); \ |
|
|
90 | if (active) STOP (type, w) |
|
|
91 | |
|
|
92 | #define RESUME(type) \ |
|
|
93 | if (active) START (type, w); \ |
|
|
94 | } while (0) |
|
|
95 | |
|
|
96 | |
82 | #define RESET(type,w,seta) \ |
97 | #define RESET(type,w,seta) \ |
83 | do { \ |
98 | PAUSE (type); \ |
84 | int active = ev_is_active (w); \ |
|
|
85 | if (active) STOP (type, w); \ |
|
|
86 | ev_ ## type ## _set seta; \ |
99 | ev_ ## type ## _set seta; \ |
87 | if (active) START (type, w); \ |
100 | RESUME (type) |
88 | } while (0) |
|
|
89 | |
101 | |
90 | typedef int Signal; |
102 | typedef int Signal; |
91 | |
103 | |
92 | /* horrible... */ |
104 | /* horrible... */ |
93 | #define CHECK_SIGNAL_CAN_START(w) \ |
105 | #define CHECK_SIGNAL_CAN_START(w) \ |
… | |
… | |
197 | dSP; |
209 | dSP; |
198 | I32 mark = SP - PL_stack_base; |
210 | I32 mark = SP - PL_stack_base; |
199 | SV *sv_self, *sv_events; |
211 | SV *sv_self, *sv_events; |
200 | |
212 | |
201 | /* libev might have stopped the watcher */ |
213 | /* libev might have stopped the watcher */ |
202 | if (expect_false (w->e_flags & WFLAG_UNREFED) |
214 | if (ecb_expect_false (w->e_flags & WFLAG_UNREFED) |
203 | && !ev_is_active (w)) |
215 | && !ev_is_active (w)) |
204 | REF (w); |
216 | REF (w); |
205 | |
217 | |
206 | if (expect_true (sv_self_cache)) |
218 | if (ecb_expect_true (sv_self_cache)) |
207 | { |
219 | { |
208 | sv_self = sv_self_cache; sv_self_cache = 0; |
220 | sv_self = sv_self_cache; sv_self_cache = 0; |
209 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
221 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
210 | } |
222 | } |
211 | else |
223 | else |
212 | { |
224 | { |
213 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
225 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
214 | SvREADONLY_on (sv_self); |
226 | SvREADONLY_on (sv_self); |
215 | } |
227 | } |
216 | |
228 | |
217 | if (expect_true (sv_events_cache)) |
229 | if (ecb_expect_true (sv_events_cache)) |
218 | { |
230 | { |
219 | sv_events = sv_events_cache; sv_events_cache = 0; |
231 | sv_events = sv_events_cache; sv_events_cache = 0; |
220 | SvIV_set (sv_events, revents); |
232 | SvIV_set (sv_events, revents); |
221 | SvIOK_only (sv_events); |
233 | SvIOK_only (sv_events); |
222 | } |
234 | } |
… | |
… | |
232 | PUSHs (sv_events); |
244 | PUSHs (sv_events); |
233 | |
245 | |
234 | PUTBACK; |
246 | PUTBACK; |
235 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
247 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
236 | |
248 | |
237 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
249 | if (ecb_expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
238 | SvREFCNT_dec (sv_self); |
250 | SvREFCNT_dec (sv_self); |
239 | else |
251 | else |
240 | { |
252 | { |
241 | SvREFCNT_dec (SvRV (sv_self)); |
253 | SvREFCNT_dec (SvRV (sv_self)); |
242 | SvRV_set (sv_self, &PL_sv_undef); |
254 | SvRV_set (sv_self, &PL_sv_undef); |
243 | sv_self_cache = sv_self; |
255 | sv_self_cache = sv_self; |
244 | } |
256 | } |
245 | |
257 | |
246 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
258 | if (ecb_expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
247 | SvREFCNT_dec (sv_events); |
259 | SvREFCNT_dec (sv_events); |
248 | else |
260 | else |
249 | sv_events_cache = sv_events; |
261 | sv_events_cache = sv_events; |
250 | |
262 | |
251 | if (expect_false (SvTRUE (ERRSV))) |
263 | if (ecb_expect_false (SvTRUE (ERRSV))) |
252 | { |
264 | { |
253 | SPAGAIN; |
265 | SPAGAIN; |
254 | PUSHMARK (SP); |
266 | PUSHMARK (SP); |
255 | PUTBACK; |
267 | PUTBACK; |
256 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
268 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
… | |
… | |
534 | |
546 | |
535 | sv_setiv (sv, (IV)&evapi); |
547 | sv_setiv (sv, (IV)&evapi); |
536 | SvREADONLY_on (sv); |
548 | SvREADONLY_on (sv); |
537 | } |
549 | } |
538 | #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK |
550 | #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK |
539 | #if __linux |
551 | /* unfortunately, musl neither implements the linux standard base, |
|
|
552 | /* nor makes itself detectable via macros. yeah, right... */ |
|
|
553 | #if __linux && (__GLIBC__ || __UCLIBC__) |
540 | int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle); |
554 | int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle); |
541 | __register_atfork (0, 0, default_fork, 0); |
555 | __register_atfork (0, 0, default_fork, 0); |
542 | #else |
556 | #else |
543 | pthread_atfork (0, 0, default_fork); |
557 | pthread_atfork (0, 0, default_fork); |
544 | #endif |
558 | #endif |
… | |
… | |
580 | NV ev_time () |
594 | NV ev_time () |
581 | |
595 | |
582 | void ev_feed_signal (SV *signal) |
596 | void ev_feed_signal (SV *signal) |
583 | CODE: |
597 | CODE: |
584 | { |
598 | { |
585 | Signal signum = s_signum (signal); |
599 | Signal signum = s_signum (signal); |
586 | CHECK_SIG (signal, signum); |
600 | CHECK_SIG (signal, signum); |
587 | |
601 | |
588 | ev_feed_signal (signum); |
602 | ev_feed_signal (signum); |
589 | } |
603 | } |
590 | |
604 | |
… | |
… | |
692 | periodic_ns = 1 |
706 | periodic_ns = 1 |
693 | INIT: |
707 | INIT: |
694 | CHECK_REPEAT (interval); |
708 | CHECK_REPEAT (interval); |
695 | CODE: |
709 | CODE: |
696 | { |
710 | { |
697 | ev_periodic *w; |
711 | ev_periodic *w; |
698 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
712 | w = e_new (sizeof (ev_periodic), cb, default_loop_sv); |
699 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
713 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
700 | ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); |
714 | ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); |
701 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
715 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
702 | if (!ix) START (periodic, w); |
716 | if (!ix) START (periodic, w); |
… | |
… | |
707 | ev_signal *signal (SV *signal, SV *cb) |
721 | ev_signal *signal (SV *signal, SV *cb) |
708 | ALIAS: |
722 | ALIAS: |
709 | signal_ns = 1 |
723 | signal_ns = 1 |
710 | CODE: |
724 | CODE: |
711 | { |
725 | { |
712 | Signal signum = s_signum (signal); |
726 | Signal signum = s_signum (signal); |
713 | CHECK_SIG (signal, signum); |
727 | CHECK_SIG (signal, signum); |
714 | |
728 | |
715 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
729 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
716 | ev_signal_set (RETVAL, signum); |
730 | ev_signal_set (RETVAL, signum); |
717 | if (!ix) START_SIGNAL (RETVAL); |
731 | if (!ix) START_SIGNAL (RETVAL); |
… | |
… | |
988 | CODE: |
1002 | CODE: |
989 | { |
1003 | { |
990 | RETVAL = w->events; |
1004 | RETVAL = w->events; |
991 | |
1005 | |
992 | if (items > 1) |
1006 | if (items > 1) |
993 | RESET (io, w, (w, w->fd, new_events)); |
1007 | { |
|
|
1008 | PAUSE (io); |
|
|
1009 | ev_io_modify (w, new_events); |
|
|
1010 | RESUME (io); |
|
|
1011 | } |
994 | } |
1012 | } |
995 | OUTPUT: |
1013 | OUTPUT: |
996 | RETVAL |
1014 | RETVAL |
997 | |
1015 | |
998 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
1016 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
… | |
… | |
1045 | |
1063 | |
1046 | void ev_timer_stop (ev_timer *w) |
1064 | void ev_timer_stop (ev_timer *w) |
1047 | CODE: |
1065 | CODE: |
1048 | STOP (timer, w); |
1066 | STOP (timer, w); |
1049 | |
1067 | |
1050 | void ev_timer_again (ev_timer *w) |
1068 | void ev_timer_again (ev_timer *w, NV repeat = NO_INIT) |
1051 | INIT: |
1069 | CODE: |
|
|
1070 | if (items > 1) |
|
|
1071 | w->repeat = repeat; |
1052 | CHECK_REPEAT (w->repeat); |
1072 | CHECK_REPEAT (w->repeat); |
1053 | CODE: |
|
|
1054 | ev_timer_again (e_loop (w), w); |
1073 | ev_timer_again (e_loop (w), w); |
1055 | UNREF (w); |
1074 | UNREF (w); |
1056 | |
1075 | |
1057 | NV ev_timer_remaining (ev_timer *w) |
1076 | NV ev_timer_remaining (ev_timer *w) |
1058 | C_ARGS: e_loop (w), w |
1077 | C_ARGS: e_loop (w), w |