… | |
… | |
23 | #include "libev/ev.c" |
23 | #include "libev/ev.c" |
24 | |
24 | |
25 | #ifndef _WIN32 |
25 | #ifndef _WIN32 |
26 | # include <pthread.h> |
26 | # include <pthread.h> |
27 | #endif |
27 | #endif |
|
|
28 | |
|
|
29 | /* 5.10.0 */ |
|
|
30 | #ifndef SvREFCNT_inc_NN |
|
|
31 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
|
|
32 | #endif |
|
|
33 | |
|
|
34 | /* 5.6.x */ |
|
|
35 | #ifndef SvRV_set |
|
|
36 | # define SvRV_set(a,b) SvRV ((a)) = (b) |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | #if __GNUC__ >= 3 |
|
|
40 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
41 | #else |
|
|
42 | # define expect(expr,value) (expr) |
|
|
43 | #endif |
|
|
44 | |
|
|
45 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
46 | #define expect_true(expr) expect ((expr) != 0, 1) |
28 | |
47 | |
29 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
48 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
30 | |
49 | |
31 | #define WFLAG_KEEPALIVE 1 |
50 | #define WFLAG_KEEPALIVE 1 |
32 | |
51 | |
… | |
… | |
191 | } |
210 | } |
192 | |
211 | |
193 | return rv; |
212 | return rv; |
194 | } |
213 | } |
195 | |
214 | |
196 | static SV *sv_events_cache; |
215 | static SV *sv_self_cache, *sv_events_cache; |
197 | |
216 | |
198 | static void |
217 | static void |
199 | e_cb (EV_P_ ev_watcher *w, int revents) |
218 | e_cb (EV_P_ ev_watcher *w, int revents) |
200 | { |
219 | { |
201 | dSP; |
220 | dSP; |
202 | I32 mark = SP - PL_stack_base; |
221 | I32 mark = SP - PL_stack_base; |
203 | SV *sv_self, *sv_events; |
222 | SV *sv_self, *sv_events; |
204 | |
223 | |
|
|
224 | if (expect_true (sv_self_cache)) |
|
|
225 | { |
|
|
226 | sv_self = sv_self_cache; sv_self_cache = 0; |
|
|
227 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
|
|
228 | } |
|
|
229 | else |
|
|
230 | { |
205 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
231 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
|
|
232 | SvREADONLY_on (sv_self); |
|
|
233 | } |
206 | |
234 | |
207 | if (sv_events_cache) |
235 | if (expect_true (sv_events_cache)) |
208 | { |
236 | { |
209 | sv_events = sv_events_cache; sv_events_cache = 0; |
237 | sv_events = sv_events_cache; sv_events_cache = 0; |
210 | SvIV_set (sv_events, revents); |
238 | SvIV_set (sv_events, revents); |
211 | } |
239 | } |
212 | else |
240 | else |
|
|
241 | { |
213 | sv_events = newSViv (revents); |
242 | sv_events = newSViv (revents); |
|
|
243 | SvREADONLY_on (sv_events); |
|
|
244 | } |
214 | |
245 | |
215 | PUSHMARK (SP); |
246 | PUSHMARK (SP); |
216 | EXTEND (SP, 2); |
247 | EXTEND (SP, 2); |
217 | PUSHs (sv_self); |
248 | PUSHs (sv_self); |
218 | PUSHs (sv_events); |
249 | PUSHs (sv_events); |
219 | |
250 | |
220 | PUTBACK; |
251 | PUTBACK; |
221 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
252 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
222 | |
253 | |
|
|
254 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
223 | SvREFCNT_dec (sv_self); |
255 | SvREFCNT_dec (sv_self); |
|
|
256 | else |
|
|
257 | { |
|
|
258 | SvREFCNT_dec (SvRV (sv_self)); |
|
|
259 | SvRV_set (sv_self, &PL_sv_undef); |
|
|
260 | sv_self_cache = sv_self; |
|
|
261 | } |
224 | |
262 | |
225 | if (sv_events_cache) |
263 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
226 | SvREFCNT_dec (sv_events); |
264 | SvREFCNT_dec (sv_events); |
227 | else |
265 | else |
228 | sv_events_cache = sv_events; |
266 | sv_events_cache = sv_events; |
229 | |
267 | |
230 | if (SvTRUE (ERRSV)) |
268 | if (expect_false (SvTRUE (ERRSV))) |
231 | { |
269 | { |
232 | SPAGAIN; |
270 | SPAGAIN; |
233 | PUSHMARK (SP); |
271 | PUSHMARK (SP); |
234 | PUTBACK; |
272 | PUTBACK; |
235 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
273 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
… | |
… | |
487 | |
525 | |
488 | unsigned int ev_recommended_backends () |
526 | unsigned int ev_recommended_backends () |
489 | |
527 | |
490 | unsigned int ev_embeddable_backends () |
528 | unsigned int ev_embeddable_backends () |
491 | |
529 | |
|
|
530 | void ev_sleep (NV interval) |
|
|
531 | |
492 | NV ev_time () |
532 | NV ev_time () |
493 | |
533 | |
494 | NV ev_now () |
534 | NV ev_now () |
495 | C_ARGS: evapi.default_loop |
535 | C_ARGS: evapi.default_loop |
496 | |
536 | |