… | |
… | |
198 | # define inline_speed static inline |
198 | # define inline_speed static inline |
199 | # endif |
199 | # endif |
200 | #else |
200 | #else |
201 | # define expect(expr,value) (expr) |
201 | # define expect(expr,value) (expr) |
202 | # define inline_speed static |
202 | # define inline_speed static |
203 | # define inline_minimal static |
203 | # define inline_size static |
204 | # define noinline |
204 | # define noinline |
205 | #endif |
205 | #endif |
206 | |
206 | |
207 | #define expect_false(expr) expect ((expr) != 0, 0) |
207 | #define expect_false(expr) expect ((expr) != 0, 0) |
208 | #define expect_true(expr) expect ((expr) != 0, 1) |
208 | #define expect_true(expr) expect ((expr) != 0, 1) |
… | |
… | |
715 | |
715 | |
716 | #ifndef _WIN32 |
716 | #ifndef _WIN32 |
717 | |
717 | |
718 | static ev_signal childev; |
718 | static ev_signal childev; |
719 | |
719 | |
720 | #ifndef WCONTINUED |
|
|
721 | # define WCONTINUED 0 |
|
|
722 | #endif |
|
|
723 | |
|
|
724 | void inline_speed |
720 | void inline_speed |
725 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
721 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
726 | { |
722 | { |
727 | ev_child *w; |
723 | ev_child *w; |
728 | |
724 | |
… | |
… | |
734 | w->rstatus = status; |
730 | w->rstatus = status; |
735 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
731 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
736 | } |
732 | } |
737 | } |
733 | } |
738 | |
734 | |
|
|
735 | #ifndef WCONTINUED |
|
|
736 | # define WCONTINUED 0 |
|
|
737 | #endif |
|
|
738 | |
739 | static void |
739 | static void |
740 | childcb (EV_P_ ev_signal *sw, int revents) |
740 | childcb (EV_P_ ev_signal *sw, int revents) |
741 | { |
741 | { |
742 | int pid, status; |
742 | int pid, status; |
743 | |
743 | |
|
|
744 | /* some systems define WCONTINUED but then fail to support it (linux 2.4) */ |
744 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
745 | if (0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
745 | { |
746 | if (!WCONTINUED |
|
|
747 | || errno != EINVAL |
|
|
748 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
|
|
749 | return; |
|
|
750 | |
746 | /* make sure we are called again until all childs have been reaped */ |
751 | /* make sure we are called again until all childs have been reaped */ |
747 | /* we need to do it this way so that the callback gets called before we continue */ |
752 | /* we need to do it this way so that the callback gets called before we continue */ |
748 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
753 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
749 | |
754 | |
750 | child_reap (EV_A_ sw, pid, pid, status); |
755 | child_reap (EV_A_ sw, pid, pid, status); |
751 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
756 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
752 | } |
|
|
753 | } |
757 | } |
754 | |
758 | |
755 | #endif |
759 | #endif |
756 | |
760 | |
757 | /*****************************************************************************/ |
761 | /*****************************************************************************/ |
… | |
… | |
1272 | ? EVUNLOOP_ONE |
1276 | ? EVUNLOOP_ONE |
1273 | : EVUNLOOP_CANCEL; |
1277 | : EVUNLOOP_CANCEL; |
1274 | |
1278 | |
1275 | while (activecnt) |
1279 | while (activecnt) |
1276 | { |
1280 | { |
|
|
1281 | /* we might have forked, so reify kernel state if necessary */ |
|
|
1282 | if (expect_false (postfork)) |
|
|
1283 | if (forkcnt) |
|
|
1284 | { |
|
|
1285 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
|
|
1286 | call_pending (EV_A); |
|
|
1287 | } |
|
|
1288 | |
1277 | /* queue check watchers (and execute them) */ |
1289 | /* queue check watchers (and execute them) */ |
1278 | if (expect_false (preparecnt)) |
1290 | if (expect_false (preparecnt)) |
1279 | { |
1291 | { |
1280 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1292 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1281 | call_pending (EV_A); |
1293 | call_pending (EV_A); |
… | |
… | |
1554 | ev_periodic_stop (EV_A_ w); |
1566 | ev_periodic_stop (EV_A_ w); |
1555 | ev_periodic_start (EV_A_ w); |
1567 | ev_periodic_start (EV_A_ w); |
1556 | } |
1568 | } |
1557 | #endif |
1569 | #endif |
1558 | |
1570 | |
1559 | void |
|
|
1560 | ev_idle_start (EV_P_ ev_idle *w) |
|
|
1561 | { |
|
|
1562 | if (expect_false (ev_is_active (w))) |
|
|
1563 | return; |
|
|
1564 | |
|
|
1565 | ev_start (EV_A_ (W)w, ++idlecnt); |
|
|
1566 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
|
|
1567 | idles [idlecnt - 1] = w; |
|
|
1568 | } |
|
|
1569 | |
|
|
1570 | void |
|
|
1571 | ev_idle_stop (EV_P_ ev_idle *w) |
|
|
1572 | { |
|
|
1573 | ev_clear_pending (EV_A_ (W)w); |
|
|
1574 | if (expect_false (!ev_is_active (w))) |
|
|
1575 | return; |
|
|
1576 | |
|
|
1577 | { |
|
|
1578 | int active = ((W)w)->active; |
|
|
1579 | idles [active - 1] = idles [--idlecnt]; |
|
|
1580 | ((W)idles [active - 1])->active = active; |
|
|
1581 | } |
|
|
1582 | |
|
|
1583 | ev_stop (EV_A_ (W)w); |
|
|
1584 | } |
|
|
1585 | |
|
|
1586 | void |
|
|
1587 | ev_prepare_start (EV_P_ ev_prepare *w) |
|
|
1588 | { |
|
|
1589 | if (expect_false (ev_is_active (w))) |
|
|
1590 | return; |
|
|
1591 | |
|
|
1592 | ev_start (EV_A_ (W)w, ++preparecnt); |
|
|
1593 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
|
|
1594 | prepares [preparecnt - 1] = w; |
|
|
1595 | } |
|
|
1596 | |
|
|
1597 | void |
|
|
1598 | ev_prepare_stop (EV_P_ ev_prepare *w) |
|
|
1599 | { |
|
|
1600 | ev_clear_pending (EV_A_ (W)w); |
|
|
1601 | if (expect_false (!ev_is_active (w))) |
|
|
1602 | return; |
|
|
1603 | |
|
|
1604 | { |
|
|
1605 | int active = ((W)w)->active; |
|
|
1606 | prepares [active - 1] = prepares [--preparecnt]; |
|
|
1607 | ((W)prepares [active - 1])->active = active; |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | ev_stop (EV_A_ (W)w); |
|
|
1611 | } |
|
|
1612 | |
|
|
1613 | void |
|
|
1614 | ev_check_start (EV_P_ ev_check *w) |
|
|
1615 | { |
|
|
1616 | if (expect_false (ev_is_active (w))) |
|
|
1617 | return; |
|
|
1618 | |
|
|
1619 | ev_start (EV_A_ (W)w, ++checkcnt); |
|
|
1620 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
|
|
1621 | checks [checkcnt - 1] = w; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | void |
|
|
1625 | ev_check_stop (EV_P_ ev_check *w) |
|
|
1626 | { |
|
|
1627 | ev_clear_pending (EV_A_ (W)w); |
|
|
1628 | if (expect_false (!ev_is_active (w))) |
|
|
1629 | return; |
|
|
1630 | |
|
|
1631 | { |
|
|
1632 | int active = ((W)w)->active; |
|
|
1633 | checks [active - 1] = checks [--checkcnt]; |
|
|
1634 | ((W)checks [active - 1])->active = active; |
|
|
1635 | } |
|
|
1636 | |
|
|
1637 | ev_stop (EV_A_ (W)w); |
|
|
1638 | } |
|
|
1639 | |
|
|
1640 | #ifndef SA_RESTART |
1571 | #ifndef SA_RESTART |
1641 | # define SA_RESTART 0 |
1572 | # define SA_RESTART 0 |
1642 | #endif |
1573 | #endif |
1643 | |
1574 | |
1644 | void |
1575 | void |
… | |
… | |
1706 | |
1637 | |
1707 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1638 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1708 | ev_stop (EV_A_ (W)w); |
1639 | ev_stop (EV_A_ (W)w); |
1709 | } |
1640 | } |
1710 | |
1641 | |
|
|
1642 | #if EV_STAT_ENABLE |
|
|
1643 | |
|
|
1644 | # ifdef _WIN32 |
|
|
1645 | # undef lstat |
|
|
1646 | # define lstat(a,b) _stati64 (a,b) |
|
|
1647 | # endif |
|
|
1648 | |
|
|
1649 | #define DEF_STAT_INTERVAL 5.0074891 |
|
|
1650 | #define MIN_STAT_INTERVAL 0.1074891 |
|
|
1651 | |
|
|
1652 | void |
|
|
1653 | ev_stat_stat (EV_P_ ev_stat *w) |
|
|
1654 | { |
|
|
1655 | if (lstat (w->path, &w->attr) < 0) |
|
|
1656 | w->attr.st_nlink = 0; |
|
|
1657 | else if (!w->attr.st_nlink) |
|
|
1658 | w->attr.st_nlink = 1; |
|
|
1659 | } |
|
|
1660 | |
|
|
1661 | static void |
|
|
1662 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
|
|
1663 | { |
|
|
1664 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
|
|
1665 | |
|
|
1666 | /* we copy this here each the time so that */ |
|
|
1667 | /* prev has the old value when the callback gets invoked */ |
|
|
1668 | w->prev = w->attr; |
|
|
1669 | ev_stat_stat (EV_A_ w); |
|
|
1670 | |
|
|
1671 | if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) |
|
|
1672 | ev_feed_event (EV_A_ w, EV_STAT); |
|
|
1673 | } |
|
|
1674 | |
|
|
1675 | void |
|
|
1676 | ev_stat_start (EV_P_ ev_stat *w) |
|
|
1677 | { |
|
|
1678 | if (expect_false (ev_is_active (w))) |
|
|
1679 | return; |
|
|
1680 | |
|
|
1681 | /* since we use memcmp, we need to clear any padding data etc. */ |
|
|
1682 | memset (&w->prev, 0, sizeof (ev_statdata)); |
|
|
1683 | memset (&w->attr, 0, sizeof (ev_statdata)); |
|
|
1684 | |
|
|
1685 | ev_stat_stat (EV_A_ w); |
|
|
1686 | |
|
|
1687 | if (w->interval < MIN_STAT_INTERVAL) |
|
|
1688 | w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
1689 | |
|
|
1690 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
|
|
1691 | ev_set_priority (&w->timer, ev_priority (w)); |
|
|
1692 | ev_timer_start (EV_A_ &w->timer); |
|
|
1693 | |
|
|
1694 | ev_start (EV_A_ (W)w, 1); |
|
|
1695 | } |
|
|
1696 | |
|
|
1697 | void |
|
|
1698 | ev_stat_stop (EV_P_ ev_stat *w) |
|
|
1699 | { |
|
|
1700 | ev_clear_pending (EV_A_ (W)w); |
|
|
1701 | if (expect_false (!ev_is_active (w))) |
|
|
1702 | return; |
|
|
1703 | |
|
|
1704 | ev_timer_stop (EV_A_ &w->timer); |
|
|
1705 | |
|
|
1706 | ev_stop (EV_A_ (W)w); |
|
|
1707 | } |
|
|
1708 | #endif |
|
|
1709 | |
|
|
1710 | void |
|
|
1711 | ev_idle_start (EV_P_ ev_idle *w) |
|
|
1712 | { |
|
|
1713 | if (expect_false (ev_is_active (w))) |
|
|
1714 | return; |
|
|
1715 | |
|
|
1716 | ev_start (EV_A_ (W)w, ++idlecnt); |
|
|
1717 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
|
|
1718 | idles [idlecnt - 1] = w; |
|
|
1719 | } |
|
|
1720 | |
|
|
1721 | void |
|
|
1722 | ev_idle_stop (EV_P_ ev_idle *w) |
|
|
1723 | { |
|
|
1724 | ev_clear_pending (EV_A_ (W)w); |
|
|
1725 | if (expect_false (!ev_is_active (w))) |
|
|
1726 | return; |
|
|
1727 | |
|
|
1728 | { |
|
|
1729 | int active = ((W)w)->active; |
|
|
1730 | idles [active - 1] = idles [--idlecnt]; |
|
|
1731 | ((W)idles [active - 1])->active = active; |
|
|
1732 | } |
|
|
1733 | |
|
|
1734 | ev_stop (EV_A_ (W)w); |
|
|
1735 | } |
|
|
1736 | |
|
|
1737 | void |
|
|
1738 | ev_prepare_start (EV_P_ ev_prepare *w) |
|
|
1739 | { |
|
|
1740 | if (expect_false (ev_is_active (w))) |
|
|
1741 | return; |
|
|
1742 | |
|
|
1743 | ev_start (EV_A_ (W)w, ++preparecnt); |
|
|
1744 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
|
|
1745 | prepares [preparecnt - 1] = w; |
|
|
1746 | } |
|
|
1747 | |
|
|
1748 | void |
|
|
1749 | ev_prepare_stop (EV_P_ ev_prepare *w) |
|
|
1750 | { |
|
|
1751 | ev_clear_pending (EV_A_ (W)w); |
|
|
1752 | if (expect_false (!ev_is_active (w))) |
|
|
1753 | return; |
|
|
1754 | |
|
|
1755 | { |
|
|
1756 | int active = ((W)w)->active; |
|
|
1757 | prepares [active - 1] = prepares [--preparecnt]; |
|
|
1758 | ((W)prepares [active - 1])->active = active; |
|
|
1759 | } |
|
|
1760 | |
|
|
1761 | ev_stop (EV_A_ (W)w); |
|
|
1762 | } |
|
|
1763 | |
|
|
1764 | void |
|
|
1765 | ev_check_start (EV_P_ ev_check *w) |
|
|
1766 | { |
|
|
1767 | if (expect_false (ev_is_active (w))) |
|
|
1768 | return; |
|
|
1769 | |
|
|
1770 | ev_start (EV_A_ (W)w, ++checkcnt); |
|
|
1771 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
|
|
1772 | checks [checkcnt - 1] = w; |
|
|
1773 | } |
|
|
1774 | |
|
|
1775 | void |
|
|
1776 | ev_check_stop (EV_P_ ev_check *w) |
|
|
1777 | { |
|
|
1778 | ev_clear_pending (EV_A_ (W)w); |
|
|
1779 | if (expect_false (!ev_is_active (w))) |
|
|
1780 | return; |
|
|
1781 | |
|
|
1782 | { |
|
|
1783 | int active = ((W)w)->active; |
|
|
1784 | checks [active - 1] = checks [--checkcnt]; |
|
|
1785 | ((W)checks [active - 1])->active = active; |
|
|
1786 | } |
|
|
1787 | |
|
|
1788 | ev_stop (EV_A_ (W)w); |
|
|
1789 | } |
|
|
1790 | |
1711 | #if EV_EMBED_ENABLE |
1791 | #if EV_EMBED_ENABLE |
1712 | void noinline |
1792 | void noinline |
1713 | ev_embed_sweep (EV_P_ ev_embed *w) |
1793 | ev_embed_sweep (EV_P_ ev_embed *w) |
1714 | { |
1794 | { |
1715 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
1795 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
… | |
… | |
1755 | |
1835 | |
1756 | ev_stop (EV_A_ (W)w); |
1836 | ev_stop (EV_A_ (W)w); |
1757 | } |
1837 | } |
1758 | #endif |
1838 | #endif |
1759 | |
1839 | |
1760 | #if EV_STAT_ENABLE |
1840 | #if EV_FORK_ENABLE |
1761 | |
|
|
1762 | # ifdef _WIN32 |
|
|
1763 | # define lstat(a,b) stat(a,b) |
|
|
1764 | # endif |
|
|
1765 | |
|
|
1766 | void |
1841 | void |
1767 | ev_stat_stat (EV_P_ ev_stat *w) |
|
|
1768 | { |
|
|
1769 | if (lstat (w->path, &w->attr) < 0) |
|
|
1770 | w->attr.st_nlink = 0; |
|
|
1771 | else if (!w->attr.st_nlink) |
|
|
1772 | w->attr.st_nlink = 1; |
|
|
1773 | } |
|
|
1774 | |
|
|
1775 | static void |
|
|
1776 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
|
|
1777 | { |
|
|
1778 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
|
|
1779 | |
|
|
1780 | /* we copy this here each the time so that */ |
|
|
1781 | /* prev has the old value when the callback gets invoked */ |
|
|
1782 | w->prev = w->attr; |
|
|
1783 | ev_stat_stat (EV_A_ w); |
|
|
1784 | |
|
|
1785 | if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) |
|
|
1786 | ev_feed_event (EV_A_ w, EV_STAT); |
|
|
1787 | } |
|
|
1788 | |
|
|
1789 | void |
|
|
1790 | ev_stat_start (EV_P_ ev_stat *w) |
1842 | ev_fork_start (EV_P_ ev_fork *w) |
1791 | { |
1843 | { |
1792 | if (expect_false (ev_is_active (w))) |
1844 | if (expect_false (ev_is_active (w))) |
1793 | return; |
1845 | return; |
1794 | |
1846 | |
1795 | /* since we use memcmp, we need to clear any padding data etc. */ |
|
|
1796 | memset (&w->prev, 0, sizeof (ev_statdata)); |
|
|
1797 | memset (&w->attr, 0, sizeof (ev_statdata)); |
|
|
1798 | |
|
|
1799 | ev_stat_stat (EV_A_ w); |
|
|
1800 | |
|
|
1801 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
|
|
1802 | ev_set_priority (&w->timer, ev_priority (w)); |
|
|
1803 | ev_timer_start (EV_A_ &w->timer); |
|
|
1804 | |
|
|
1805 | ev_start (EV_A_ (W)w, 1); |
1847 | ev_start (EV_A_ (W)w, ++forkcnt); |
|
|
1848 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
|
|
1849 | forks [forkcnt - 1] = w; |
1806 | } |
1850 | } |
1807 | |
1851 | |
1808 | void |
1852 | void |
1809 | ev_stat_stop (EV_P_ ev_stat *w) |
1853 | ev_fork_stop (EV_P_ ev_fork *w) |
1810 | { |
1854 | { |
1811 | ev_clear_pending (EV_A_ (W)w); |
1855 | ev_clear_pending (EV_A_ (W)w); |
1812 | if (expect_false (!ev_is_active (w))) |
1856 | if (expect_false (!ev_is_active (w))) |
1813 | return; |
1857 | return; |
1814 | |
1858 | |
1815 | ev_timer_stop (EV_A_ &w->timer); |
1859 | { |
|
|
1860 | int active = ((W)w)->active; |
|
|
1861 | forks [active - 1] = forks [--forkcnt]; |
|
|
1862 | ((W)forks [active - 1])->active = active; |
|
|
1863 | } |
1816 | |
1864 | |
1817 | ev_stop (EV_A_ (W)w); |
1865 | ev_stop (EV_A_ (W)w); |
1818 | } |
1866 | } |
1819 | #endif |
1867 | #endif |
1820 | |
1868 | |