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