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

Comparing libev/ev.c (file contents):
Revision 1.356 by root, Fri Oct 22 11:21:52 2010 UTC vs.
Revision 1.364 by root, Sun Oct 24 21:51:03 2010 UTC

530 530
531static unsigned int noinline 531static unsigned int noinline
532ev_linux_version (void) 532ev_linux_version (void)
533{ 533{
534#ifdef __linux 534#ifdef __linux
535 unsigned int v = 0;
535 struct utsname buf; 536 struct utsname buf;
536 unsigned int v;
537 int i; 537 int i;
538 char *p = buf.release; 538 char *p = buf.release;
539 539
540 if (uname (&buf)) 540 if (uname (&buf))
541 return 0; 541 return 0;
668 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 668 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */
669 unsigned char unused; 669 unsigned char unused;
670#if EV_USE_EPOLL 670#if EV_USE_EPOLL
671 unsigned int egen; /* generation counter to counter epoll bugs */ 671 unsigned int egen; /* generation counter to counter epoll bugs */
672#endif 672#endif
673#if EV_SELECT_IS_WINSOCKET 673#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
674 SOCKET handle; 674 SOCKET handle;
675#endif
676#if EV_USE_IOCP
677 OVERLAPPED or, ow;
675#endif 678#endif
676} ANFD; 679} ANFD;
677 680
678/* stores the pending event set for a given watcher */ 681/* stores the pending event set for a given watcher */
679typedef struct 682typedef struct
975 unsigned char o_events = anfd->events; 978 unsigned char o_events = anfd->events;
976 unsigned char o_reify = anfd->reify; 979 unsigned char o_reify = anfd->reify;
977 980
978 anfd->reify = 0; 981 anfd->reify = 0;
979 982
980#if EV_SELECT_IS_WINSOCKET 983#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
981 if (o_reify & EV__IOFDSET) 984 if (o_reify & EV__IOFDSET)
982 { 985 {
983 unsigned long arg; 986 unsigned long arg;
984 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); 987 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
985 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); 988 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
989 printf ("oi %d %x\n", fd, anfd->handle);//D
986 } 990 }
987#endif 991#endif
988 992
989 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 993 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
990 { 994 {
1489 1493
1490#endif 1494#endif
1491 1495
1492/*****************************************************************************/ 1496/*****************************************************************************/
1493 1497
1498#if EV_USE_IOCP
1499# include "ev_iocp.c"
1500#endif
1494#if EV_USE_PORT 1501#if EV_USE_PORT
1495# include "ev_port.c" 1502# include "ev_port.c"
1496#endif 1503#endif
1497#if EV_USE_KQUEUE 1504#if EV_USE_KQUEUE
1498# include "ev_kqueue.c" 1505# include "ev_kqueue.c"
1695#endif 1702#endif
1696 1703
1697 if (!(flags & 0x0000ffffU)) 1704 if (!(flags & 0x0000ffffU))
1698 flags |= ev_recommended_backends (); 1705 flags |= ev_recommended_backends ();
1699 1706
1707#if EV_USE_IOCP
1708 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
1709#endif
1700#if EV_USE_PORT 1710#if EV_USE_PORT
1701 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 1711 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
1702#endif 1712#endif
1703#if EV_USE_KQUEUE 1713#if EV_USE_KQUEUE
1704 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 1714 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags);
1721#endif 1731#endif
1722 } 1732 }
1723} 1733}
1724 1734
1725/* free up a loop structure */ 1735/* free up a loop structure */
1726static void noinline 1736void
1727loop_destroy (EV_P) 1737ev_loop_destroy (EV_P)
1728{ 1738{
1729 int i; 1739 int i;
1740
1741#if EV_MULTIPLICITY
1742 /* mimic free (0) */
1743 if (!EV_A)
1744 return;
1745#endif
1746
1747#if EV_CLEANUP_ENABLE
1748 /* queue cleanup watchers (and execute them) */
1749 if (expect_false (cleanupcnt))
1750 {
1751 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
1752 EV_INVOKE_PENDING;
1753 }
1754#endif
1755
1756#if EV_CHILD_ENABLE
1757 if (ev_is_active (&childev))
1758 {
1759 ev_ref (EV_A); /* child watcher */
1760 ev_signal_stop (EV_A_ &childev);
1761 }
1762#endif
1730 1763
1731 if (ev_is_active (&pipe_w)) 1764 if (ev_is_active (&pipe_w))
1732 { 1765 {
1733 /*ev_ref (EV_A);*/ 1766 /*ev_ref (EV_A);*/
1734 /*ev_io_stop (EV_A_ &pipe_w);*/ 1767 /*ev_io_stop (EV_A_ &pipe_w);*/
1756#endif 1789#endif
1757 1790
1758 if (backend_fd >= 0) 1791 if (backend_fd >= 0)
1759 close (backend_fd); 1792 close (backend_fd);
1760 1793
1794#if EV_USE_IOCP
1795 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
1796#endif
1761#if EV_USE_PORT 1797#if EV_USE_PORT
1762 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 1798 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
1763#endif 1799#endif
1764#if EV_USE_KQUEUE 1800#if EV_USE_KQUEUE
1765 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 1801 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
1792 array_free (periodic, EMPTY); 1828 array_free (periodic, EMPTY);
1793#endif 1829#endif
1794#if EV_FORK_ENABLE 1830#if EV_FORK_ENABLE
1795 array_free (fork, EMPTY); 1831 array_free (fork, EMPTY);
1796#endif 1832#endif
1833#if EV_CLEANUP_ENABLE
1834 array_free (cleanup, EMPTY);
1835#endif
1797 array_free (prepare, EMPTY); 1836 array_free (prepare, EMPTY);
1798 array_free (check, EMPTY); 1837 array_free (check, EMPTY);
1799#if EV_ASYNC_ENABLE 1838#if EV_ASYNC_ENABLE
1800 array_free (async, EMPTY); 1839 array_free (async, EMPTY);
1801#endif 1840#endif
1802 1841
1803 backend = 0; 1842 backend = 0;
1843
1844#if EV_MULTIPLICITY
1845 if (ev_is_default_loop (EV_A))
1846#endif
1847 ev_default_loop_ptr = 0;
1848#if EV_MULTIPLICITY
1849 else
1850 ev_free (EV_A);
1851#endif
1804} 1852}
1805 1853
1806#if EV_USE_INOTIFY 1854#if EV_USE_INOTIFY
1807inline_size void infy_fork (EV_P); 1855inline_size void infy_fork (EV_P);
1808#endif 1856#endif
1867 loop_init (EV_A_ flags); 1915 loop_init (EV_A_ flags);
1868 1916
1869 if (ev_backend (EV_A)) 1917 if (ev_backend (EV_A))
1870 return EV_A; 1918 return EV_A;
1871 1919
1920 ev_free (EV_A);
1872 return 0; 1921 return 0;
1873} 1922}
1874 1923
1875void
1876ev_loop_destroy (EV_P)
1877{
1878 loop_destroy (EV_A);
1879 ev_free (loop);
1880}
1881
1882void
1883ev_loop_fork (EV_P)
1884{
1885 postfork = 1; /* must be in line with ev_default_fork */
1886}
1887#endif /* multiplicity */ 1924#endif /* multiplicity */
1888 1925
1889#if EV_VERIFY 1926#if EV_VERIFY
1890static void noinline 1927static void noinline
1891verify_watcher (EV_P_ W w) 1928verify_watcher (EV_P_ W w)
1966#if EV_FORK_ENABLE 2003#if EV_FORK_ENABLE
1967 assert (forkmax >= forkcnt); 2004 assert (forkmax >= forkcnt);
1968 array_verify (EV_A_ (W *)forks, forkcnt); 2005 array_verify (EV_A_ (W *)forks, forkcnt);
1969#endif 2006#endif
1970 2007
2008#if EV_CLEANUP_ENABLE
2009 assert (cleanupmax >= cleanupcnt);
2010 array_verify (EV_A_ (W *)cleanups, cleanupcnt);
2011#endif
2012
1971#if EV_ASYNC_ENABLE 2013#if EV_ASYNC_ENABLE
1972 assert (asyncmax >= asynccnt); 2014 assert (asyncmax >= asynccnt);
1973 array_verify (EV_A_ (W *)asyncs, asynccnt); 2015 array_verify (EV_A_ (W *)asyncs, asynccnt);
1974#endif 2016#endif
1975 2017
1993} 2035}
1994#endif 2036#endif
1995 2037
1996#if EV_MULTIPLICITY 2038#if EV_MULTIPLICITY
1997struct ev_loop * 2039struct ev_loop *
1998ev_default_loop_init (unsigned int flags)
1999#else 2040#else
2000int 2041int
2042#endif
2001ev_default_loop (unsigned int flags) 2043ev_default_loop (unsigned int flags)
2002#endif
2003{ 2044{
2004 if (!ev_default_loop_ptr) 2045 if (!ev_default_loop_ptr)
2005 { 2046 {
2006#if EV_MULTIPLICITY 2047#if EV_MULTIPLICITY
2007 EV_P = ev_default_loop_ptr = &default_loop_struct; 2048 EV_P = ev_default_loop_ptr = &default_loop_struct;
2026 2067
2027 return ev_default_loop_ptr; 2068 return ev_default_loop_ptr;
2028} 2069}
2029 2070
2030void 2071void
2031ev_default_destroy (void) 2072ev_loop_fork (EV_P)
2032{ 2073{
2033#if EV_MULTIPLICITY
2034 EV_P = ev_default_loop_ptr;
2035#endif
2036
2037 ev_default_loop_ptr = 0;
2038
2039#if EV_CHILD_ENABLE
2040 ev_ref (EV_A); /* child watcher */
2041 ev_signal_stop (EV_A_ &childev);
2042#endif
2043
2044 loop_destroy (EV_A);
2045}
2046
2047void
2048ev_default_fork (void)
2049{
2050#if EV_MULTIPLICITY
2051 EV_P = ev_default_loop_ptr;
2052#endif
2053
2054 postfork = 1; /* must be in line with ev_loop_fork */ 2074 postfork = 1; /* must be in line with ev_default_fork */
2055} 2075}
2056 2076
2057/*****************************************************************************/ 2077/*****************************************************************************/
2058 2078
2059void 2079void
3565 3585
3566 EV_FREQUENT_CHECK; 3586 EV_FREQUENT_CHECK;
3567} 3587}
3568#endif 3588#endif
3569 3589
3590#if EV_CLEANUP_ENABLE
3591void
3592ev_cleanup_start (EV_P_ ev_cleanup *w)
3593{
3594 if (expect_false (ev_is_active (w)))
3595 return;
3596
3597 EV_FREQUENT_CHECK;
3598
3599 ev_start (EV_A_ (W)w, ++cleanupcnt);
3600 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2);
3601 cleanups [cleanupcnt - 1] = w;
3602
3603 /* cleanup watchers should never keep a refcount on the loop */
3604 ev_unref (EV_A);
3605 EV_FREQUENT_CHECK;
3606}
3607
3608void
3609ev_cleanup_stop (EV_P_ ev_cleanup *w)
3610{
3611 clear_pending (EV_A_ (W)w);
3612 if (expect_false (!ev_is_active (w)))
3613 return;
3614
3615 EV_FREQUENT_CHECK;
3616 ev_ref (EV_A);
3617
3618 {
3619 int active = ev_active (w);
3620
3621 cleanups [active - 1] = cleanups [--cleanupcnt];
3622 ev_active (cleanups [active - 1]) = active;
3623 }
3624
3625 ev_stop (EV_A_ (W)w);
3626
3627 EV_FREQUENT_CHECK;
3628}
3629#endif
3630
3570#if EV_ASYNC_ENABLE 3631#if EV_ASYNC_ENABLE
3571void 3632void
3572ev_async_start (EV_P_ ev_async *w) 3633ev_async_start (EV_P_ ev_async *w)
3573{ 3634{
3574 if (expect_false (ev_is_active (w))) 3635 if (expect_false (ev_is_active (w)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines