… | |
… | |
46 | #define expect_true(expr) expect ((expr) != 0, 1) |
46 | #define expect_true(expr) expect ((expr) != 0, 1) |
47 | |
47 | |
48 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
48 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
49 | |
49 | |
50 | #define WFLAG_KEEPALIVE 1 |
50 | #define WFLAG_KEEPALIVE 1 |
|
|
51 | #define WFLAG_UNREFED 2 /* has been unref'ed */ |
51 | |
52 | |
52 | #define UNREF(w) \ |
53 | #define UNREF(w) \ |
53 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
54 | if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \ |
54 | && !ev_is_active (w)) \ |
55 | && ev_is_active (w)) \ |
|
|
56 | { \ |
55 | ev_unref (e_loop (w)); |
57 | ev_unref (e_loop (w)); \ |
|
|
58 | (w)->e_flags |= WFLAG_UNREFED; \ |
|
|
59 | } |
56 | |
60 | |
57 | #define REF(w) \ |
61 | #define REF(w) \ |
58 | if (!((w)->e_flags & WFLAG_KEEPALIVE) \ |
62 | if ((w)->e_flags & WFLAG_UNREFED) \ |
59 | && ev_is_active (w)) \ |
63 | { \ |
|
|
64 | (w)->e_flags &= ~WFLAG_UNREFED; \ |
60 | ev_ref (e_loop (w)); |
65 | ev_ref (e_loop (w)); \ |
|
|
66 | } |
61 | |
67 | |
62 | #define START(type,w) \ |
68 | #define START(type,w) \ |
63 | do { \ |
69 | do { \ |
|
|
70 | ev_ ## type ## _start (e_loop (w), w); \ |
64 | UNREF (w); \ |
71 | UNREF (w); \ |
65 | ev_ ## type ## _start (e_loop (w), w); \ |
|
|
66 | } while (0) |
72 | } while (0) |
67 | |
73 | |
68 | #define STOP(type,w) \ |
74 | #define STOP(type,w) \ |
69 | do { \ |
75 | do { \ |
70 | REF (w); \ |
76 | REF (w); \ |
… | |
… | |
219 | { |
225 | { |
220 | dSP; |
226 | dSP; |
221 | I32 mark = SP - PL_stack_base; |
227 | I32 mark = SP - PL_stack_base; |
222 | SV *sv_self, *sv_events; |
228 | SV *sv_self, *sv_events; |
223 | |
229 | |
|
|
230 | /* libev might have stopped the watcher */ |
|
|
231 | if (expect_false (w->e_flags & WFLAG_UNREFED) |
|
|
232 | && !ev_is_active (w)) |
|
|
233 | REF (w); |
|
|
234 | |
224 | if (expect_true (sv_self_cache)) |
235 | if (expect_true (sv_self_cache)) |
225 | { |
236 | { |
226 | sv_self = sv_self_cache; sv_self_cache = 0; |
237 | sv_self = sv_self_cache; sv_self_cache = 0; |
227 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
238 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
228 | } |
239 | } |
… | |
… | |
249 | PUSHs (sv_events); |
260 | PUSHs (sv_events); |
250 | |
261 | |
251 | PUTBACK; |
262 | PUTBACK; |
252 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
263 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
253 | |
264 | |
254 | if (expect_false (sv_self_cache)) |
265 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
255 | SvREFCNT_dec (sv_self); |
266 | SvREFCNT_dec (sv_self); |
256 | else |
267 | else |
257 | { |
268 | { |
258 | SvREFCNT_dec (SvRV (sv_self)); |
269 | SvREFCNT_dec (SvRV (sv_self)); |
259 | SvRV_set (sv_self, &PL_sv_undef); |
270 | SvRV_set (sv_self, &PL_sv_undef); |
260 | sv_self_cache = sv_self; |
271 | sv_self_cache = sv_self; |
261 | } |
272 | } |
262 | |
273 | |
263 | if (expect_false (sv_events_cache)) |
274 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
264 | SvREFCNT_dec (sv_events); |
275 | SvREFCNT_dec (sv_events); |
265 | else |
276 | else |
266 | sv_events_cache = sv_events; |
277 | sv_events_cache = sv_events; |
267 | |
278 | |
268 | if (expect_false (SvTRUE (ERRSV))) |
279 | if (expect_false (SvTRUE (ERRSV))) |
… | |
… | |
388 | const_iv (EV_, MINPRI) |
399 | const_iv (EV_, MINPRI) |
389 | const_iv (EV_, MAXPRI) |
400 | const_iv (EV_, MAXPRI) |
390 | |
401 | |
391 | const_iv (EV_, UNDEF) |
402 | const_iv (EV_, UNDEF) |
392 | const_iv (EV_, NONE) |
403 | const_iv (EV_, NONE) |
393 | const_iv (EV_, TIMEOUT) |
|
|
394 | const_iv (EV_, READ) |
404 | const_iv (EV_, READ) |
395 | const_iv (EV_, WRITE) |
405 | const_iv (EV_, WRITE) |
|
|
406 | const_iv (EV_, IO) |
|
|
407 | const_iv (EV_, TIMEOUT) |
|
|
408 | const_iv (EV_, TIMER) |
|
|
409 | const_iv (EV_, PERIODIC) |
396 | const_iv (EV_, SIGNAL) |
410 | const_iv (EV_, SIGNAL) |
|
|
411 | const_iv (EV_, CHILD) |
|
|
412 | const_iv (EV_, STAT) |
397 | const_iv (EV_, IDLE) |
413 | const_iv (EV_, IDLE) |
|
|
414 | const_iv (EV_, PREPARE) |
398 | const_iv (EV_, CHECK) |
415 | const_iv (EV_, CHECK) |
|
|
416 | const_iv (EV_, EMBED) |
|
|
417 | const_iv (EV_, FORK) |
|
|
418 | const_iv (EV_, ASYNC) |
|
|
419 | const_iv (EV_, CUSTOM) |
399 | const_iv (EV_, ERROR) |
420 | const_iv (EV_, ERROR) |
400 | |
421 | |
|
|
422 | const_iv (EV, LOOP_NONBLOCK) |
401 | const_iv (EV, LOOP_ONESHOT) |
423 | const_iv (EV, LOOP_ONESHOT) |
|
|
424 | |
402 | const_iv (EV, LOOP_NONBLOCK) |
425 | const_iv (EV, UNLOOP_CANCEL) |
403 | const_iv (EV, UNLOOP_ONE) |
426 | const_iv (EV, UNLOOP_ONE) |
404 | const_iv (EV, UNLOOP_ALL) |
427 | const_iv (EV, UNLOOP_ALL) |
405 | |
428 | |
406 | const_iv (EV, BACKEND_SELECT) |
429 | const_iv (EV, BACKEND_SELECT) |
407 | const_iv (EV, BACKEND_POLL) |
430 | const_iv (EV, BACKEND_POLL) |
… | |
… | |
410 | const_iv (EV, BACKEND_DEVPOLL) |
433 | const_iv (EV, BACKEND_DEVPOLL) |
411 | const_iv (EV, BACKEND_PORT) |
434 | const_iv (EV, BACKEND_PORT) |
412 | const_iv (EV, FLAG_AUTO) |
435 | const_iv (EV, FLAG_AUTO) |
413 | const_iv (EV, FLAG_NOENV) |
436 | const_iv (EV, FLAG_NOENV) |
414 | const_iv (EV, FLAG_FORKCHECK) |
437 | const_iv (EV, FLAG_FORKCHECK) |
|
|
438 | |
|
|
439 | const_iv (EV_, VERSION_MAJOR) |
|
|
440 | const_iv (EV_, VERSION_MINOR) |
415 | }; |
441 | }; |
416 | |
442 | |
417 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
443 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
418 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
444 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
419 | |
445 | |
… | |
… | |
450 | evapi.loop_destroy = ev_loop_destroy; |
476 | evapi.loop_destroy = ev_loop_destroy; |
451 | evapi.loop_fork = ev_loop_fork; |
477 | evapi.loop_fork = ev_loop_fork; |
452 | evapi.loop_count = ev_loop_count; |
478 | evapi.loop_count = ev_loop_count; |
453 | evapi.now = ev_now; |
479 | evapi.now = ev_now; |
454 | evapi.now_update = ev_now_update; |
480 | evapi.now_update = ev_now_update; |
|
|
481 | evapi.suspend = ev_suspend; |
|
|
482 | evapi.resume = ev_resume; |
455 | evapi.backend = ev_backend; |
483 | evapi.backend = ev_backend; |
456 | evapi.unloop = ev_unloop; |
484 | evapi.unloop = ev_unloop; |
457 | evapi.ref = ev_ref; |
485 | evapi.ref = ev_ref; |
458 | evapi.unref = ev_unref; |
486 | evapi.unref = ev_unref; |
459 | evapi.loop = ev_loop; |
487 | evapi.loop = ev_loop; |
… | |
… | |
535 | C_ARGS: evapi.default_loop |
563 | C_ARGS: evapi.default_loop |
536 | |
564 | |
537 | void ev_now_update () |
565 | void ev_now_update () |
538 | C_ARGS: evapi.default_loop |
566 | C_ARGS: evapi.default_loop |
539 | |
567 | |
|
|
568 | void ev_suspend () |
|
|
569 | C_ARGS: evapi.default_loop |
|
|
570 | |
|
|
571 | void ev_resume () |
|
|
572 | C_ARGS: evapi.default_loop |
|
|
573 | |
540 | unsigned int ev_backend () |
574 | unsigned int ev_backend () |
541 | C_ARGS: evapi.default_loop |
575 | C_ARGS: evapi.default_loop |
542 | |
576 | |
543 | unsigned int ev_loop_count () |
577 | unsigned int ev_loop_count () |
544 | C_ARGS: evapi.default_loop |
578 | C_ARGS: evapi.default_loop |
… | |
… | |
747 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
781 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
748 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
782 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
749 | |
783 | |
750 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
784 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
751 | { |
785 | { |
|
|
786 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
752 | REF (w); |
787 | REF (w); |
753 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
|
|
754 | UNREF (w); |
788 | UNREF (w); |
755 | } |
789 | } |
756 | } |
790 | } |
757 | OUTPUT: |
791 | OUTPUT: |
758 | RETVAL |
792 | RETVAL |
… | |
… | |
933 | |
967 | |
934 | void ev_timer_again (ev_timer *w) |
968 | void ev_timer_again (ev_timer *w) |
935 | INIT: |
969 | INIT: |
936 | CHECK_REPEAT (w->repeat); |
970 | CHECK_REPEAT (w->repeat); |
937 | CODE: |
971 | CODE: |
938 | REF (w); |
|
|
939 | ev_timer_again (e_loop (w), w); |
972 | ev_timer_again (e_loop (w), w); |
940 | UNREF (w); |
973 | UNREF (w); |
941 | |
974 | |
942 | void DESTROY (ev_timer *w) |
975 | void DESTROY (ev_timer *w) |
943 | CODE: |
976 | CODE: |
… | |
… | |
962 | CODE: |
995 | CODE: |
963 | STOP (periodic, w); |
996 | STOP (periodic, w); |
964 | |
997 | |
965 | void ev_periodic_again (ev_periodic *w) |
998 | void ev_periodic_again (ev_periodic *w) |
966 | CODE: |
999 | CODE: |
967 | REF (w); |
|
|
968 | ev_periodic_again (e_loop (w), w); |
1000 | ev_periodic_again (e_loop (w), w); |
969 | UNREF (w); |
1001 | UNREF (w); |
970 | |
1002 | |
971 | void DESTROY (ev_periodic *w) |
1003 | void DESTROY (ev_periodic *w) |
972 | CODE: |
1004 | CODE: |
… | |
… | |
1255 | |
1287 | |
1256 | NV ev_now (struct ev_loop *loop) |
1288 | NV ev_now (struct ev_loop *loop) |
1257 | |
1289 | |
1258 | void ev_now_update (struct ev_loop *loop) |
1290 | void ev_now_update (struct ev_loop *loop) |
1259 | |
1291 | |
|
|
1292 | void ev_suspend (struct ev_loop *loop) |
|
|
1293 | |
|
|
1294 | void ev_resume (struct ev_loop *loop) |
|
|
1295 | |
1260 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1296 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1261 | |
1297 | |
1262 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1298 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1263 | |
1299 | |
1264 | unsigned int ev_backend (struct ev_loop *loop) |
1300 | unsigned int ev_backend (struct ev_loop *loop) |