… | |
… | |
162 | # define EV_USE_EVENTFD 0 |
162 | # define EV_USE_EVENTFD 0 |
163 | # endif |
163 | # endif |
164 | |
164 | |
165 | #endif |
165 | #endif |
166 | |
166 | |
|
|
167 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
168 | * a limit of 1024 into their select. Where people have brains, |
|
|
169 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
170 | * ordered to have a vacuum, or they do anything for money. |
|
|
171 | * This might help. Or not. |
|
|
172 | * Note that this must be defined early, as other include files |
|
|
173 | * will rely on this define as well. |
|
|
174 | */ |
|
|
175 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
176 | |
167 | #include <stdlib.h> |
177 | #include <stdlib.h> |
168 | #include <string.h> |
178 | #include <string.h> |
169 | #include <fcntl.h> |
179 | #include <fcntl.h> |
170 | #include <stddef.h> |
180 | #include <stddef.h> |
171 | |
181 | |
… | |
… | |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
218 | # ifndef EV_SELECT_IS_WINSOCKET |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
219 | # define EV_SELECT_IS_WINSOCKET 1 |
210 | # endif |
220 | # endif |
211 | # undef EV_AVOID_STDIO |
221 | # undef EV_AVOID_STDIO |
212 | #endif |
222 | #endif |
213 | |
|
|
214 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
215 | * a limit of 1024 into their select. Where people have brains, |
|
|
216 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
217 | * ordered to have a vacuum, or they do anything for money. |
|
|
218 | * This might help. Or not. |
|
|
219 | */ |
|
|
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
221 | |
223 | |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
224 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
223 | |
225 | |
224 | /* try to deduce the maximum number of signals on this platform */ |
226 | /* try to deduce the maximum number of signals on this platform */ |
225 | #if defined EV_NSIG |
227 | #if defined EV_NSIG |
… | |
… | |
363 | |
365 | |
364 | #ifndef EV_HEAP_CACHE_AT |
366 | #ifndef EV_HEAP_CACHE_AT |
365 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
367 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
366 | #endif |
368 | #endif |
367 | |
369 | |
368 | #ifdef ANDROID |
370 | #ifdef __ANDROID__ |
369 | /* supposedly, android doesn't typedef fd_mask */ |
371 | /* supposedly, android doesn't typedef fd_mask */ |
370 | # undef EV_USE_SELECT |
372 | # undef EV_USE_SELECT |
371 | # define EV_USE_SELECT 0 |
373 | # define EV_USE_SELECT 0 |
372 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
374 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
373 | # undef EV_USE_CLOCK_SYSCALL |
375 | # undef EV_USE_CLOCK_SYSCALL |
… | |
… | |
1527 | #define inline_size ecb_inline |
1529 | #define inline_size ecb_inline |
1528 | |
1530 | |
1529 | #if EV_FEATURE_CODE |
1531 | #if EV_FEATURE_CODE |
1530 | # define inline_speed ecb_inline |
1532 | # define inline_speed ecb_inline |
1531 | #else |
1533 | #else |
1532 | # define inline_speed static noinline |
1534 | # define inline_speed noinline static |
1533 | #endif |
1535 | #endif |
1534 | |
1536 | |
1535 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1537 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1536 | |
1538 | |
1537 | #if EV_MINPRI == EV_MAXPRI |
1539 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
1584 | #else |
1586 | #else |
1585 | |
1587 | |
1586 | #include <float.h> |
1588 | #include <float.h> |
1587 | |
1589 | |
1588 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1590 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
|
|
1591 | noinline |
1589 | static ev_tstamp noinline |
1592 | static ev_tstamp |
1590 | ev_floor (ev_tstamp v) |
1593 | ev_floor (ev_tstamp v) |
1591 | { |
1594 | { |
1592 | /* the choice of shift factor is not terribly important */ |
1595 | /* the choice of shift factor is not terribly important */ |
1593 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1596 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1594 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1597 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
… | |
… | |
1626 | |
1629 | |
1627 | #ifdef __linux |
1630 | #ifdef __linux |
1628 | # include <sys/utsname.h> |
1631 | # include <sys/utsname.h> |
1629 | #endif |
1632 | #endif |
1630 | |
1633 | |
1631 | static unsigned int noinline ecb_cold |
1634 | noinline ecb_cold |
|
|
1635 | static unsigned int |
1632 | ev_linux_version (void) |
1636 | ev_linux_version (void) |
1633 | { |
1637 | { |
1634 | #ifdef __linux |
1638 | #ifdef __linux |
1635 | unsigned int v = 0; |
1639 | unsigned int v = 0; |
1636 | struct utsname buf; |
1640 | struct utsname buf; |
… | |
… | |
1665 | } |
1669 | } |
1666 | |
1670 | |
1667 | /*****************************************************************************/ |
1671 | /*****************************************************************************/ |
1668 | |
1672 | |
1669 | #if EV_AVOID_STDIO |
1673 | #if EV_AVOID_STDIO |
1670 | static void noinline ecb_cold |
1674 | noinline ecb_cold |
|
|
1675 | static void |
1671 | ev_printerr (const char *msg) |
1676 | ev_printerr (const char *msg) |
1672 | { |
1677 | { |
1673 | write (STDERR_FILENO, msg, strlen (msg)); |
1678 | write (STDERR_FILENO, msg, strlen (msg)); |
1674 | } |
1679 | } |
1675 | #endif |
1680 | #endif |
1676 | |
1681 | |
1677 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1682 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1678 | |
1683 | |
1679 | void ecb_cold |
1684 | ecb_cold |
|
|
1685 | void |
1680 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1686 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1681 | { |
1687 | { |
1682 | syserr_cb = cb; |
1688 | syserr_cb = cb; |
1683 | } |
1689 | } |
1684 | |
1690 | |
1685 | static void noinline ecb_cold |
1691 | noinline ecb_cold |
|
|
1692 | static void |
1686 | ev_syserr (const char *msg) |
1693 | ev_syserr (const char *msg) |
1687 | { |
1694 | { |
1688 | if (!msg) |
1695 | if (!msg) |
1689 | msg = "(libev) system error"; |
1696 | msg = "(libev) system error"; |
1690 | |
1697 | |
… | |
… | |
1721 | return 0; |
1728 | return 0; |
1722 | } |
1729 | } |
1723 | |
1730 | |
1724 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1731 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1725 | |
1732 | |
1726 | void ecb_cold |
1733 | ecb_cold |
|
|
1734 | void |
1727 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1735 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1728 | { |
1736 | { |
1729 | alloc = cb; |
1737 | alloc = cb; |
1730 | } |
1738 | } |
1731 | |
1739 | |
… | |
… | |
1900 | struct timespec ts; |
1908 | struct timespec ts; |
1901 | |
1909 | |
1902 | EV_TS_SET (ts, delay); |
1910 | EV_TS_SET (ts, delay); |
1903 | nanosleep (&ts, 0); |
1911 | nanosleep (&ts, 0); |
1904 | #elif defined _WIN32 |
1912 | #elif defined _WIN32 |
|
|
1913 | /* maybe this should round up, as ms is very low resolution */ |
|
|
1914 | /* compared to select (µs) or nanosleep (ns) */ |
1905 | Sleep ((unsigned long)(delay * 1e3)); |
1915 | Sleep ((unsigned long)(delay * 1e3)); |
1906 | #else |
1916 | #else |
1907 | struct timeval tv; |
1917 | struct timeval tv; |
1908 | |
1918 | |
1909 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1919 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1940 | } |
1950 | } |
1941 | |
1951 | |
1942 | return ncur; |
1952 | return ncur; |
1943 | } |
1953 | } |
1944 | |
1954 | |
1945 | static void * noinline ecb_cold |
1955 | noinline ecb_cold |
|
|
1956 | static void * |
1946 | array_realloc (int elem, void *base, int *cur, int cnt) |
1957 | array_realloc (int elem, void *base, int *cur, int cnt) |
1947 | { |
1958 | { |
1948 | *cur = array_nextsize (elem, *cur, cnt); |
1959 | *cur = array_nextsize (elem, *cur, cnt); |
1949 | return ev_realloc (base, elem * *cur); |
1960 | return ev_realloc (base, elem * *cur); |
1950 | } |
1961 | } |
… | |
… | |
1953 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1964 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1954 | |
1965 | |
1955 | #define array_needsize(type,base,cur,cnt,init) \ |
1966 | #define array_needsize(type,base,cur,cnt,init) \ |
1956 | if (expect_false ((cnt) > (cur))) \ |
1967 | if (expect_false ((cnt) > (cur))) \ |
1957 | { \ |
1968 | { \ |
1958 | int ecb_unused ocur_ = (cur); \ |
1969 | ecb_unused int ocur_ = (cur); \ |
1959 | (base) = (type *)array_realloc \ |
1970 | (base) = (type *)array_realloc \ |
1960 | (sizeof (type), (base), &(cur), (cnt)); \ |
1971 | (sizeof (type), (base), &(cur), (cnt)); \ |
1961 | init ((base) + (ocur_), (cur) - ocur_); \ |
1972 | init ((base) + (ocur_), (cur) - ocur_); \ |
1962 | } |
1973 | } |
1963 | |
1974 | |
… | |
… | |
1975 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
1986 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
1976 | |
1987 | |
1977 | /*****************************************************************************/ |
1988 | /*****************************************************************************/ |
1978 | |
1989 | |
1979 | /* dummy callback for pending events */ |
1990 | /* dummy callback for pending events */ |
1980 | static void noinline |
1991 | noinline |
|
|
1992 | static void |
1981 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1993 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1982 | { |
1994 | { |
1983 | } |
1995 | } |
1984 | |
1996 | |
1985 | void noinline |
1997 | noinline |
|
|
1998 | void |
1986 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1999 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1987 | { |
2000 | { |
1988 | W w_ = (W)w; |
2001 | W w_ = (W)w; |
1989 | int pri = ABSPRI (w_); |
2002 | int pri = ABSPRI (w_); |
1990 | |
2003 | |
… | |
… | |
2120 | |
2133 | |
2121 | fdchangecnt = 0; |
2134 | fdchangecnt = 0; |
2122 | } |
2135 | } |
2123 | |
2136 | |
2124 | /* something about the given fd changed */ |
2137 | /* something about the given fd changed */ |
2125 | inline_size void |
2138 | inline_size |
|
|
2139 | void |
2126 | fd_change (EV_P_ int fd, int flags) |
2140 | fd_change (EV_P_ int fd, int flags) |
2127 | { |
2141 | { |
2128 | unsigned char reify = anfds [fd].reify; |
2142 | unsigned char reify = anfds [fd].reify; |
2129 | anfds [fd].reify |= flags; |
2143 | anfds [fd].reify |= flags; |
2130 | |
2144 | |
… | |
… | |
2135 | fdchanges [fdchangecnt - 1] = fd; |
2149 | fdchanges [fdchangecnt - 1] = fd; |
2136 | } |
2150 | } |
2137 | } |
2151 | } |
2138 | |
2152 | |
2139 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2153 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2140 | inline_speed void ecb_cold |
2154 | inline_speed ecb_cold void |
2141 | fd_kill (EV_P_ int fd) |
2155 | fd_kill (EV_P_ int fd) |
2142 | { |
2156 | { |
2143 | ev_io *w; |
2157 | ev_io *w; |
2144 | |
2158 | |
2145 | while ((w = (ev_io *)anfds [fd].head)) |
2159 | while ((w = (ev_io *)anfds [fd].head)) |
… | |
… | |
2148 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2162 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2149 | } |
2163 | } |
2150 | } |
2164 | } |
2151 | |
2165 | |
2152 | /* check whether the given fd is actually valid, for error recovery */ |
2166 | /* check whether the given fd is actually valid, for error recovery */ |
2153 | inline_size int ecb_cold |
2167 | inline_size ecb_cold int |
2154 | fd_valid (int fd) |
2168 | fd_valid (int fd) |
2155 | { |
2169 | { |
2156 | #ifdef _WIN32 |
2170 | #ifdef _WIN32 |
2157 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2171 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2158 | #else |
2172 | #else |
2159 | return fcntl (fd, F_GETFD) != -1; |
2173 | return fcntl (fd, F_GETFD) != -1; |
2160 | #endif |
2174 | #endif |
2161 | } |
2175 | } |
2162 | |
2176 | |
2163 | /* called on EBADF to verify fds */ |
2177 | /* called on EBADF to verify fds */ |
2164 | static void noinline ecb_cold |
2178 | noinline ecb_cold |
|
|
2179 | static void |
2165 | fd_ebadf (EV_P) |
2180 | fd_ebadf (EV_P) |
2166 | { |
2181 | { |
2167 | int fd; |
2182 | int fd; |
2168 | |
2183 | |
2169 | for (fd = 0; fd < anfdmax; ++fd) |
2184 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2171 | if (!fd_valid (fd) && errno == EBADF) |
2186 | if (!fd_valid (fd) && errno == EBADF) |
2172 | fd_kill (EV_A_ fd); |
2187 | fd_kill (EV_A_ fd); |
2173 | } |
2188 | } |
2174 | |
2189 | |
2175 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2190 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2176 | static void noinline ecb_cold |
2191 | noinline ecb_cold |
|
|
2192 | static void |
2177 | fd_enomem (EV_P) |
2193 | fd_enomem (EV_P) |
2178 | { |
2194 | { |
2179 | int fd; |
2195 | int fd; |
2180 | |
2196 | |
2181 | for (fd = anfdmax; fd--; ) |
2197 | for (fd = anfdmax; fd--; ) |
… | |
… | |
2185 | break; |
2201 | break; |
2186 | } |
2202 | } |
2187 | } |
2203 | } |
2188 | |
2204 | |
2189 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2205 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2190 | static void noinline |
2206 | noinline |
|
|
2207 | static void |
2191 | fd_rearm_all (EV_P) |
2208 | fd_rearm_all (EV_P) |
2192 | { |
2209 | { |
2193 | int fd; |
2210 | int fd; |
2194 | |
2211 | |
2195 | for (fd = 0; fd < anfdmax; ++fd) |
2212 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2376 | |
2393 | |
2377 | /*****************************************************************************/ |
2394 | /*****************************************************************************/ |
2378 | |
2395 | |
2379 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2396 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2380 | |
2397 | |
2381 | static void noinline ecb_cold |
2398 | noinline ecb_cold |
|
|
2399 | static void |
2382 | evpipe_init (EV_P) |
2400 | evpipe_init (EV_P) |
2383 | { |
2401 | { |
2384 | if (!ev_is_active (&pipe_w)) |
2402 | if (!ev_is_active (&pipe_w)) |
2385 | { |
2403 | { |
2386 | int fds [2]; |
2404 | int fds [2]; |
… | |
… | |
2564 | #endif |
2582 | #endif |
2565 | |
2583 | |
2566 | ev_feed_signal (signum); |
2584 | ev_feed_signal (signum); |
2567 | } |
2585 | } |
2568 | |
2586 | |
2569 | void noinline |
2587 | noinline |
|
|
2588 | void |
2570 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2589 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2571 | { |
2590 | { |
2572 | WL w; |
2591 | WL w; |
2573 | |
2592 | |
2574 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2593 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
… | |
… | |
2691 | #endif |
2710 | #endif |
2692 | #if EV_USE_SELECT |
2711 | #if EV_USE_SELECT |
2693 | # include "ev_select.c" |
2712 | # include "ev_select.c" |
2694 | #endif |
2713 | #endif |
2695 | |
2714 | |
2696 | int ecb_cold |
2715 | ecb_cold int |
2697 | ev_version_major (void) EV_THROW |
2716 | ev_version_major (void) EV_THROW |
2698 | { |
2717 | { |
2699 | return EV_VERSION_MAJOR; |
2718 | return EV_VERSION_MAJOR; |
2700 | } |
2719 | } |
2701 | |
2720 | |
2702 | int ecb_cold |
2721 | ecb_cold int |
2703 | ev_version_minor (void) EV_THROW |
2722 | ev_version_minor (void) EV_THROW |
2704 | { |
2723 | { |
2705 | return EV_VERSION_MINOR; |
2724 | return EV_VERSION_MINOR; |
2706 | } |
2725 | } |
2707 | |
2726 | |
2708 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2727 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2709 | int inline_size ecb_cold |
2728 | inline_size ecb_cold int |
2710 | enable_secure (void) |
2729 | enable_secure (void) |
2711 | { |
2730 | { |
2712 | #ifdef _WIN32 |
2731 | #ifdef _WIN32 |
2713 | return 0; |
2732 | return 0; |
2714 | #else |
2733 | #else |
2715 | return getuid () != geteuid () |
2734 | return getuid () != geteuid () |
2716 | || getgid () != getegid (); |
2735 | || getgid () != getegid (); |
2717 | #endif |
2736 | #endif |
2718 | } |
2737 | } |
2719 | |
2738 | |
2720 | unsigned int ecb_cold |
2739 | ecb_cold |
|
|
2740 | unsigned int |
2721 | ev_supported_backends (void) EV_THROW |
2741 | ev_supported_backends (void) EV_THROW |
2722 | { |
2742 | { |
2723 | unsigned int flags = 0; |
2743 | unsigned int flags = 0; |
2724 | |
2744 | |
2725 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2745 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
… | |
… | |
2729 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2749 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2730 | |
2750 | |
2731 | return flags; |
2751 | return flags; |
2732 | } |
2752 | } |
2733 | |
2753 | |
2734 | unsigned int ecb_cold |
2754 | ecb_cold |
|
|
2755 | unsigned int |
2735 | ev_recommended_backends (void) EV_THROW |
2756 | ev_recommended_backends (void) EV_THROW |
2736 | { |
2757 | { |
2737 | unsigned int flags = ev_supported_backends (); |
2758 | unsigned int flags = ev_supported_backends (); |
2738 | |
2759 | |
2739 | #ifndef __NetBSD__ |
2760 | #ifndef __NetBSD__ |
… | |
… | |
2751 | #endif |
2772 | #endif |
2752 | |
2773 | |
2753 | return flags; |
2774 | return flags; |
2754 | } |
2775 | } |
2755 | |
2776 | |
2756 | unsigned int ecb_cold |
2777 | ecb_cold |
|
|
2778 | unsigned int |
2757 | ev_embeddable_backends (void) EV_THROW |
2779 | ev_embeddable_backends (void) EV_THROW |
2758 | { |
2780 | { |
2759 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2781 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2760 | |
2782 | |
2761 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2783 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
… | |
… | |
2821 | acquire_cb = acquire; |
2843 | acquire_cb = acquire; |
2822 | } |
2844 | } |
2823 | #endif |
2845 | #endif |
2824 | |
2846 | |
2825 | /* initialise a loop structure, must be zero-initialised */ |
2847 | /* initialise a loop structure, must be zero-initialised */ |
2826 | static void noinline ecb_cold |
2848 | noinline ecb_cold |
|
|
2849 | static void |
2827 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2850 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2828 | { |
2851 | { |
2829 | if (!backend) |
2852 | if (!backend) |
2830 | { |
2853 | { |
2831 | origflags = flags; |
2854 | origflags = flags; |
… | |
… | |
2918 | #endif |
2941 | #endif |
2919 | } |
2942 | } |
2920 | } |
2943 | } |
2921 | |
2944 | |
2922 | /* free up a loop structure */ |
2945 | /* free up a loop structure */ |
2923 | void ecb_cold |
2946 | ecb_cold |
|
|
2947 | void |
2924 | ev_loop_destroy (EV_P) |
2948 | ev_loop_destroy (EV_P) |
2925 | { |
2949 | { |
2926 | int i; |
2950 | int i; |
2927 | |
2951 | |
2928 | #if EV_MULTIPLICITY |
2952 | #if EV_MULTIPLICITY |
… | |
… | |
3070 | postfork = 0; |
3094 | postfork = 0; |
3071 | } |
3095 | } |
3072 | |
3096 | |
3073 | #if EV_MULTIPLICITY |
3097 | #if EV_MULTIPLICITY |
3074 | |
3098 | |
|
|
3099 | ecb_cold |
3075 | struct ev_loop * ecb_cold |
3100 | struct ev_loop * |
3076 | ev_loop_new (unsigned int flags) EV_THROW |
3101 | ev_loop_new (unsigned int flags) EV_THROW |
3077 | { |
3102 | { |
3078 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3103 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3079 | |
3104 | |
3080 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3105 | memset (EV_A, 0, sizeof (struct ev_loop)); |
… | |
… | |
3088 | } |
3113 | } |
3089 | |
3114 | |
3090 | #endif /* multiplicity */ |
3115 | #endif /* multiplicity */ |
3091 | |
3116 | |
3092 | #if EV_VERIFY |
3117 | #if EV_VERIFY |
3093 | static void noinline ecb_cold |
3118 | noinline ecb_cold |
|
|
3119 | static void |
3094 | verify_watcher (EV_P_ W w) |
3120 | verify_watcher (EV_P_ W w) |
3095 | { |
3121 | { |
3096 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3122 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3097 | |
3123 | |
3098 | if (w->pending) |
3124 | if (w->pending) |
3099 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3125 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3100 | } |
3126 | } |
3101 | |
3127 | |
3102 | static void noinline ecb_cold |
3128 | noinline ecb_cold |
|
|
3129 | static void |
3103 | verify_heap (EV_P_ ANHE *heap, int N) |
3130 | verify_heap (EV_P_ ANHE *heap, int N) |
3104 | { |
3131 | { |
3105 | int i; |
3132 | int i; |
3106 | |
3133 | |
3107 | for (i = HEAP0; i < N + HEAP0; ++i) |
3134 | for (i = HEAP0; i < N + HEAP0; ++i) |
… | |
… | |
3112 | |
3139 | |
3113 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3140 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3114 | } |
3141 | } |
3115 | } |
3142 | } |
3116 | |
3143 | |
3117 | static void noinline ecb_cold |
3144 | noinline ecb_cold |
|
|
3145 | static void |
3118 | array_verify (EV_P_ W *ws, int cnt) |
3146 | array_verify (EV_P_ W *ws, int cnt) |
3119 | { |
3147 | { |
3120 | while (cnt--) |
3148 | while (cnt--) |
3121 | { |
3149 | { |
3122 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
3150 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
… | |
… | |
3211 | #endif |
3239 | #endif |
3212 | } |
3240 | } |
3213 | #endif |
3241 | #endif |
3214 | |
3242 | |
3215 | #if EV_MULTIPLICITY |
3243 | #if EV_MULTIPLICITY |
|
|
3244 | ecb_cold |
3216 | struct ev_loop * ecb_cold |
3245 | struct ev_loop * |
3217 | #else |
3246 | #else |
3218 | int |
3247 | int |
3219 | #endif |
3248 | #endif |
3220 | ev_default_loop (unsigned int flags) EV_THROW |
3249 | ev_default_loop (unsigned int flags) EV_THROW |
3221 | { |
3250 | { |
… | |
… | |
3269 | count += pendingcnt [pri]; |
3298 | count += pendingcnt [pri]; |
3270 | |
3299 | |
3271 | return count; |
3300 | return count; |
3272 | } |
3301 | } |
3273 | |
3302 | |
3274 | void noinline |
3303 | noinline |
|
|
3304 | void |
3275 | ev_invoke_pending (EV_P) |
3305 | ev_invoke_pending (EV_P) |
3276 | { |
3306 | { |
3277 | pendingpri = NUMPRI; |
3307 | pendingpri = NUMPRI; |
3278 | |
3308 | |
3279 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3309 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
… | |
… | |
3354 | } |
3384 | } |
3355 | } |
3385 | } |
3356 | |
3386 | |
3357 | #if EV_PERIODIC_ENABLE |
3387 | #if EV_PERIODIC_ENABLE |
3358 | |
3388 | |
3359 | static void noinline |
3389 | noinline |
|
|
3390 | static void |
3360 | periodic_recalc (EV_P_ ev_periodic *w) |
3391 | periodic_recalc (EV_P_ ev_periodic *w) |
3361 | { |
3392 | { |
3362 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3393 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3363 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3394 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3364 | |
3395 | |
… | |
… | |
3422 | } |
3453 | } |
3423 | } |
3454 | } |
3424 | |
3455 | |
3425 | /* simply recalculate all periodics */ |
3456 | /* simply recalculate all periodics */ |
3426 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3457 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3427 | static void noinline ecb_cold |
3458 | noinline ecb_cold |
|
|
3459 | static void |
3428 | periodics_reschedule (EV_P) |
3460 | periodics_reschedule (EV_P) |
3429 | { |
3461 | { |
3430 | int i; |
3462 | int i; |
3431 | |
3463 | |
3432 | /* adjust periodics after time jump */ |
3464 | /* adjust periodics after time jump */ |
… | |
… | |
3445 | reheap (periodics, periodiccnt); |
3477 | reheap (periodics, periodiccnt); |
3446 | } |
3478 | } |
3447 | #endif |
3479 | #endif |
3448 | |
3480 | |
3449 | /* adjust all timers by a given offset */ |
3481 | /* adjust all timers by a given offset */ |
3450 | static void noinline ecb_cold |
3482 | noinline ecb_cold |
|
|
3483 | static void |
3451 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3484 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3452 | { |
3485 | { |
3453 | int i; |
3486 | int i; |
3454 | |
3487 | |
3455 | for (i = 0; i < timercnt; ++i) |
3488 | for (i = 0; i < timercnt; ++i) |
… | |
… | |
3823 | w->active = 0; |
3856 | w->active = 0; |
3824 | } |
3857 | } |
3825 | |
3858 | |
3826 | /*****************************************************************************/ |
3859 | /*****************************************************************************/ |
3827 | |
3860 | |
3828 | void noinline |
3861 | noinline |
|
|
3862 | void |
3829 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3863 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3830 | { |
3864 | { |
3831 | int fd = w->fd; |
3865 | int fd = w->fd; |
3832 | |
3866 | |
3833 | if (expect_false (ev_is_active (w))) |
3867 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3849 | w->events &= ~EV__IOFDSET; |
3883 | w->events &= ~EV__IOFDSET; |
3850 | |
3884 | |
3851 | EV_FREQUENT_CHECK; |
3885 | EV_FREQUENT_CHECK; |
3852 | } |
3886 | } |
3853 | |
3887 | |
3854 | void noinline |
3888 | noinline |
|
|
3889 | void |
3855 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3890 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3856 | { |
3891 | { |
3857 | clear_pending (EV_A_ (W)w); |
3892 | clear_pending (EV_A_ (W)w); |
3858 | if (expect_false (!ev_is_active (w))) |
3893 | if (expect_false (!ev_is_active (w))) |
3859 | return; |
3894 | return; |
… | |
… | |
3868 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3903 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3869 | |
3904 | |
3870 | EV_FREQUENT_CHECK; |
3905 | EV_FREQUENT_CHECK; |
3871 | } |
3906 | } |
3872 | |
3907 | |
3873 | void noinline |
3908 | noinline |
|
|
3909 | void |
3874 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3910 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3875 | { |
3911 | { |
3876 | if (expect_false (ev_is_active (w))) |
3912 | if (expect_false (ev_is_active (w))) |
3877 | return; |
3913 | return; |
3878 | |
3914 | |
… | |
… | |
3892 | EV_FREQUENT_CHECK; |
3928 | EV_FREQUENT_CHECK; |
3893 | |
3929 | |
3894 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3930 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3895 | } |
3931 | } |
3896 | |
3932 | |
3897 | void noinline |
3933 | noinline |
|
|
3934 | void |
3898 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3935 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3899 | { |
3936 | { |
3900 | clear_pending (EV_A_ (W)w); |
3937 | clear_pending (EV_A_ (W)w); |
3901 | if (expect_false (!ev_is_active (w))) |
3938 | if (expect_false (!ev_is_active (w))) |
3902 | return; |
3939 | return; |
… | |
… | |
3922 | ev_stop (EV_A_ (W)w); |
3959 | ev_stop (EV_A_ (W)w); |
3923 | |
3960 | |
3924 | EV_FREQUENT_CHECK; |
3961 | EV_FREQUENT_CHECK; |
3925 | } |
3962 | } |
3926 | |
3963 | |
3927 | void noinline |
3964 | noinline |
|
|
3965 | void |
3928 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3966 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3929 | { |
3967 | { |
3930 | EV_FREQUENT_CHECK; |
3968 | EV_FREQUENT_CHECK; |
3931 | |
3969 | |
3932 | clear_pending (EV_A_ (W)w); |
3970 | clear_pending (EV_A_ (W)w); |
… | |
… | |
3956 | { |
3994 | { |
3957 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3995 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3958 | } |
3996 | } |
3959 | |
3997 | |
3960 | #if EV_PERIODIC_ENABLE |
3998 | #if EV_PERIODIC_ENABLE |
3961 | void noinline |
3999 | noinline |
|
|
4000 | void |
3962 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4001 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3963 | { |
4002 | { |
3964 | if (expect_false (ev_is_active (w))) |
4003 | if (expect_false (ev_is_active (w))) |
3965 | return; |
4004 | return; |
3966 | |
4005 | |
… | |
… | |
3986 | EV_FREQUENT_CHECK; |
4025 | EV_FREQUENT_CHECK; |
3987 | |
4026 | |
3988 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4027 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3989 | } |
4028 | } |
3990 | |
4029 | |
3991 | void noinline |
4030 | noinline |
|
|
4031 | void |
3992 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4032 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3993 | { |
4033 | { |
3994 | clear_pending (EV_A_ (W)w); |
4034 | clear_pending (EV_A_ (W)w); |
3995 | if (expect_false (!ev_is_active (w))) |
4035 | if (expect_false (!ev_is_active (w))) |
3996 | return; |
4036 | return; |
… | |
… | |
4014 | ev_stop (EV_A_ (W)w); |
4054 | ev_stop (EV_A_ (W)w); |
4015 | |
4055 | |
4016 | EV_FREQUENT_CHECK; |
4056 | EV_FREQUENT_CHECK; |
4017 | } |
4057 | } |
4018 | |
4058 | |
4019 | void noinline |
4059 | noinline |
|
|
4060 | void |
4020 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4061 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4021 | { |
4062 | { |
4022 | /* TODO: use adjustheap and recalculation */ |
4063 | /* TODO: use adjustheap and recalculation */ |
4023 | ev_periodic_stop (EV_A_ w); |
4064 | ev_periodic_stop (EV_A_ w); |
4024 | ev_periodic_start (EV_A_ w); |
4065 | ev_periodic_start (EV_A_ w); |
… | |
… | |
4029 | # define SA_RESTART 0 |
4070 | # define SA_RESTART 0 |
4030 | #endif |
4071 | #endif |
4031 | |
4072 | |
4032 | #if EV_SIGNAL_ENABLE |
4073 | #if EV_SIGNAL_ENABLE |
4033 | |
4074 | |
4034 | void noinline |
4075 | noinline |
|
|
4076 | void |
4035 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4077 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4036 | { |
4078 | { |
4037 | if (expect_false (ev_is_active (w))) |
4079 | if (expect_false (ev_is_active (w))) |
4038 | return; |
4080 | return; |
4039 | |
4081 | |
… | |
… | |
4111 | } |
4153 | } |
4112 | |
4154 | |
4113 | EV_FREQUENT_CHECK; |
4155 | EV_FREQUENT_CHECK; |
4114 | } |
4156 | } |
4115 | |
4157 | |
4116 | void noinline |
4158 | noinline |
|
|
4159 | void |
4117 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4160 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4118 | { |
4161 | { |
4119 | clear_pending (EV_A_ (W)w); |
4162 | clear_pending (EV_A_ (W)w); |
4120 | if (expect_false (!ev_is_active (w))) |
4163 | if (expect_false (!ev_is_active (w))) |
4121 | return; |
4164 | return; |
… | |
… | |
4197 | |
4240 | |
4198 | #define DEF_STAT_INTERVAL 5.0074891 |
4241 | #define DEF_STAT_INTERVAL 5.0074891 |
4199 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4242 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4200 | #define MIN_STAT_INTERVAL 0.1074891 |
4243 | #define MIN_STAT_INTERVAL 0.1074891 |
4201 | |
4244 | |
4202 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4245 | noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4203 | |
4246 | |
4204 | #if EV_USE_INOTIFY |
4247 | #if EV_USE_INOTIFY |
4205 | |
4248 | |
4206 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4249 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4207 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4250 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4208 | |
4251 | |
4209 | static void noinline |
4252 | noinline |
|
|
4253 | static void |
4210 | infy_add (EV_P_ ev_stat *w) |
4254 | infy_add (EV_P_ ev_stat *w) |
4211 | { |
4255 | { |
4212 | w->wd = inotify_add_watch (fs_fd, w->path, |
4256 | w->wd = inotify_add_watch (fs_fd, w->path, |
4213 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4257 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4214 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
4258 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
… | |
… | |
4278 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4322 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4279 | ev_timer_again (EV_A_ &w->timer); |
4323 | ev_timer_again (EV_A_ &w->timer); |
4280 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4324 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4281 | } |
4325 | } |
4282 | |
4326 | |
4283 | static void noinline |
4327 | noinline |
|
|
4328 | static void |
4284 | infy_del (EV_P_ ev_stat *w) |
4329 | infy_del (EV_P_ ev_stat *w) |
4285 | { |
4330 | { |
4286 | int slot; |
4331 | int slot; |
4287 | int wd = w->wd; |
4332 | int wd = w->wd; |
4288 | |
4333 | |
… | |
… | |
4295 | |
4340 | |
4296 | /* remove this watcher, if others are watching it, they will rearm */ |
4341 | /* remove this watcher, if others are watching it, they will rearm */ |
4297 | inotify_rm_watch (fs_fd, wd); |
4342 | inotify_rm_watch (fs_fd, wd); |
4298 | } |
4343 | } |
4299 | |
4344 | |
4300 | static void noinline |
4345 | noinline |
|
|
4346 | static void |
4301 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4347 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4302 | { |
4348 | { |
4303 | if (slot < 0) |
4349 | if (slot < 0) |
4304 | /* overflow, need to check for all hash slots */ |
4350 | /* overflow, need to check for all hash slots */ |
4305 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
4351 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
… | |
… | |
4341 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4387 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4342 | ofs += sizeof (struct inotify_event) + ev->len; |
4388 | ofs += sizeof (struct inotify_event) + ev->len; |
4343 | } |
4389 | } |
4344 | } |
4390 | } |
4345 | |
4391 | |
4346 | inline_size void ecb_cold |
4392 | inline_size ecb_cold |
|
|
4393 | void |
4347 | ev_check_2625 (EV_P) |
4394 | ev_check_2625 (EV_P) |
4348 | { |
4395 | { |
4349 | /* kernels < 2.6.25 are borked |
4396 | /* kernels < 2.6.25 are borked |
4350 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4397 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4351 | */ |
4398 | */ |
… | |
… | |
4449 | w->attr.st_nlink = 0; |
4496 | w->attr.st_nlink = 0; |
4450 | else if (!w->attr.st_nlink) |
4497 | else if (!w->attr.st_nlink) |
4451 | w->attr.st_nlink = 1; |
4498 | w->attr.st_nlink = 1; |
4452 | } |
4499 | } |
4453 | |
4500 | |
4454 | static void noinline |
4501 | noinline |
|
|
4502 | static void |
4455 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4503 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4456 | { |
4504 | { |
4457 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4505 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4458 | |
4506 | |
4459 | ev_statdata prev = w->attr; |
4507 | ev_statdata prev = w->attr; |
… | |
… | |
4669 | EV_FREQUENT_CHECK; |
4717 | EV_FREQUENT_CHECK; |
4670 | } |
4718 | } |
4671 | #endif |
4719 | #endif |
4672 | |
4720 | |
4673 | #if EV_EMBED_ENABLE |
4721 | #if EV_EMBED_ENABLE |
4674 | void noinline |
4722 | noinline |
|
|
4723 | void |
4675 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4724 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4676 | { |
4725 | { |
4677 | ev_run (w->other, EVRUN_NOWAIT); |
4726 | ev_run (w->other, EVRUN_NOWAIT); |
4678 | } |
4727 | } |
4679 | |
4728 | |
… | |
… | |
4976 | } |
5025 | } |
4977 | |
5026 | |
4978 | /*****************************************************************************/ |
5027 | /*****************************************************************************/ |
4979 | |
5028 | |
4980 | #if EV_WALK_ENABLE |
5029 | #if EV_WALK_ENABLE |
4981 | void ecb_cold |
5030 | ecb_cold |
|
|
5031 | void |
4982 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5032 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4983 | { |
5033 | { |
4984 | int i, j; |
5034 | int i, j; |
4985 | ev_watcher_list *wl, *wn; |
5035 | ev_watcher_list *wl, *wn; |
4986 | |
5036 | |