ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.143 by root, Tue Nov 27 07:27:10 2007 UTC vs.
Revision 1.144 by root, Tue Nov 27 08:11:52 2007 UTC

1558 ev_periodic_stop (EV_A_ w); 1558 ev_periodic_stop (EV_A_ w);
1559 ev_periodic_start (EV_A_ w); 1559 ev_periodic_start (EV_A_ w);
1560} 1560}
1561#endif 1561#endif
1562 1562
1563void
1564ev_idle_start (EV_P_ ev_idle *w)
1565{
1566 if (expect_false (ev_is_active (w)))
1567 return;
1568
1569 ev_start (EV_A_ (W)w, ++idlecnt);
1570 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1571 idles [idlecnt - 1] = w;
1572}
1573
1574void
1575ev_idle_stop (EV_P_ ev_idle *w)
1576{
1577 ev_clear_pending (EV_A_ (W)w);
1578 if (expect_false (!ev_is_active (w)))
1579 return;
1580
1581 {
1582 int active = ((W)w)->active;
1583 idles [active - 1] = idles [--idlecnt];
1584 ((W)idles [active - 1])->active = active;
1585 }
1586
1587 ev_stop (EV_A_ (W)w);
1588}
1589
1590void
1591ev_prepare_start (EV_P_ ev_prepare *w)
1592{
1593 if (expect_false (ev_is_active (w)))
1594 return;
1595
1596 ev_start (EV_A_ (W)w, ++preparecnt);
1597 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1598 prepares [preparecnt - 1] = w;
1599}
1600
1601void
1602ev_prepare_stop (EV_P_ ev_prepare *w)
1603{
1604 ev_clear_pending (EV_A_ (W)w);
1605 if (expect_false (!ev_is_active (w)))
1606 return;
1607
1608 {
1609 int active = ((W)w)->active;
1610 prepares [active - 1] = prepares [--preparecnt];
1611 ((W)prepares [active - 1])->active = active;
1612 }
1613
1614 ev_stop (EV_A_ (W)w);
1615}
1616
1617void
1618ev_check_start (EV_P_ ev_check *w)
1619{
1620 if (expect_false (ev_is_active (w)))
1621 return;
1622
1623 ev_start (EV_A_ (W)w, ++checkcnt);
1624 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2);
1625 checks [checkcnt - 1] = w;
1626}
1627
1628void
1629ev_check_stop (EV_P_ ev_check *w)
1630{
1631 ev_clear_pending (EV_A_ (W)w);
1632 if (expect_false (!ev_is_active (w)))
1633 return;
1634
1635 {
1636 int active = ((W)w)->active;
1637 checks [active - 1] = checks [--checkcnt];
1638 ((W)checks [active - 1])->active = active;
1639 }
1640
1641 ev_stop (EV_A_ (W)w);
1642}
1643
1644#ifndef SA_RESTART 1563#ifndef SA_RESTART
1645# define SA_RESTART 0 1564# define SA_RESTART 0
1646#endif 1565#endif
1647 1566
1648void 1567void
1710 1629
1711 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1630 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1712 ev_stop (EV_A_ (W)w); 1631 ev_stop (EV_A_ (W)w);
1713} 1632}
1714 1633
1634#if EV_STAT_ENABLE
1635
1636# ifdef _WIN32
1637# define lstat(a,b) stat(a,b)
1638# endif
1639
1640#define DEF_STAT_INTERVAL 5.0074891
1641#define MIN_STAT_INTERVAL 0.1074891
1642
1643void
1644ev_stat_stat (EV_P_ ev_stat *w)
1645{
1646 if (lstat (w->path, &w->attr) < 0)
1647 w->attr.st_nlink = 0;
1648 else if (!w->attr.st_nlink)
1649 w->attr.st_nlink = 1;
1650}
1651
1652static void
1653stat_timer_cb (EV_P_ ev_timer *w_, int revents)
1654{
1655 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
1656
1657 /* we copy this here each the time so that */
1658 /* prev has the old value when the callback gets invoked */
1659 w->prev = w->attr;
1660 ev_stat_stat (EV_A_ w);
1661
1662 if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata)))
1663 ev_feed_event (EV_A_ w, EV_STAT);
1664}
1665
1666void
1667ev_stat_start (EV_P_ ev_stat *w)
1668{
1669 if (expect_false (ev_is_active (w)))
1670 return;
1671
1672 /* since we use memcmp, we need to clear any padding data etc. */
1673 memset (&w->prev, 0, sizeof (ev_statdata));
1674 memset (&w->attr, 0, sizeof (ev_statdata));
1675
1676 ev_stat_stat (EV_A_ w);
1677
1678 if (w->interval < MIN_STAT_INTERVAL)
1679 w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL;
1680
1681 ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval);
1682 ev_set_priority (&w->timer, ev_priority (w));
1683 ev_timer_start (EV_A_ &w->timer);
1684
1685 ev_start (EV_A_ (W)w, 1);
1686}
1687
1688void
1689ev_stat_stop (EV_P_ ev_stat *w)
1690{
1691 ev_clear_pending (EV_A_ (W)w);
1692 if (expect_false (!ev_is_active (w)))
1693 return;
1694
1695 ev_timer_stop (EV_A_ &w->timer);
1696
1697 ev_stop (EV_A_ (W)w);
1698}
1699#endif
1700
1701void
1702ev_idle_start (EV_P_ ev_idle *w)
1703{
1704 if (expect_false (ev_is_active (w)))
1705 return;
1706
1707 ev_start (EV_A_ (W)w, ++idlecnt);
1708 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1709 idles [idlecnt - 1] = w;
1710}
1711
1712void
1713ev_idle_stop (EV_P_ ev_idle *w)
1714{
1715 ev_clear_pending (EV_A_ (W)w);
1716 if (expect_false (!ev_is_active (w)))
1717 return;
1718
1719 {
1720 int active = ((W)w)->active;
1721 idles [active - 1] = idles [--idlecnt];
1722 ((W)idles [active - 1])->active = active;
1723 }
1724
1725 ev_stop (EV_A_ (W)w);
1726}
1727
1728void
1729ev_prepare_start (EV_P_ ev_prepare *w)
1730{
1731 if (expect_false (ev_is_active (w)))
1732 return;
1733
1734 ev_start (EV_A_ (W)w, ++preparecnt);
1735 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1736 prepares [preparecnt - 1] = w;
1737}
1738
1739void
1740ev_prepare_stop (EV_P_ ev_prepare *w)
1741{
1742 ev_clear_pending (EV_A_ (W)w);
1743 if (expect_false (!ev_is_active (w)))
1744 return;
1745
1746 {
1747 int active = ((W)w)->active;
1748 prepares [active - 1] = prepares [--preparecnt];
1749 ((W)prepares [active - 1])->active = active;
1750 }
1751
1752 ev_stop (EV_A_ (W)w);
1753}
1754
1755void
1756ev_check_start (EV_P_ ev_check *w)
1757{
1758 if (expect_false (ev_is_active (w)))
1759 return;
1760
1761 ev_start (EV_A_ (W)w, ++checkcnt);
1762 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2);
1763 checks [checkcnt - 1] = w;
1764}
1765
1766void
1767ev_check_stop (EV_P_ ev_check *w)
1768{
1769 ev_clear_pending (EV_A_ (W)w);
1770 if (expect_false (!ev_is_active (w)))
1771 return;
1772
1773 {
1774 int active = ((W)w)->active;
1775 checks [active - 1] = checks [--checkcnt];
1776 ((W)checks [active - 1])->active = active;
1777 }
1778
1779 ev_stop (EV_A_ (W)w);
1780}
1781
1715#if EV_EMBED_ENABLE 1782#if EV_EMBED_ENABLE
1716void noinline 1783void noinline
1717ev_embed_sweep (EV_P_ ev_embed *w) 1784ev_embed_sweep (EV_P_ ev_embed *w)
1718{ 1785{
1719 ev_loop (w->loop, EVLOOP_NONBLOCK); 1786 ev_loop (w->loop, EVLOOP_NONBLOCK);
1759 1826
1760 ev_stop (EV_A_ (W)w); 1827 ev_stop (EV_A_ (W)w);
1761} 1828}
1762#endif 1829#endif
1763 1830
1764#if EV_STAT_ENABLE
1765
1766# ifdef _WIN32
1767# define lstat(a,b) stat(a,b)
1768# endif
1769
1770#define DEF_STAT_INTERVAL 5.0074891
1771#define MIN_STAT_INTERVAL 0.1074891
1772
1773void
1774ev_stat_stat (EV_P_ ev_stat *w)
1775{
1776 if (lstat (w->path, &w->attr) < 0)
1777 w->attr.st_nlink = 0;
1778 else if (!w->attr.st_nlink)
1779 w->attr.st_nlink = 1;
1780}
1781
1782static void
1783stat_timer_cb (EV_P_ ev_timer *w_, int revents)
1784{
1785 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
1786
1787 /* we copy this here each the time so that */
1788 /* prev has the old value when the callback gets invoked */
1789 w->prev = w->attr;
1790 ev_stat_stat (EV_A_ w);
1791
1792 if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata)))
1793 ev_feed_event (EV_A_ w, EV_STAT);
1794}
1795
1796void
1797ev_stat_start (EV_P_ ev_stat *w)
1798{
1799 if (expect_false (ev_is_active (w)))
1800 return;
1801
1802 /* since we use memcmp, we need to clear any padding data etc. */
1803 memset (&w->prev, 0, sizeof (ev_statdata));
1804 memset (&w->attr, 0, sizeof (ev_statdata));
1805
1806 ev_stat_stat (EV_A_ w);
1807
1808 if (w->interval < MIN_STAT_INTERVAL)
1809 w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL;
1810
1811 ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval);
1812 ev_set_priority (&w->timer, ev_priority (w));
1813 ev_timer_start (EV_A_ &w->timer);
1814
1815 ev_start (EV_A_ (W)w, 1);
1816}
1817
1818void
1819ev_stat_stop (EV_P_ ev_stat *w)
1820{
1821 ev_clear_pending (EV_A_ (W)w);
1822 if (expect_false (!ev_is_active (w)))
1823 return;
1824
1825 ev_timer_stop (EV_A_ &w->timer);
1826
1827 ev_stop (EV_A_ (W)w);
1828}
1829#endif
1830
1831/*****************************************************************************/ 1831/*****************************************************************************/
1832 1832
1833struct ev_once 1833struct ev_once
1834{ 1834{
1835 ev_io io; 1835 ev_io io;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines