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