… | |
… | |
126 | # define EV_USE_EVENTFD 1 |
126 | # define EV_USE_EVENTFD 1 |
127 | # else |
127 | # else |
128 | # define EV_USE_EVENTFD 0 |
128 | # define EV_USE_EVENTFD 0 |
129 | # endif |
129 | # endif |
130 | # endif |
130 | # endif |
131 | |
131 | |
132 | #endif |
132 | #endif |
133 | |
133 | |
134 | #include <math.h> |
134 | #include <math.h> |
135 | #include <stdlib.h> |
135 | #include <stdlib.h> |
136 | #include <fcntl.h> |
136 | #include <fcntl.h> |
… | |
… | |
236 | # define EV_USE_EVENTFD 0 |
236 | # define EV_USE_EVENTFD 0 |
237 | # endif |
237 | # endif |
238 | #endif |
238 | #endif |
239 | |
239 | |
240 | #if 0 /* debugging */ |
240 | #if 0 /* debugging */ |
241 | # define EV_VERIFY 1 |
241 | # define EV_VERIFY 3 |
242 | # define EV_USE_4HEAP 1 |
242 | # define EV_USE_4HEAP 1 |
243 | # define EV_HEAP_CACHE_AT 1 |
243 | # define EV_HEAP_CACHE_AT 1 |
|
|
244 | #endif |
|
|
245 | |
|
|
246 | #ifndef EV_VERIFY |
|
|
247 | # define EV_VERIFY !EV_MINIMAL |
244 | #endif |
248 | #endif |
245 | |
249 | |
246 | #ifndef EV_USE_4HEAP |
250 | #ifndef EV_USE_4HEAP |
247 | # define EV_USE_4HEAP !EV_MINIMAL |
251 | # define EV_USE_4HEAP !EV_MINIMAL |
248 | #endif |
252 | #endif |
… | |
… | |
294 | # endif |
298 | # endif |
295 | #endif |
299 | #endif |
296 | |
300 | |
297 | /**/ |
301 | /**/ |
298 | |
302 | |
299 | /* EV_VERIFY: enable internal consistency checks |
|
|
300 | * undefined or zero: no verification done or available |
|
|
301 | * 1 or higher: ev_loop_verify function available |
|
|
302 | * 2 or higher: ev_loop_verify is called frequently |
|
|
303 | */ |
|
|
304 | #if EV_VERIFY >= 1 |
303 | #if EV_VERIFY >= 3 |
305 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
304 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
306 | #else |
305 | #else |
307 | # define EV_FREQUENT_CHECK do { } while (0) |
306 | # define EV_FREQUENT_CHECK do { } while (0) |
308 | #endif |
307 | #endif |
309 | |
308 | |
… | |
… | |
1484 | |
1483 | |
1485 | postfork = 0; |
1484 | postfork = 0; |
1486 | } |
1485 | } |
1487 | |
1486 | |
1488 | #if EV_MULTIPLICITY |
1487 | #if EV_MULTIPLICITY |
|
|
1488 | |
1489 | struct ev_loop * |
1489 | struct ev_loop * |
1490 | ev_loop_new (unsigned int flags) |
1490 | ev_loop_new (unsigned int flags) |
1491 | { |
1491 | { |
1492 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1492 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1493 | |
1493 | |
… | |
… | |
1519 | array_check (W **ws, int cnt) |
1519 | array_check (W **ws, int cnt) |
1520 | { |
1520 | { |
1521 | while (cnt--) |
1521 | while (cnt--) |
1522 | assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
1522 | assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
1523 | } |
1523 | } |
|
|
1524 | #endif |
1524 | |
1525 | |
1525 | static void |
1526 | void |
1526 | ev_loop_verify (EV_P) |
1527 | ev_loop_verify (EV_P) |
1527 | { |
1528 | { |
|
|
1529 | #if EV_VERIFY |
1528 | int i; |
1530 | int i; |
1529 | |
1531 | |
1530 | checkheap (timers, timercnt); |
1532 | checkheap (timers, timercnt); |
1531 | #if EV_PERIODIC_ENABLE |
1533 | #if EV_PERIODIC_ENABLE |
1532 | checkheap (periodics, periodiccnt); |
1534 | checkheap (periodics, periodiccnt); |
… | |
… | |
1537 | array_check ((W **)idles [i], idlecnt [i]); |
1539 | array_check ((W **)idles [i], idlecnt [i]); |
1538 | #endif |
1540 | #endif |
1539 | #if EV_FORK_ENABLE |
1541 | #if EV_FORK_ENABLE |
1540 | array_check ((W **)forks, forkcnt); |
1542 | array_check ((W **)forks, forkcnt); |
1541 | #endif |
1543 | #endif |
|
|
1544 | #if EV_ASYNC_ENABLE |
|
|
1545 | array_check ((W **)asyncs, asynccnt); |
|
|
1546 | #endif |
1542 | array_check ((W **)prepares, preparecnt); |
1547 | array_check ((W **)prepares, preparecnt); |
1543 | array_check ((W **)checks, checkcnt); |
1548 | array_check ((W **)checks, checkcnt); |
1544 | #if EV_ASYNC_ENABLE |
|
|
1545 | array_check ((W **)asyncs, asynccnt); |
|
|
1546 | #endif |
1549 | #endif |
1547 | } |
1550 | } |
1548 | #endif |
|
|
1549 | |
1551 | |
1550 | #endif |
1552 | #endif /* multiplicity */ |
1551 | |
1553 | |
1552 | #if EV_MULTIPLICITY |
1554 | #if EV_MULTIPLICITY |
1553 | struct ev_loop * |
1555 | struct ev_loop * |
1554 | ev_default_loop_init (unsigned int flags) |
1556 | ev_default_loop_init (unsigned int flags) |
1555 | #else |
1557 | #else |
… | |
… | |
1620 | void inline_speed |
1622 | void inline_speed |
1621 | call_pending (EV_P) |
1623 | call_pending (EV_P) |
1622 | { |
1624 | { |
1623 | int pri; |
1625 | int pri; |
1624 | |
1626 | |
1625 | EV_FREQUENT_CHECK; |
|
|
1626 | |
|
|
1627 | for (pri = NUMPRI; pri--; ) |
1627 | for (pri = NUMPRI; pri--; ) |
1628 | while (pendingcnt [pri]) |
1628 | while (pendingcnt [pri]) |
1629 | { |
1629 | { |
1630 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1630 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1631 | |
1631 | |
… | |
… | |
1633 | { |
1633 | { |
1634 | /*assert (("non-pending watcher on pending list", p->w->pending));*/ |
1634 | /*assert (("non-pending watcher on pending list", p->w->pending));*/ |
1635 | |
1635 | |
1636 | p->w->pending = 0; |
1636 | p->w->pending = 0; |
1637 | EV_CB_INVOKE (p->w, p->events); |
1637 | EV_CB_INVOKE (p->w, p->events); |
|
|
1638 | EV_FREQUENT_CHECK; |
1638 | } |
1639 | } |
1639 | } |
1640 | } |
1640 | |
|
|
1641 | EV_FREQUENT_CHECK; |
|
|
1642 | } |
1641 | } |
1643 | |
1642 | |
1644 | #if EV_IDLE_ENABLE |
1643 | #if EV_IDLE_ENABLE |
1645 | void inline_size |
1644 | void inline_size |
1646 | idle_reify (EV_P) |
1645 | idle_reify (EV_P) |
… | |
… | |
1698 | #if EV_PERIODIC_ENABLE |
1697 | #if EV_PERIODIC_ENABLE |
1699 | void inline_size |
1698 | void inline_size |
1700 | periodics_reify (EV_P) |
1699 | periodics_reify (EV_P) |
1701 | { |
1700 | { |
1702 | EV_FREQUENT_CHECK; |
1701 | EV_FREQUENT_CHECK; |
|
|
1702 | |
1703 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
1703 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
1704 | { |
1704 | { |
1705 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1705 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1706 | |
1706 | |
1707 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1707 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
… | |
… | |
1713 | |
1713 | |
1714 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); |
1714 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); |
1715 | |
1715 | |
1716 | ANHE_at_cache (periodics [HEAP0]); |
1716 | ANHE_at_cache (periodics [HEAP0]); |
1717 | downheap (periodics, periodiccnt, HEAP0); |
1717 | downheap (periodics, periodiccnt, HEAP0); |
1718 | EV_FREQUENT_CHECK; |
|
|
1719 | } |
1718 | } |
1720 | else if (w->interval) |
1719 | else if (w->interval) |
1721 | { |
1720 | { |
1722 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1721 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1723 | /* if next trigger time is not sufficiently in the future, put it there */ |
1722 | /* if next trigger time is not sufficiently in the future, put it there */ |
… | |
… | |
1859 | |
1858 | |
1860 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1859 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1861 | |
1860 | |
1862 | do |
1861 | do |
1863 | { |
1862 | { |
|
|
1863 | #if EV_VERIFY >= 2 |
|
|
1864 | ev_loop_verify (EV_A); |
|
|
1865 | #endif |
|
|
1866 | |
1864 | #ifndef _WIN32 |
1867 | #ifndef _WIN32 |
1865 | if (expect_false (curpid)) /* penalise the forking check even more */ |
1868 | if (expect_false (curpid)) /* penalise the forking check even more */ |
1866 | if (expect_false (getpid () != curpid)) |
1869 | if (expect_false (getpid () != curpid)) |
1867 | { |
1870 | { |
1868 | curpid = getpid (); |
1871 | curpid = getpid (); |