… | |
… | |
34 | /* 5.6.x */ |
34 | /* 5.6.x */ |
35 | #ifndef SvRV_set |
35 | #ifndef SvRV_set |
36 | # define SvRV_set(a,b) SvRV ((a)) = (b) |
36 | # define SvRV_set(a,b) SvRV ((a)) = (b) |
37 | #endif |
37 | #endif |
38 | |
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) |
|
|
47 | |
|
|
48 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
39 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
49 | |
40 | |
50 | #define WFLAG_KEEPALIVE 1 |
41 | #define WFLAG_KEEPALIVE 1 |
|
|
42 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
51 | |
43 | |
52 | #define UNREF(w) \ |
44 | #define UNREF(w) \ |
53 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
45 | if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ |
54 | && !ev_is_active (w)) \ |
46 | && ev_is_active (w)) \ |
|
|
47 | { \ |
55 | ev_unref (e_loop (w)); |
48 | ev_unref (e_loop (w)); \ |
|
|
49 | (w)->e_flags |= WFLAG_UNREFED; \ |
|
|
50 | } |
56 | |
51 | |
57 | #define REF(w) \ |
52 | #define REF(w) \ |
58 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
53 | if ((w)->e_flags & WFLAG_UNREFED) \ |
59 | && ev_is_active (w)) \ |
54 | { \ |
|
|
55 | (w)->e_flags &= ~WFLAG_UNREFED; \ |
60 | ev_ref (e_loop (w)); |
56 | ev_ref (e_loop (w)); \ |
|
|
57 | } |
61 | |
58 | |
62 | #define START(type,w) \ |
59 | #define START(type,w) \ |
63 | do { \ |
60 | do { \ |
|
|
61 | ev_ ## type ## _start (e_loop (w), w); \ |
64 | UNREF (w); \ |
62 | UNREF (w); \ |
65 | ev_ ## type ## _start (e_loop (w), w); \ |
|
|
66 | } while (0) |
63 | } while (0) |
67 | |
64 | |
68 | #define STOP(type,w) \ |
65 | #define STOP(type,w) \ |
69 | do { \ |
66 | do { \ |
70 | REF (w); \ |
67 | REF (w); \ |
… | |
… | |
219 | { |
216 | { |
220 | dSP; |
217 | dSP; |
221 | I32 mark = SP - PL_stack_base; |
218 | I32 mark = SP - PL_stack_base; |
222 | SV *sv_self, *sv_events; |
219 | SV *sv_self, *sv_events; |
223 | |
220 | |
|
|
221 | /* libev might have stopped the watcher */ |
|
|
222 | if (expect_false (w->e_flags & WFLAG_UNREFED) |
|
|
223 | && !ev_is_active (w)) |
|
|
224 | REF (w); |
|
|
225 | |
224 | if (expect_true (sv_self_cache)) |
226 | if (expect_true (sv_self_cache)) |
225 | { |
227 | { |
226 | sv_self = sv_self_cache; sv_self_cache = 0; |
228 | sv_self = sv_self_cache; sv_self_cache = 0; |
227 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
229 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
228 | } |
230 | } |
… | |
… | |
249 | PUSHs (sv_events); |
251 | PUSHs (sv_events); |
250 | |
252 | |
251 | PUTBACK; |
253 | PUTBACK; |
252 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
254 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
253 | |
255 | |
254 | if (expect_false (sv_self_cache)) |
256 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
255 | SvREFCNT_dec (sv_self); |
257 | SvREFCNT_dec (sv_self); |
256 | else |
258 | else |
257 | { |
259 | { |
258 | SvREFCNT_dec (SvRV (sv_self)); |
260 | SvREFCNT_dec (SvRV (sv_self)); |
259 | SvRV_set (sv_self, &PL_sv_undef); |
261 | SvRV_set (sv_self, &PL_sv_undef); |
260 | sv_self_cache = sv_self; |
262 | sv_self_cache = sv_self; |
261 | } |
263 | } |
262 | |
264 | |
263 | if (expect_false (sv_events_cache)) |
265 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
|
|
266 | SvREFCNT_dec (sv_events); |
|
|
267 | else |
|
|
268 | sv_events_cache = sv_events; |
|
|
269 | |
|
|
270 | if (expect_false (SvTRUE (ERRSV))) |
|
|
271 | { |
|
|
272 | SPAGAIN; |
|
|
273 | PUSHMARK (SP); |
|
|
274 | PUTBACK; |
|
|
275 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
276 | } |
|
|
277 | |
|
|
278 | SP = PL_stack_base + mark; |
|
|
279 | PUTBACK; |
|
|
280 | } |
|
|
281 | |
|
|
282 | static void |
|
|
283 | e_once_cb (int revents, void *arg) |
|
|
284 | { |
|
|
285 | dSP; |
|
|
286 | I32 mark = SP - PL_stack_base; |
|
|
287 | SV *sv_events; |
|
|
288 | |
|
|
289 | if (sv_events_cache) |
|
|
290 | { |
|
|
291 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
292 | SvIV_set (sv_events, revents); |
|
|
293 | } |
|
|
294 | else |
|
|
295 | sv_events = newSViv (revents); |
|
|
296 | |
|
|
297 | PUSHMARK (SP); |
|
|
298 | XPUSHs (sv_events); |
|
|
299 | |
|
|
300 | PUTBACK; |
|
|
301 | call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL); |
|
|
302 | |
|
|
303 | SvREFCNT_dec ((SV *)arg); |
|
|
304 | |
|
|
305 | if (sv_events_cache) |
264 | SvREFCNT_dec (sv_events); |
306 | SvREFCNT_dec (sv_events); |
265 | else |
307 | else |
266 | sv_events_cache = sv_events; |
308 | sv_events_cache = sv_events; |
267 | |
309 | |
268 | if (SvTRUE (ERRSV)) |
310 | if (SvTRUE (ERRSV)) |
… | |
… | |
275 | |
317 | |
276 | SP = PL_stack_base + mark; |
318 | SP = PL_stack_base + mark; |
277 | PUTBACK; |
319 | PUTBACK; |
278 | } |
320 | } |
279 | |
321 | |
280 | static void |
|
|
281 | e_once_cb (int revents, void *arg) |
|
|
282 | { |
|
|
283 | dSP; |
|
|
284 | I32 mark = SP - PL_stack_base; |
|
|
285 | SV *sv_events; |
|
|
286 | |
|
|
287 | if (sv_events_cache) |
|
|
288 | { |
|
|
289 | sv_events = sv_events_cache; sv_events_cache = 0; |
|
|
290 | SvIV_set (sv_events, revents); |
|
|
291 | } |
|
|
292 | else |
|
|
293 | sv_events = newSViv (revents); |
|
|
294 | |
|
|
295 | PUSHMARK (SP); |
|
|
296 | XPUSHs (sv_events); |
|
|
297 | |
|
|
298 | PUTBACK; |
|
|
299 | call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL); |
|
|
300 | |
|
|
301 | SvREFCNT_dec ((SV *)arg); |
|
|
302 | |
|
|
303 | if (sv_events_cache) |
|
|
304 | SvREFCNT_dec (sv_events); |
|
|
305 | else |
|
|
306 | sv_events_cache = sv_events; |
|
|
307 | |
|
|
308 | if (SvTRUE (ERRSV)) |
|
|
309 | { |
|
|
310 | SPAGAIN; |
|
|
311 | PUSHMARK (SP); |
|
|
312 | PUTBACK; |
|
|
313 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
|
|
314 | } |
|
|
315 | |
|
|
316 | SP = PL_stack_base + mark; |
|
|
317 | PUTBACK; |
|
|
318 | } |
|
|
319 | |
|
|
320 | static ev_tstamp |
322 | static ev_tstamp |
321 | e_periodic_cb (ev_periodic *w, ev_tstamp now) |
323 | e_periodic_cb (ev_periodic *w, ev_tstamp now) |
322 | { |
324 | { |
323 | ev_tstamp retval; |
325 | ev_tstamp retval; |
324 | int count; |
326 | int count; |
… | |
… | |
388 | const_iv (EV_, MINPRI) |
390 | const_iv (EV_, MINPRI) |
389 | const_iv (EV_, MAXPRI) |
391 | const_iv (EV_, MAXPRI) |
390 | |
392 | |
391 | const_iv (EV_, UNDEF) |
393 | const_iv (EV_, UNDEF) |
392 | const_iv (EV_, NONE) |
394 | const_iv (EV_, NONE) |
393 | const_iv (EV_, TIMEOUT) |
|
|
394 | const_iv (EV_, READ) |
395 | const_iv (EV_, READ) |
395 | const_iv (EV_, WRITE) |
396 | const_iv (EV_, WRITE) |
|
|
397 | const_iv (EV_, IO) |
|
|
398 | const_iv (EV_, TIMEOUT) |
|
|
399 | const_iv (EV_, TIMER) |
|
|
400 | const_iv (EV_, PERIODIC) |
396 | const_iv (EV_, SIGNAL) |
401 | const_iv (EV_, SIGNAL) |
|
|
402 | const_iv (EV_, CHILD) |
|
|
403 | const_iv (EV_, STAT) |
397 | const_iv (EV_, IDLE) |
404 | const_iv (EV_, IDLE) |
|
|
405 | const_iv (EV_, PREPARE) |
398 | const_iv (EV_, CHECK) |
406 | const_iv (EV_, CHECK) |
|
|
407 | const_iv (EV_, EMBED) |
|
|
408 | const_iv (EV_, FORK) |
|
|
409 | const_iv (EV_, ASYNC) |
|
|
410 | const_iv (EV_, CUSTOM) |
399 | const_iv (EV_, ERROR) |
411 | const_iv (EV_, ERROR) |
400 | |
412 | |
|
|
413 | const_iv (EV, LOOP_NONBLOCK) |
401 | const_iv (EV, LOOP_ONESHOT) |
414 | const_iv (EV, LOOP_ONESHOT) |
|
|
415 | |
402 | const_iv (EV, LOOP_NONBLOCK) |
416 | const_iv (EV, UNLOOP_CANCEL) |
403 | const_iv (EV, UNLOOP_ONE) |
417 | const_iv (EV, UNLOOP_ONE) |
404 | const_iv (EV, UNLOOP_ALL) |
418 | const_iv (EV, UNLOOP_ALL) |
405 | |
419 | |
406 | const_iv (EV, BACKEND_SELECT) |
420 | const_iv (EV, BACKEND_SELECT) |
407 | const_iv (EV, BACKEND_POLL) |
421 | const_iv (EV, BACKEND_POLL) |
… | |
… | |
410 | const_iv (EV, BACKEND_DEVPOLL) |
424 | const_iv (EV, BACKEND_DEVPOLL) |
411 | const_iv (EV, BACKEND_PORT) |
425 | const_iv (EV, BACKEND_PORT) |
412 | const_iv (EV, FLAG_AUTO) |
426 | const_iv (EV, FLAG_AUTO) |
413 | const_iv (EV, FLAG_NOENV) |
427 | const_iv (EV, FLAG_NOENV) |
414 | const_iv (EV, FLAG_FORKCHECK) |
428 | const_iv (EV, FLAG_FORKCHECK) |
|
|
429 | |
|
|
430 | const_iv (EV_, VERSION_MAJOR) |
|
|
431 | const_iv (EV_, VERSION_MINOR) |
415 | }; |
432 | }; |
416 | |
433 | |
417 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
434 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
418 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
435 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
419 | |
436 | |
… | |
… | |
450 | evapi.loop_destroy = ev_loop_destroy; |
467 | evapi.loop_destroy = ev_loop_destroy; |
451 | evapi.loop_fork = ev_loop_fork; |
468 | evapi.loop_fork = ev_loop_fork; |
452 | evapi.loop_count = ev_loop_count; |
469 | evapi.loop_count = ev_loop_count; |
453 | evapi.now = ev_now; |
470 | evapi.now = ev_now; |
454 | evapi.now_update = ev_now_update; |
471 | evapi.now_update = ev_now_update; |
|
|
472 | evapi.suspend = ev_suspend; |
|
|
473 | evapi.resume = ev_resume; |
455 | evapi.backend = ev_backend; |
474 | evapi.backend = ev_backend; |
456 | evapi.unloop = ev_unloop; |
475 | evapi.unloop = ev_unloop; |
457 | evapi.ref = ev_ref; |
476 | evapi.ref = ev_ref; |
458 | evapi.unref = ev_unref; |
477 | evapi.unref = ev_unref; |
459 | evapi.loop = ev_loop; |
478 | evapi.loop = ev_loop; |
… | |
… | |
535 | C_ARGS: evapi.default_loop |
554 | C_ARGS: evapi.default_loop |
536 | |
555 | |
537 | void ev_now_update () |
556 | void ev_now_update () |
538 | C_ARGS: evapi.default_loop |
557 | C_ARGS: evapi.default_loop |
539 | |
558 | |
|
|
559 | void ev_suspend () |
|
|
560 | C_ARGS: evapi.default_loop |
|
|
561 | |
|
|
562 | void ev_resume () |
|
|
563 | C_ARGS: evapi.default_loop |
|
|
564 | |
540 | unsigned int ev_backend () |
565 | unsigned int ev_backend () |
541 | C_ARGS: evapi.default_loop |
566 | C_ARGS: evapi.default_loop |
542 | |
567 | |
543 | unsigned int ev_loop_count () |
568 | unsigned int ev_loop_count () |
544 | C_ARGS: evapi.default_loop |
569 | C_ARGS: evapi.default_loop |
… | |
… | |
747 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
772 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
748 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
773 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
749 | |
774 | |
750 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
775 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
751 | { |
776 | { |
|
|
777 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
752 | REF (w); |
778 | REF (w); |
753 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
|
|
754 | UNREF (w); |
779 | UNREF (w); |
755 | } |
780 | } |
756 | } |
781 | } |
757 | OUTPUT: |
782 | OUTPUT: |
758 | RETVAL |
783 | RETVAL |
… | |
… | |
933 | |
958 | |
934 | void ev_timer_again (ev_timer *w) |
959 | void ev_timer_again (ev_timer *w) |
935 | INIT: |
960 | INIT: |
936 | CHECK_REPEAT (w->repeat); |
961 | CHECK_REPEAT (w->repeat); |
937 | CODE: |
962 | CODE: |
938 | REF (w); |
|
|
939 | ev_timer_again (e_loop (w), w); |
963 | ev_timer_again (e_loop (w), w); |
940 | UNREF (w); |
964 | UNREF (w); |
941 | |
965 | |
942 | void DESTROY (ev_timer *w) |
966 | void DESTROY (ev_timer *w) |
943 | CODE: |
967 | CODE: |
… | |
… | |
962 | CODE: |
986 | CODE: |
963 | STOP (periodic, w); |
987 | STOP (periodic, w); |
964 | |
988 | |
965 | void ev_periodic_again (ev_periodic *w) |
989 | void ev_periodic_again (ev_periodic *w) |
966 | CODE: |
990 | CODE: |
967 | REF (w); |
|
|
968 | ev_periodic_again (e_loop (w), w); |
991 | ev_periodic_again (e_loop (w), w); |
969 | UNREF (w); |
992 | UNREF (w); |
970 | |
993 | |
971 | void DESTROY (ev_periodic *w) |
994 | void DESTROY (ev_periodic *w) |
972 | CODE: |
995 | CODE: |
… | |
… | |
1255 | |
1278 | |
1256 | NV ev_now (struct ev_loop *loop) |
1279 | NV ev_now (struct ev_loop *loop) |
1257 | |
1280 | |
1258 | void ev_now_update (struct ev_loop *loop) |
1281 | void ev_now_update (struct ev_loop *loop) |
1259 | |
1282 | |
|
|
1283 | void ev_suspend (struct ev_loop *loop) |
|
|
1284 | |
|
|
1285 | void ev_resume (struct ev_loop *loop) |
|
|
1286 | |
1260 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1287 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1261 | |
1288 | |
1262 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1289 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1263 | |
1290 | |
1264 | unsigned int ev_backend (struct ev_loop *loop) |
1291 | unsigned int ev_backend (struct ev_loop *loop) |