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

Comparing libev/ev.c (file contents):
Revision 1.479 by root, Sun Dec 20 01:31:17 2015 UTC vs.
Revision 1.483 by root, Tue Jul 31 04:45:58 2018 UTC

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 */
1591noinline
1589static ev_tstamp noinline 1592static ev_tstamp
1590ev_floor (ev_tstamp v) 1593ev_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
1631static unsigned int noinline ecb_cold 1634noinline ecb_cold
1635static unsigned int
1632ev_linux_version (void) 1636ev_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
1670static void noinline ecb_cold 1674noinline ecb_cold
1675static void
1671ev_printerr (const char *msg) 1676ev_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
1677static void (*syserr_cb)(const char *msg) EV_THROW; 1682static void (*syserr_cb)(const char *msg) EV_THROW;
1678 1683
1679void ecb_cold 1684ecb_cold
1685void
1680ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW 1686ev_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
1685static void noinline ecb_cold 1691noinline ecb_cold
1692static void
1686ev_syserr (const char *msg) 1693ev_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
1724static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1731static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1725 1732
1726void ecb_cold 1733ecb_cold
1734void
1727ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW 1735ev_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
1945static void * noinline ecb_cold 1955noinline ecb_cold
1956static void *
1946array_realloc (int elem, void *base, int *cur, int cnt) 1957array_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 */
1980static void noinline 1991noinline
1992static void
1981pendingcb (EV_P_ ev_prepare *w, int revents) 1993pendingcb (EV_P_ ev_prepare *w, int revents)
1982{ 1994{
1983} 1995}
1984 1996
1985void noinline 1997noinline
1998void
1986ev_feed_event (EV_P_ void *w, int revents) EV_THROW 1999ev_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 */
2125inline_size void 2138inline_size
2139void
2126fd_change (EV_P_ int fd, int flags) 2140fd_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 */
2140inline_speed void ecb_cold 2154inline_speed ecb_cold void
2141fd_kill (EV_P_ int fd) 2155fd_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 */
2153inline_size int ecb_cold 2167inline_size ecb_cold int
2154fd_valid (int fd) 2168fd_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 */
2164static void noinline ecb_cold 2178noinline ecb_cold
2179static void
2165fd_ebadf (EV_P) 2180fd_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 */
2176static void noinline ecb_cold 2191noinline ecb_cold
2192static void
2177fd_enomem (EV_P) 2193fd_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 */
2190static void noinline 2206noinline
2207static void
2191fd_rearm_all (EV_P) 2208fd_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
2381static void noinline ecb_cold 2398noinline ecb_cold
2399static void
2382evpipe_init (EV_P) 2400evpipe_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
2569void noinline 2587noinline
2588void
2570ev_feed_signal_event (EV_P_ int signum) EV_THROW 2589ev_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
2696int ecb_cold 2715ecb_cold int
2697ev_version_major (void) EV_THROW 2716ev_version_major (void) EV_THROW
2698{ 2717{
2699 return EV_VERSION_MAJOR; 2718 return EV_VERSION_MAJOR;
2700} 2719}
2701 2720
2702int ecb_cold 2721ecb_cold int
2703ev_version_minor (void) EV_THROW 2722ev_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 */
2709int inline_size ecb_cold 2728inline_size ecb_cold int
2710enable_secure (void) 2729enable_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
2720unsigned int ecb_cold 2739ecb_cold
2740unsigned int
2721ev_supported_backends (void) EV_THROW 2741ev_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
2734unsigned int ecb_cold 2754ecb_cold
2755unsigned int
2735ev_recommended_backends (void) EV_THROW 2756ev_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
2756unsigned int ecb_cold 2777ecb_cold
2778unsigned int
2757ev_embeddable_backends (void) EV_THROW 2779ev_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 */
2826static void noinline ecb_cold 2848noinline ecb_cold
2849static void
2827loop_init (EV_P_ unsigned int flags) EV_THROW 2850loop_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 */
2923void ecb_cold 2946ecb_cold
2947void
2924ev_loop_destroy (EV_P) 2948ev_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
3099ecb_cold
3075struct ev_loop * ecb_cold 3100struct ev_loop *
3076ev_loop_new (unsigned int flags) EV_THROW 3101ev_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
3093static void noinline ecb_cold 3118noinline ecb_cold
3119static void
3094verify_watcher (EV_P_ W w) 3120verify_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
3102static void noinline ecb_cold 3128noinline ecb_cold
3129static void
3103verify_heap (EV_P_ ANHE *heap, int N) 3130verify_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
3117static void noinline ecb_cold 3144noinline ecb_cold
3145static void
3118array_verify (EV_P_ W *ws, int cnt) 3146array_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
3244ecb_cold
3216struct ev_loop * ecb_cold 3245struct ev_loop *
3217#else 3246#else
3218int 3247int
3219#endif 3248#endif
3220ev_default_loop (unsigned int flags) EV_THROW 3249ev_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
3274void noinline 3303noinline
3304void
3275ev_invoke_pending (EV_P) 3305ev_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
3359static void noinline 3389noinline
3390static void
3360periodic_recalc (EV_P_ ev_periodic *w) 3391periodic_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? */
3427static void noinline ecb_cold 3458noinline ecb_cold
3459static void
3428periodics_reschedule (EV_P) 3460periodics_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 */
3450static void noinline ecb_cold 3482noinline ecb_cold
3483static void
3451timers_reschedule (EV_P_ ev_tstamp adjust) 3484timers_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
3828void noinline 3861noinline
3862void
3829ev_io_start (EV_P_ ev_io *w) EV_THROW 3863ev_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
3854void noinline 3888noinline
3889void
3855ev_io_stop (EV_P_ ev_io *w) EV_THROW 3890ev_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
3873void noinline 3908noinline
3909void
3874ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3910ev_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
3897void noinline 3933noinline
3934void
3898ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3935ev_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
3927void noinline 3964noinline
3965void
3928ev_timer_again (EV_P_ ev_timer *w) EV_THROW 3966ev_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
3961void noinline 3999noinline
4000void
3962ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4001ev_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
3991void noinline 4030noinline
4031void
3992ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4032ev_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
4019void noinline 4059noinline
4060void
4020ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4061ev_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
4034void noinline 4075noinline
4076void
4035ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4077ev_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
4116void noinline 4158noinline
4159void
4117ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4160ev_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
4202static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4245noinline 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
4209static void noinline 4252noinline
4253static void
4210infy_add (EV_P_ ev_stat *w) 4254infy_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
4283static void noinline 4327noinline
4328static void
4284infy_del (EV_P_ ev_stat *w) 4329infy_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
4300static void noinline 4345noinline
4346static void
4301infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4347infy_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
4346inline_size void ecb_cold 4392inline_size ecb_cold
4393void
4347ev_check_2625 (EV_P) 4394ev_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
4454static void noinline 4501noinline
4502static void
4455stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4503stat_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
4674void noinline 4722noinline
4723void
4675ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4724ev_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
4981void ecb_cold 5030ecb_cold
5031void
4982ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5032ev_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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines