… | |
… | |
557 | |
557 | |
558 | fdchangecnt = 0; |
558 | fdchangecnt = 0; |
559 | } |
559 | } |
560 | |
560 | |
561 | void inline_size |
561 | void inline_size |
562 | fd_change (EV_P_ int fd) |
562 | fd_change (EV_P_ int fd, int flags) |
563 | { |
563 | { |
564 | if (expect_false (anfds [fd].reify)) |
564 | unsigned char reify = anfds [fd].reify; |
565 | return; |
|
|
566 | |
|
|
567 | anfds [fd].reify = 1; |
565 | anfds [fd].reify |= flags | 1; |
568 | |
566 | |
|
|
567 | if (expect_true (!reify)) |
|
|
568 | { |
569 | ++fdchangecnt; |
569 | ++fdchangecnt; |
570 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
570 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
571 | fdchanges [fdchangecnt - 1] = fd; |
571 | fdchanges [fdchangecnt - 1] = fd; |
|
|
572 | } |
572 | } |
573 | } |
573 | |
574 | |
574 | void inline_speed |
575 | void inline_speed |
575 | fd_kill (EV_P_ int fd) |
576 | fd_kill (EV_P_ int fd) |
576 | { |
577 | { |
… | |
… | |
627 | |
628 | |
628 | for (fd = 0; fd < anfdmax; ++fd) |
629 | for (fd = 0; fd < anfdmax; ++fd) |
629 | if (anfds [fd].events) |
630 | if (anfds [fd].events) |
630 | { |
631 | { |
631 | anfds [fd].events = 0; |
632 | anfds [fd].events = 0; |
632 | fd_change (EV_A_ fd); |
633 | fd_change (EV_A_ fd, EV_IOFDSET); |
633 | } |
634 | } |
634 | } |
635 | } |
635 | |
636 | |
636 | /*****************************************************************************/ |
637 | /*****************************************************************************/ |
637 | |
638 | |
… | |
… | |
652 | k = p; |
653 | k = p; |
653 | } |
654 | } |
654 | |
655 | |
655 | heap [k] = w; |
656 | heap [k] = w; |
656 | ((W)heap [k])->active = k + 1; |
657 | ((W)heap [k])->active = k + 1; |
657 | |
|
|
658 | } |
658 | } |
659 | |
659 | |
660 | void inline_speed |
660 | void inline_speed |
661 | downheap (WT *heap, int N, int k) |
661 | downheap (WT *heap, int N, int k) |
662 | { |
662 | { |
… | |
… | |
793 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
793 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
794 | } |
794 | } |
795 | |
795 | |
796 | /*****************************************************************************/ |
796 | /*****************************************************************************/ |
797 | |
797 | |
798 | static ev_child *childs [EV_PID_HASHSIZE]; |
798 | static WL childs [EV_PID_HASHSIZE]; |
799 | |
799 | |
800 | #ifndef _WIN32 |
800 | #ifndef _WIN32 |
801 | |
801 | |
802 | static ev_signal childev; |
802 | static ev_signal childev; |
803 | |
803 | |
… | |
… | |
1215 | void inline_size |
1215 | void inline_size |
1216 | timers_reify (EV_P) |
1216 | timers_reify (EV_P) |
1217 | { |
1217 | { |
1218 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1218 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1219 | { |
1219 | { |
1220 | ev_timer *w = timers [0]; |
1220 | ev_timer *w = (ev_timer *)timers [0]; |
1221 | |
1221 | |
1222 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1222 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1223 | |
1223 | |
1224 | /* first reschedule or stop timer */ |
1224 | /* first reschedule or stop timer */ |
1225 | if (w->repeat) |
1225 | if (w->repeat) |
… | |
… | |
1228 | |
1228 | |
1229 | ((WT)w)->at += w->repeat; |
1229 | ((WT)w)->at += w->repeat; |
1230 | if (((WT)w)->at < mn_now) |
1230 | if (((WT)w)->at < mn_now) |
1231 | ((WT)w)->at = mn_now; |
1231 | ((WT)w)->at = mn_now; |
1232 | |
1232 | |
1233 | downheap ((WT *)timers, timercnt, 0); |
1233 | downheap (timers, timercnt, 0); |
1234 | } |
1234 | } |
1235 | else |
1235 | else |
1236 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1236 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1237 | |
1237 | |
1238 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1238 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
… | |
… | |
1243 | void inline_size |
1243 | void inline_size |
1244 | periodics_reify (EV_P) |
1244 | periodics_reify (EV_P) |
1245 | { |
1245 | { |
1246 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1246 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1247 | { |
1247 | { |
1248 | ev_periodic *w = periodics [0]; |
1248 | ev_periodic *w = (ev_periodic *)periodics [0]; |
1249 | |
1249 | |
1250 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1250 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1251 | |
1251 | |
1252 | /* first reschedule or stop timer */ |
1252 | /* first reschedule or stop timer */ |
1253 | if (w->reschedule_cb) |
1253 | if (w->reschedule_cb) |
1254 | { |
1254 | { |
1255 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1255 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1256 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1256 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1257 | downheap ((WT *)periodics, periodiccnt, 0); |
1257 | downheap (periodics, periodiccnt, 0); |
1258 | } |
1258 | } |
1259 | else if (w->interval) |
1259 | else if (w->interval) |
1260 | { |
1260 | { |
1261 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1261 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1262 | if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; |
1262 | if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; |
1263 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1263 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1264 | downheap ((WT *)periodics, periodiccnt, 0); |
1264 | downheap (periodics, periodiccnt, 0); |
1265 | } |
1265 | } |
1266 | else |
1266 | else |
1267 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1267 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1268 | |
1268 | |
1269 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1269 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
… | |
… | |
1276 | int i; |
1276 | int i; |
1277 | |
1277 | |
1278 | /* adjust periodics after time jump */ |
1278 | /* adjust periodics after time jump */ |
1279 | for (i = 0; i < periodiccnt; ++i) |
1279 | for (i = 0; i < periodiccnt; ++i) |
1280 | { |
1280 | { |
1281 | ev_periodic *w = periodics [i]; |
1281 | ev_periodic *w = (ev_periodic *)periodics [i]; |
1282 | |
1282 | |
1283 | if (w->reschedule_cb) |
1283 | if (w->reschedule_cb) |
1284 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1284 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1285 | else if (w->interval) |
1285 | else if (w->interval) |
1286 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1286 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1287 | } |
1287 | } |
1288 | |
1288 | |
1289 | /* now rebuild the heap */ |
1289 | /* now rebuild the heap */ |
1290 | for (i = periodiccnt >> 1; i--; ) |
1290 | for (i = periodiccnt >> 1; i--; ) |
1291 | downheap ((WT *)periodics, periodiccnt, i); |
1291 | downheap (periodics, periodiccnt, i); |
1292 | } |
1292 | } |
1293 | #endif |
1293 | #endif |
1294 | |
1294 | |
1295 | #if EV_IDLE_ENABLE |
1295 | #if EV_IDLE_ENABLE |
1296 | void inline_size |
1296 | void inline_size |
… | |
… | |
1598 | |
1598 | |
1599 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1599 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1600 | |
1600 | |
1601 | ev_start (EV_A_ (W)w, 1); |
1601 | ev_start (EV_A_ (W)w, 1); |
1602 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1602 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1603 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1603 | wlist_add (&anfds[fd].head, (WL)w); |
1604 | |
1604 | |
1605 | fd_change (EV_A_ fd); |
1605 | fd_change (EV_A_ fd, w->events & EV_IOFDSET); |
|
|
1606 | w->events &= ~ EV_IOFDSET; |
1606 | } |
1607 | } |
1607 | |
1608 | |
1608 | void noinline |
1609 | void noinline |
1609 | ev_io_stop (EV_P_ ev_io *w) |
1610 | ev_io_stop (EV_P_ ev_io *w) |
1610 | { |
1611 | { |
… | |
… | |
1612 | if (expect_false (!ev_is_active (w))) |
1613 | if (expect_false (!ev_is_active (w))) |
1613 | return; |
1614 | return; |
1614 | |
1615 | |
1615 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1616 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1616 | |
1617 | |
1617 | wlist_del ((WL *)&anfds[w->fd].head, (WL)w); |
1618 | wlist_del (&anfds[w->fd].head, (WL)w); |
1618 | ev_stop (EV_A_ (W)w); |
1619 | ev_stop (EV_A_ (W)w); |
1619 | |
1620 | |
1620 | fd_change (EV_A_ w->fd); |
1621 | fd_change (EV_A_ w->fd, 0); |
1621 | } |
1622 | } |
1622 | |
1623 | |
1623 | void noinline |
1624 | void noinline |
1624 | ev_timer_start (EV_P_ ev_timer *w) |
1625 | ev_timer_start (EV_P_ ev_timer *w) |
1625 | { |
1626 | { |
… | |
… | |
1629 | ((WT)w)->at += mn_now; |
1630 | ((WT)w)->at += mn_now; |
1630 | |
1631 | |
1631 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1632 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1632 | |
1633 | |
1633 | ev_start (EV_A_ (W)w, ++timercnt); |
1634 | ev_start (EV_A_ (W)w, ++timercnt); |
1634 | array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2); |
1635 | array_needsize (WT, timers, timermax, timercnt, EMPTY2); |
1635 | timers [timercnt - 1] = w; |
1636 | timers [timercnt - 1] = (WT)w; |
1636 | upheap ((WT *)timers, timercnt - 1); |
1637 | upheap (timers, timercnt - 1); |
1637 | |
1638 | |
1638 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1639 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1639 | } |
1640 | } |
1640 | |
1641 | |
1641 | void noinline |
1642 | void noinline |
… | |
… | |
1643 | { |
1644 | { |
1644 | clear_pending (EV_A_ (W)w); |
1645 | clear_pending (EV_A_ (W)w); |
1645 | if (expect_false (!ev_is_active (w))) |
1646 | if (expect_false (!ev_is_active (w))) |
1646 | return; |
1647 | return; |
1647 | |
1648 | |
1648 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1649 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w)); |
1649 | |
1650 | |
1650 | { |
1651 | { |
1651 | int active = ((W)w)->active; |
1652 | int active = ((W)w)->active; |
1652 | |
1653 | |
1653 | if (expect_true (--active < --timercnt)) |
1654 | if (expect_true (--active < --timercnt)) |
1654 | { |
1655 | { |
1655 | timers [active] = timers [timercnt]; |
1656 | timers [active] = timers [timercnt]; |
1656 | adjustheap ((WT *)timers, timercnt, active); |
1657 | adjustheap (timers, timercnt, active); |
1657 | } |
1658 | } |
1658 | } |
1659 | } |
1659 | |
1660 | |
1660 | ((WT)w)->at -= mn_now; |
1661 | ((WT)w)->at -= mn_now; |
1661 | |
1662 | |
… | |
… | |
1668 | if (ev_is_active (w)) |
1669 | if (ev_is_active (w)) |
1669 | { |
1670 | { |
1670 | if (w->repeat) |
1671 | if (w->repeat) |
1671 | { |
1672 | { |
1672 | ((WT)w)->at = mn_now + w->repeat; |
1673 | ((WT)w)->at = mn_now + w->repeat; |
1673 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1674 | adjustheap (timers, timercnt, ((W)w)->active - 1); |
1674 | } |
1675 | } |
1675 | else |
1676 | else |
1676 | ev_timer_stop (EV_A_ w); |
1677 | ev_timer_stop (EV_A_ w); |
1677 | } |
1678 | } |
1678 | else if (w->repeat) |
1679 | else if (w->repeat) |
… | |
… | |
1699 | } |
1700 | } |
1700 | else |
1701 | else |
1701 | ((WT)w)->at = w->offset; |
1702 | ((WT)w)->at = w->offset; |
1702 | |
1703 | |
1703 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1704 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1704 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1705 | array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); |
1705 | periodics [periodiccnt - 1] = w; |
1706 | periodics [periodiccnt - 1] = (WT)w; |
1706 | upheap ((WT *)periodics, periodiccnt - 1); |
1707 | upheap (periodics, periodiccnt - 1); |
1707 | |
1708 | |
1708 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1709 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1709 | } |
1710 | } |
1710 | |
1711 | |
1711 | void noinline |
1712 | void noinline |
… | |
… | |
1713 | { |
1714 | { |
1714 | clear_pending (EV_A_ (W)w); |
1715 | clear_pending (EV_A_ (W)w); |
1715 | if (expect_false (!ev_is_active (w))) |
1716 | if (expect_false (!ev_is_active (w))) |
1716 | return; |
1717 | return; |
1717 | |
1718 | |
1718 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1719 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w)); |
1719 | |
1720 | |
1720 | { |
1721 | { |
1721 | int active = ((W)w)->active; |
1722 | int active = ((W)w)->active; |
1722 | |
1723 | |
1723 | if (expect_true (--active < --periodiccnt)) |
1724 | if (expect_true (--active < --periodiccnt)) |
1724 | { |
1725 | { |
1725 | periodics [active] = periodics [periodiccnt]; |
1726 | periodics [active] = periodics [periodiccnt]; |
1726 | adjustheap ((WT *)periodics, periodiccnt, active); |
1727 | adjustheap (periodics, periodiccnt, active); |
1727 | } |
1728 | } |
1728 | } |
1729 | } |
1729 | |
1730 | |
1730 | ev_stop (EV_A_ (W)w); |
1731 | ev_stop (EV_A_ (W)w); |
1731 | } |
1732 | } |
… | |
… | |
1767 | sigprocmask (SIG_SETMASK, &prev, 0); |
1768 | sigprocmask (SIG_SETMASK, &prev, 0); |
1768 | #endif |
1769 | #endif |
1769 | } |
1770 | } |
1770 | |
1771 | |
1771 | ev_start (EV_A_ (W)w, 1); |
1772 | ev_start (EV_A_ (W)w, 1); |
1772 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1773 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1773 | |
1774 | |
1774 | if (!((WL)w)->next) |
1775 | if (!((WL)w)->next) |
1775 | { |
1776 | { |
1776 | #if _WIN32 |
1777 | #if _WIN32 |
1777 | signal (w->signum, sighandler); |
1778 | signal (w->signum, sighandler); |
… | |
… | |
1790 | { |
1791 | { |
1791 | clear_pending (EV_A_ (W)w); |
1792 | clear_pending (EV_A_ (W)w); |
1792 | if (expect_false (!ev_is_active (w))) |
1793 | if (expect_false (!ev_is_active (w))) |
1793 | return; |
1794 | return; |
1794 | |
1795 | |
1795 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1796 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
1796 | ev_stop (EV_A_ (W)w); |
1797 | ev_stop (EV_A_ (W)w); |
1797 | |
1798 | |
1798 | if (!signals [w->signum - 1].head) |
1799 | if (!signals [w->signum - 1].head) |
1799 | signal (w->signum, SIG_DFL); |
1800 | signal (w->signum, SIG_DFL); |
1800 | } |
1801 | } |
… | |
… | |
1807 | #endif |
1808 | #endif |
1808 | if (expect_false (ev_is_active (w))) |
1809 | if (expect_false (ev_is_active (w))) |
1809 | return; |
1810 | return; |
1810 | |
1811 | |
1811 | ev_start (EV_A_ (W)w, 1); |
1812 | ev_start (EV_A_ (W)w, 1); |
1812 | wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1813 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1813 | } |
1814 | } |
1814 | |
1815 | |
1815 | void |
1816 | void |
1816 | ev_child_stop (EV_P_ ev_child *w) |
1817 | ev_child_stop (EV_P_ ev_child *w) |
1817 | { |
1818 | { |
1818 | clear_pending (EV_A_ (W)w); |
1819 | clear_pending (EV_A_ (W)w); |
1819 | if (expect_false (!ev_is_active (w))) |
1820 | if (expect_false (!ev_is_active (w))) |
1820 | return; |
1821 | return; |
1821 | |
1822 | |
1822 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1823 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1823 | ev_stop (EV_A_ (W)w); |
1824 | ev_stop (EV_A_ (W)w); |
1824 | } |
1825 | } |
1825 | |
1826 | |
1826 | #if EV_STAT_ENABLE |
1827 | #if EV_STAT_ENABLE |
1827 | |
1828 | |