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.480 by root, Thu Feb 18 04:48:05 2016 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines