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

Comparing libev/ev.c (file contents):
Revision 1.498 by root, Wed Jun 26 00:01:46 2019 UTC vs.
Revision 1.500 by root, Mon Jul 1 20:47:37 2019 UTC

1536/* ECB.H END */ 1536/* ECB.H END */
1537 1537
1538#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 1538#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
1539/* if your architecture doesn't need memory fences, e.g. because it is 1539/* if your architecture doesn't need memory fences, e.g. because it is
1540 * single-cpu/core, or if you use libev in a project that doesn't use libev 1540 * single-cpu/core, or if you use libev in a project that doesn't use libev
1541 * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling 1541 * from multiple threads, then you can define ECB_NO_THREADS when compiling
1542 * libev, in which cases the memory fences become nops. 1542 * libev, in which cases the memory fences become nops.
1543 * alternatively, you can remove this #error and link against libpthread, 1543 * alternatively, you can remove this #error and link against libpthread,
1544 * which will then provide the memory fences. 1544 * which will then provide the memory fences.
1545 */ 1545 */
1546# error "memory fences not defined for your architecture, please report" 1546# error "memory fences not defined for your architecture, please report"
1550# define ECB_MEMORY_FENCE do { } while (0) 1550# define ECB_MEMORY_FENCE do { } while (0)
1551# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 1551# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
1552# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 1552# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
1553#endif 1553#endif
1554 1554
1555#define expect_false(cond) ecb_expect_false (cond)
1556#define expect_true(cond) ecb_expect_true (cond)
1557#define noinline ecb_noinline
1558
1559#define inline_size ecb_inline 1555#define inline_size ecb_inline
1560 1556
1561#if EV_FEATURE_CODE 1557#if EV_FEATURE_CODE
1562# define inline_speed ecb_inline 1558# define inline_speed ecb_inline
1563#else 1559#else
1564# define inline_speed noinline static 1560# define inline_speed ecb_noinline static
1565#endif 1561#endif
1566 1562
1567#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 1563#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
1568 1564
1569#if EV_MINPRI == EV_MAXPRI 1565#if EV_MINPRI == EV_MAXPRI
1619#else 1615#else
1620 1616
1621#include <float.h> 1617#include <float.h>
1622 1618
1623/* a floor() replacement function, should be independent of ev_tstamp type */ 1619/* a floor() replacement function, should be independent of ev_tstamp type */
1624noinline 1620ecb_noinline
1625static ev_tstamp 1621static ev_tstamp
1626ev_floor (ev_tstamp v) 1622ev_floor (ev_tstamp v)
1627{ 1623{
1628 /* the choice of shift factor is not terribly important */ 1624 /* the choice of shift factor is not terribly important */
1629#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ 1625#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */
1631#else 1627#else
1632 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; 1628 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.;
1633#endif 1629#endif
1634 1630
1635 /* argument too large for an unsigned long? */ 1631 /* argument too large for an unsigned long? */
1636 if (expect_false (v >= shift)) 1632 if (ecb_expect_false (v >= shift))
1637 { 1633 {
1638 ev_tstamp f; 1634 ev_tstamp f;
1639 1635
1640 if (v == v - 1.) 1636 if (v == v - 1.)
1641 return v; /* very large number */ 1637 return v; /* very large number */
1643 f = shift * ev_floor (v * (1. / shift)); 1639 f = shift * ev_floor (v * (1. / shift));
1644 return f + ev_floor (v - f); 1640 return f + ev_floor (v - f);
1645 } 1641 }
1646 1642
1647 /* special treatment for negative args? */ 1643 /* special treatment for negative args? */
1648 if (expect_false (v < 0.)) 1644 if (ecb_expect_false (v < 0.))
1649 { 1645 {
1650 ev_tstamp f = -ev_floor (-v); 1646 ev_tstamp f = -ev_floor (-v);
1651 1647
1652 return f - (f == v ? 0 : 1); 1648 return f - (f == v ? 0 : 1);
1653 } 1649 }
1662 1658
1663#ifdef __linux 1659#ifdef __linux
1664# include <sys/utsname.h> 1660# include <sys/utsname.h>
1665#endif 1661#endif
1666 1662
1667noinline ecb_cold 1663ecb_noinline ecb_cold
1668static unsigned int 1664static unsigned int
1669ev_linux_version (void) 1665ev_linux_version (void)
1670{ 1666{
1671#ifdef __linux 1667#ifdef __linux
1672 unsigned int v = 0; 1668 unsigned int v = 0;
1702} 1698}
1703 1699
1704/*****************************************************************************/ 1700/*****************************************************************************/
1705 1701
1706#if EV_AVOID_STDIO 1702#if EV_AVOID_STDIO
1707noinline ecb_cold 1703ecb_noinline ecb_cold
1708static void 1704static void
1709ev_printerr (const char *msg) 1705ev_printerr (const char *msg)
1710{ 1706{
1711 write (STDERR_FILENO, msg, strlen (msg)); 1707 write (STDERR_FILENO, msg, strlen (msg));
1712} 1708}
1719ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT 1715ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT
1720{ 1716{
1721 syserr_cb = cb; 1717 syserr_cb = cb;
1722} 1718}
1723 1719
1724noinline ecb_cold 1720ecb_noinline ecb_cold
1725static void 1721static void
1726ev_syserr (const char *msg) 1722ev_syserr (const char *msg)
1727{ 1723{
1728 if (!msg) 1724 if (!msg)
1729 msg = "(libev) system error"; 1725 msg = "(libev) system error";
1875 static int ev_default_loop_ptr; 1871 static int ev_default_loop_ptr;
1876 1872
1877#endif 1873#endif
1878 1874
1879#if EV_FEATURE_API 1875#if EV_FEATURE_API
1880# define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) 1876# define EV_RELEASE_CB if (ecb_expect_false (release_cb)) release_cb (EV_A)
1881# define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) 1877# define EV_ACQUIRE_CB if (ecb_expect_false (acquire_cb)) acquire_cb (EV_A)
1882# define EV_INVOKE_PENDING invoke_cb (EV_A) 1878# define EV_INVOKE_PENDING invoke_cb (EV_A)
1883#else 1879#else
1884# define EV_RELEASE_CB (void)0 1880# define EV_RELEASE_CB (void)0
1885# define EV_ACQUIRE_CB (void)0 1881# define EV_ACQUIRE_CB (void)0
1886# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 1882# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
1893#ifndef EV_HAVE_EV_TIME 1889#ifndef EV_HAVE_EV_TIME
1894ev_tstamp 1890ev_tstamp
1895ev_time (void) EV_NOEXCEPT 1891ev_time (void) EV_NOEXCEPT
1896{ 1892{
1897#if EV_USE_REALTIME 1893#if EV_USE_REALTIME
1898 if (expect_true (have_realtime)) 1894 if (ecb_expect_true (have_realtime))
1899 { 1895 {
1900 struct timespec ts; 1896 struct timespec ts;
1901 clock_gettime (CLOCK_REALTIME, &ts); 1897 clock_gettime (CLOCK_REALTIME, &ts);
1902 return ts.tv_sec + ts.tv_nsec * 1e-9; 1898 return ts.tv_sec + ts.tv_nsec * 1e-9;
1903 } 1899 }
1911 1907
1912inline_size ev_tstamp 1908inline_size ev_tstamp
1913get_clock (void) 1909get_clock (void)
1914{ 1910{
1915#if EV_USE_MONOTONIC 1911#if EV_USE_MONOTONIC
1916 if (expect_true (have_monotonic)) 1912 if (ecb_expect_true (have_monotonic))
1917 { 1913 {
1918 struct timespec ts; 1914 struct timespec ts;
1919 clock_gettime (CLOCK_MONOTONIC, &ts); 1915 clock_gettime (CLOCK_MONOTONIC, &ts);
1920 return ts.tv_sec + ts.tv_nsec * 1e-9; 1916 return ts.tv_sec + ts.tv_nsec * 1e-9;
1921 } 1917 }
1983 } 1979 }
1984 1980
1985 return ncur; 1981 return ncur;
1986} 1982}
1987 1983
1988noinline ecb_cold 1984ecb_noinline ecb_cold
1989static void * 1985static void *
1990array_realloc (int elem, void *base, int *cur, int cnt) 1986array_realloc (int elem, void *base, int *cur, int cnt)
1991{ 1987{
1992 *cur = array_nextsize (elem, *cur, cnt); 1988 *cur = array_nextsize (elem, *cur, cnt);
1993 return ev_realloc (base, elem * *cur); 1989 return ev_realloc (base, elem * *cur);
1997 1993
1998#define array_needsize_zerofill(base,offset,count) \ 1994#define array_needsize_zerofill(base,offset,count) \
1999 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) 1995 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
2000 1996
2001#define array_needsize(type,base,cur,cnt,init) \ 1997#define array_needsize(type,base,cur,cnt,init) \
2002 if (expect_false ((cnt) > (cur))) \ 1998 if (ecb_expect_false ((cnt) > (cur))) \
2003 { \ 1999 { \
2004 ecb_unused int ocur_ = (cur); \ 2000 ecb_unused int ocur_ = (cur); \
2005 (base) = (type *)array_realloc \ 2001 (base) = (type *)array_realloc \
2006 (sizeof (type), (base), &(cur), (cnt)); \ 2002 (sizeof (type), (base), &(cur), (cnt)); \
2007 init ((base), ocur_, ((cur) - ocur_)); \ 2003 init ((base), ocur_, ((cur) - ocur_)); \
2021 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 2017 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0
2022 2018
2023/*****************************************************************************/ 2019/*****************************************************************************/
2024 2020
2025/* dummy callback for pending events */ 2021/* dummy callback for pending events */
2026noinline 2022ecb_noinline
2027static void 2023static void
2028pendingcb (EV_P_ ev_prepare *w, int revents) 2024pendingcb (EV_P_ ev_prepare *w, int revents)
2029{ 2025{
2030} 2026}
2031 2027
2032noinline 2028ecb_noinline
2033void 2029void
2034ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT 2030ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
2035{ 2031{
2036 W w_ = (W)w; 2032 W w_ = (W)w;
2037 int pri = ABSPRI (w_); 2033 int pri = ABSPRI (w_);
2038 2034
2039 if (expect_false (w_->pending)) 2035 if (ecb_expect_false (w_->pending))
2040 pendings [pri][w_->pending - 1].events |= revents; 2036 pendings [pri][w_->pending - 1].events |= revents;
2041 else 2037 else
2042 { 2038 {
2043 w_->pending = ++pendingcnt [pri]; 2039 w_->pending = ++pendingcnt [pri];
2044 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); 2040 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit);
2095inline_speed void 2091inline_speed void
2096fd_event (EV_P_ int fd, int revents) 2092fd_event (EV_P_ int fd, int revents)
2097{ 2093{
2098 ANFD *anfd = anfds + fd; 2094 ANFD *anfd = anfds + fd;
2099 2095
2100 if (expect_true (!anfd->reify)) 2096 if (ecb_expect_true (!anfd->reify))
2101 fd_event_nocheck (EV_A_ fd, revents); 2097 fd_event_nocheck (EV_A_ fd, revents);
2102} 2098}
2103 2099
2104void 2100void
2105ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT 2101ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2149 unsigned char o_events = anfd->events; 2145 unsigned char o_events = anfd->events;
2150 unsigned char o_reify = anfd->reify; 2146 unsigned char o_reify = anfd->reify;
2151 2147
2152 anfd->reify = 0; 2148 anfd->reify = 0;
2153 2149
2154 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 2150 /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
2155 { 2151 {
2156 anfd->events = 0; 2152 anfd->events = 0;
2157 2153
2158 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) 2154 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
2159 anfd->events |= (unsigned char)w->events; 2155 anfd->events |= (unsigned char)w->events;
2175fd_change (EV_P_ int fd, int flags) 2171fd_change (EV_P_ int fd, int flags)
2176{ 2172{
2177 unsigned char reify = anfds [fd].reify; 2173 unsigned char reify = anfds [fd].reify;
2178 anfds [fd].reify |= flags; 2174 anfds [fd].reify |= flags;
2179 2175
2180 if (expect_true (!reify)) 2176 if (ecb_expect_true (!reify))
2181 { 2177 {
2182 ++fdchangecnt; 2178 ++fdchangecnt;
2183 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); 2179 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2184 fdchanges [fdchangecnt - 1] = fd; 2180 fdchanges [fdchangecnt - 1] = fd;
2185 } 2181 }
2208 return fcntl (fd, F_GETFD) != -1; 2204 return fcntl (fd, F_GETFD) != -1;
2209#endif 2205#endif
2210} 2206}
2211 2207
2212/* called on EBADF to verify fds */ 2208/* called on EBADF to verify fds */
2213noinline ecb_cold 2209ecb_noinline ecb_cold
2214static void 2210static void
2215fd_ebadf (EV_P) 2211fd_ebadf (EV_P)
2216{ 2212{
2217 int fd; 2213 int fd;
2218 2214
2221 if (!fd_valid (fd) && errno == EBADF) 2217 if (!fd_valid (fd) && errno == EBADF)
2222 fd_kill (EV_A_ fd); 2218 fd_kill (EV_A_ fd);
2223} 2219}
2224 2220
2225/* called on ENOMEM in select/poll to kill some fds and retry */ 2221/* called on ENOMEM in select/poll to kill some fds and retry */
2226noinline ecb_cold 2222ecb_noinline ecb_cold
2227static void 2223static void
2228fd_enomem (EV_P) 2224fd_enomem (EV_P)
2229{ 2225{
2230 int fd; 2226 int fd;
2231 2227
2236 break; 2232 break;
2237 } 2233 }
2238} 2234}
2239 2235
2240/* usually called after fork if backend needs to re-arm all fds from scratch */ 2236/* usually called after fork if backend needs to re-arm all fds from scratch */
2241noinline 2237ecb_noinline
2242static void 2238static void
2243fd_rearm_all (EV_P) 2239fd_rearm_all (EV_P)
2244{ 2240{
2245 int fd; 2241 int fd;
2246 2242
2300 ev_tstamp minat; 2296 ev_tstamp minat;
2301 ANHE *minpos; 2297 ANHE *minpos;
2302 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; 2298 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1;
2303 2299
2304 /* find minimum child */ 2300 /* find minimum child */
2305 if (expect_true (pos + DHEAP - 1 < E)) 2301 if (ecb_expect_true (pos + DHEAP - 1 < E))
2306 { 2302 {
2307 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); 2303 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos));
2308 if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); 2304 if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos));
2309 if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); 2305 if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos));
2310 if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); 2306 if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos));
2428 2424
2429/*****************************************************************************/ 2425/*****************************************************************************/
2430 2426
2431#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2427#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2432 2428
2433noinline ecb_cold 2429ecb_noinline ecb_cold
2434static void 2430static void
2435evpipe_init (EV_P) 2431evpipe_init (EV_P)
2436{ 2432{
2437 if (!ev_is_active (&pipe_w)) 2433 if (!ev_is_active (&pipe_w))
2438 { 2434 {
2479inline_speed void 2475inline_speed void
2480evpipe_write (EV_P_ EV_ATOMIC_T *flag) 2476evpipe_write (EV_P_ EV_ATOMIC_T *flag)
2481{ 2477{
2482 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ 2478 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
2483 2479
2484 if (expect_true (*flag)) 2480 if (ecb_expect_true (*flag))
2485 return; 2481 return;
2486 2482
2487 *flag = 1; 2483 *flag = 1;
2488 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ 2484 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */
2489 2485
2566 sig_pending = 0; 2562 sig_pending = 0;
2567 2563
2568 ECB_MEMORY_FENCE; 2564 ECB_MEMORY_FENCE;
2569 2565
2570 for (i = EV_NSIG - 1; i--; ) 2566 for (i = EV_NSIG - 1; i--; )
2571 if (expect_false (signals [i].pending)) 2567 if (ecb_expect_false (signals [i].pending))
2572 ev_feed_signal_event (EV_A_ i + 1); 2568 ev_feed_signal_event (EV_A_ i + 1);
2573 } 2569 }
2574#endif 2570#endif
2575 2571
2576#if EV_ASYNC_ENABLE 2572#if EV_ASYNC_ENABLE
2617#endif 2613#endif
2618 2614
2619 ev_feed_signal (signum); 2615 ev_feed_signal (signum);
2620} 2616}
2621 2617
2622noinline 2618ecb_noinline
2623void 2619void
2624ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT 2620ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2625{ 2621{
2626 WL w; 2622 WL w;
2627 2623
2628 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2624 if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG))
2629 return; 2625 return;
2630 2626
2631 --signum; 2627 --signum;
2632 2628
2633#if EV_MULTIPLICITY 2629#if EV_MULTIPLICITY
2634 /* it is permissible to try to feed a signal to the wrong loop */ 2630 /* it is permissible to try to feed a signal to the wrong loop */
2635 /* or, likely more useful, feeding a signal nobody is waiting for */ 2631 /* or, likely more useful, feeding a signal nobody is waiting for */
2636 2632
2637 if (expect_false (signals [signum].loop != EV_A)) 2633 if (ecb_expect_false (signals [signum].loop != EV_A))
2638 return; 2634 return;
2639#endif 2635#endif
2640 2636
2641 signals [signum].pending = 0; 2637 signals [signum].pending = 0;
2642 ECB_MEMORY_FENCE_RELEASE; 2638 ECB_MEMORY_FENCE_RELEASE;
2887 acquire_cb = acquire; 2883 acquire_cb = acquire;
2888} 2884}
2889#endif 2885#endif
2890 2886
2891/* initialise a loop structure, must be zero-initialised */ 2887/* initialise a loop structure, must be zero-initialised */
2892noinline ecb_cold 2888ecb_noinline ecb_cold
2893static void 2889static void
2894loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT 2890loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2895{ 2891{
2896 if (!backend) 2892 if (!backend)
2897 { 2893 {
3002 return; 2998 return;
3003#endif 2999#endif
3004 3000
3005#if EV_CLEANUP_ENABLE 3001#if EV_CLEANUP_ENABLE
3006 /* queue cleanup watchers (and execute them) */ 3002 /* queue cleanup watchers (and execute them) */
3007 if (expect_false (cleanupcnt)) 3003 if (ecb_expect_false (cleanupcnt))
3008 { 3004 {
3009 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); 3005 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
3010 EV_INVOKE_PENDING; 3006 EV_INVOKE_PENDING;
3011 } 3007 }
3012#endif 3008#endif
3166} 3162}
3167 3163
3168#endif /* multiplicity */ 3164#endif /* multiplicity */
3169 3165
3170#if EV_VERIFY 3166#if EV_VERIFY
3171noinline ecb_cold 3167ecb_noinline ecb_cold
3172static void 3168static void
3173verify_watcher (EV_P_ W w) 3169verify_watcher (EV_P_ W w)
3174{ 3170{
3175 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 3171 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
3176 3172
3177 if (w->pending) 3173 if (w->pending)
3178 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); 3174 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
3179} 3175}
3180 3176
3181noinline ecb_cold 3177ecb_noinline ecb_cold
3182static void 3178static void
3183verify_heap (EV_P_ ANHE *heap, int N) 3179verify_heap (EV_P_ ANHE *heap, int N)
3184{ 3180{
3185 int i; 3181 int i;
3186 3182
3192 3188
3193 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 3189 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
3194 } 3190 }
3195} 3191}
3196 3192
3197noinline ecb_cold 3193ecb_noinline ecb_cold
3198static void 3194static void
3199array_verify (EV_P_ W *ws, int cnt) 3195array_verify (EV_P_ W *ws, int cnt)
3200{ 3196{
3201 while (cnt--) 3197 while (cnt--)
3202 { 3198 {
3351 count += pendingcnt [pri]; 3347 count += pendingcnt [pri];
3352 3348
3353 return count; 3349 return count;
3354} 3350}
3355 3351
3356noinline 3352ecb_noinline
3357void 3353void
3358ev_invoke_pending (EV_P) 3354ev_invoke_pending (EV_P)
3359{ 3355{
3360 pendingpri = NUMPRI; 3356 pendingpri = NUMPRI;
3361 3357
3380/* make idle watchers pending. this handles the "call-idle */ 3376/* make idle watchers pending. this handles the "call-idle */
3381/* only when higher priorities are idle" logic */ 3377/* only when higher priorities are idle" logic */
3382inline_size void 3378inline_size void
3383idle_reify (EV_P) 3379idle_reify (EV_P)
3384{ 3380{
3385 if (expect_false (idleall)) 3381 if (ecb_expect_false (idleall))
3386 { 3382 {
3387 int pri; 3383 int pri;
3388 3384
3389 for (pri = NUMPRI; pri--; ) 3385 for (pri = NUMPRI; pri--; )
3390 { 3386 {
3439 } 3435 }
3440} 3436}
3441 3437
3442#if EV_PERIODIC_ENABLE 3438#if EV_PERIODIC_ENABLE
3443 3439
3444noinline 3440ecb_noinline
3445static void 3441static void
3446periodic_recalc (EV_P_ ev_periodic *w) 3442periodic_recalc (EV_P_ ev_periodic *w)
3447{ 3443{
3448 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; 3444 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL;
3449 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); 3445 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval);
3452 while (at <= ev_rt_now) 3448 while (at <= ev_rt_now)
3453 { 3449 {
3454 ev_tstamp nat = at + w->interval; 3450 ev_tstamp nat = at + w->interval;
3455 3451
3456 /* when resolution fails us, we use ev_rt_now */ 3452 /* when resolution fails us, we use ev_rt_now */
3457 if (expect_false (nat == at)) 3453 if (ecb_expect_false (nat == at))
3458 { 3454 {
3459 at = ev_rt_now; 3455 at = ev_rt_now;
3460 break; 3456 break;
3461 } 3457 }
3462 3458
3508 } 3504 }
3509} 3505}
3510 3506
3511/* simply recalculate all periodics */ 3507/* simply recalculate all periodics */
3512/* TODO: maybe ensure that at least one event happens when jumping forward? */ 3508/* TODO: maybe ensure that at least one event happens when jumping forward? */
3513noinline ecb_cold 3509ecb_noinline ecb_cold
3514static void 3510static void
3515periodics_reschedule (EV_P) 3511periodics_reschedule (EV_P)
3516{ 3512{
3517 int i; 3513 int i;
3518 3514
3532 reheap (periodics, periodiccnt); 3528 reheap (periodics, periodiccnt);
3533} 3529}
3534#endif 3530#endif
3535 3531
3536/* adjust all timers by a given offset */ 3532/* adjust all timers by a given offset */
3537noinline ecb_cold 3533ecb_noinline ecb_cold
3538static void 3534static void
3539timers_reschedule (EV_P_ ev_tstamp adjust) 3535timers_reschedule (EV_P_ ev_tstamp adjust)
3540{ 3536{
3541 int i; 3537 int i;
3542 3538
3552/* also detect if there was a timejump, and act accordingly */ 3548/* also detect if there was a timejump, and act accordingly */
3553inline_speed void 3549inline_speed void
3554time_update (EV_P_ ev_tstamp max_block) 3550time_update (EV_P_ ev_tstamp max_block)
3555{ 3551{
3556#if EV_USE_MONOTONIC 3552#if EV_USE_MONOTONIC
3557 if (expect_true (have_monotonic)) 3553 if (ecb_expect_true (have_monotonic))
3558 { 3554 {
3559 int i; 3555 int i;
3560 ev_tstamp odiff = rtmn_diff; 3556 ev_tstamp odiff = rtmn_diff;
3561 3557
3562 mn_now = get_clock (); 3558 mn_now = get_clock ();
3563 3559
3564 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ 3560 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */
3565 /* interpolate in the meantime */ 3561 /* interpolate in the meantime */
3566 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 3562 if (ecb_expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
3567 { 3563 {
3568 ev_rt_now = rtmn_diff + mn_now; 3564 ev_rt_now = rtmn_diff + mn_now;
3569 return; 3565 return;
3570 } 3566 }
3571 3567
3585 ev_tstamp diff; 3581 ev_tstamp diff;
3586 rtmn_diff = ev_rt_now - mn_now; 3582 rtmn_diff = ev_rt_now - mn_now;
3587 3583
3588 diff = odiff - rtmn_diff; 3584 diff = odiff - rtmn_diff;
3589 3585
3590 if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) 3586 if (ecb_expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP))
3591 return; /* all is well */ 3587 return; /* all is well */
3592 3588
3593 ev_rt_now = ev_time (); 3589 ev_rt_now = ev_time ();
3594 mn_now = get_clock (); 3590 mn_now = get_clock ();
3595 now_floor = mn_now; 3591 now_floor = mn_now;
3604 else 3600 else
3605#endif 3601#endif
3606 { 3602 {
3607 ev_rt_now = ev_time (); 3603 ev_rt_now = ev_time ();
3608 3604
3609 if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) 3605 if (ecb_expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP))
3610 { 3606 {
3611 /* adjust timers. this is easy, as the offset is the same for all of them */ 3607 /* adjust timers. this is easy, as the offset is the same for all of them */
3612 timers_reschedule (EV_A_ ev_rt_now - mn_now); 3608 timers_reschedule (EV_A_ ev_rt_now - mn_now);
3613#if EV_PERIODIC_ENABLE 3609#if EV_PERIODIC_ENABLE
3614 periodics_reschedule (EV_A); 3610 periodics_reschedule (EV_A);
3637#if EV_VERIFY >= 2 3633#if EV_VERIFY >= 2
3638 ev_verify (EV_A); 3634 ev_verify (EV_A);
3639#endif 3635#endif
3640 3636
3641#ifndef _WIN32 3637#ifndef _WIN32
3642 if (expect_false (curpid)) /* penalise the forking check even more */ 3638 if (ecb_expect_false (curpid)) /* penalise the forking check even more */
3643 if (expect_false (getpid () != curpid)) 3639 if (ecb_expect_false (getpid () != curpid))
3644 { 3640 {
3645 curpid = getpid (); 3641 curpid = getpid ();
3646 postfork = 1; 3642 postfork = 1;
3647 } 3643 }
3648#endif 3644#endif
3649 3645
3650#if EV_FORK_ENABLE 3646#if EV_FORK_ENABLE
3651 /* we might have forked, so queue fork handlers */ 3647 /* we might have forked, so queue fork handlers */
3652 if (expect_false (postfork)) 3648 if (ecb_expect_false (postfork))
3653 if (forkcnt) 3649 if (forkcnt)
3654 { 3650 {
3655 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 3651 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
3656 EV_INVOKE_PENDING; 3652 EV_INVOKE_PENDING;
3657 } 3653 }
3658#endif 3654#endif
3659 3655
3660#if EV_PREPARE_ENABLE 3656#if EV_PREPARE_ENABLE
3661 /* queue prepare watchers (and execute them) */ 3657 /* queue prepare watchers (and execute them) */
3662 if (expect_false (preparecnt)) 3658 if (ecb_expect_false (preparecnt))
3663 { 3659 {
3664 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 3660 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
3665 EV_INVOKE_PENDING; 3661 EV_INVOKE_PENDING;
3666 } 3662 }
3667#endif 3663#endif
3668 3664
3669 if (expect_false (loop_done)) 3665 if (ecb_expect_false (loop_done))
3670 break; 3666 break;
3671 3667
3672 /* we might have forked, so reify kernel state if necessary */ 3668 /* we might have forked, so reify kernel state if necessary */
3673 if (expect_false (postfork)) 3669 if (ecb_expect_false (postfork))
3674 loop_fork (EV_A); 3670 loop_fork (EV_A);
3675 3671
3676 /* update fd-related kernel structures */ 3672 /* update fd-related kernel structures */
3677 fd_reify (EV_A); 3673 fd_reify (EV_A);
3678 3674
3690 /* from now on, we want a pipe-wake-up */ 3686 /* from now on, we want a pipe-wake-up */
3691 pipe_write_wanted = 1; 3687 pipe_write_wanted = 1;
3692 3688
3693 ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ 3689 ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */
3694 3690
3695 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 3691 if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
3696 { 3692 {
3697 waittime = MAX_BLOCKTIME; 3693 waittime = MAX_BLOCKTIME;
3698 3694
3699 if (timercnt) 3695 if (timercnt)
3700 { 3696 {
3709 if (waittime > to) waittime = to; 3705 if (waittime > to) waittime = to;
3710 } 3706 }
3711#endif 3707#endif
3712 3708
3713 /* don't let timeouts decrease the waittime below timeout_blocktime */ 3709 /* don't let timeouts decrease the waittime below timeout_blocktime */
3714 if (expect_false (waittime < timeout_blocktime)) 3710 if (ecb_expect_false (waittime < timeout_blocktime))
3715 waittime = timeout_blocktime; 3711 waittime = timeout_blocktime;
3716 3712
3717 /* at this point, we NEED to wait, so we have to ensure */ 3713 /* at this point, we NEED to wait, so we have to ensure */
3718 /* to pass a minimum nonzero value to the backend */ 3714 /* to pass a minimum nonzero value to the backend */
3719 if (expect_false (waittime < backend_mintime)) 3715 if (ecb_expect_false (waittime < backend_mintime))
3720 waittime = backend_mintime; 3716 waittime = backend_mintime;
3721 3717
3722 /* extra check because io_blocktime is commonly 0 */ 3718 /* extra check because io_blocktime is commonly 0 */
3723 if (expect_false (io_blocktime)) 3719 if (ecb_expect_false (io_blocktime))
3724 { 3720 {
3725 sleeptime = io_blocktime - (mn_now - prev_mn_now); 3721 sleeptime = io_blocktime - (mn_now - prev_mn_now);
3726 3722
3727 if (sleeptime > waittime - backend_mintime) 3723 if (sleeptime > waittime - backend_mintime)
3728 sleeptime = waittime - backend_mintime; 3724 sleeptime = waittime - backend_mintime;
3729 3725
3730 if (expect_true (sleeptime > 0.)) 3726 if (ecb_expect_true (sleeptime > 0.))
3731 { 3727 {
3732 ev_sleep (sleeptime); 3728 ev_sleep (sleeptime);
3733 waittime -= sleeptime; 3729 waittime -= sleeptime;
3734 } 3730 }
3735 } 3731 }
3749 { 3745 {
3750 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 3746 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
3751 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3747 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3752 } 3748 }
3753 3749
3754
3755 /* update ev_rt_now, do magic */ 3750 /* update ev_rt_now, do magic */
3756 time_update (EV_A_ waittime + sleeptime); 3751 time_update (EV_A_ waittime + sleeptime);
3757 } 3752 }
3758 3753
3759 /* queue pending timers and reschedule them */ 3754 /* queue pending timers and reschedule them */
3767 idle_reify (EV_A); 3762 idle_reify (EV_A);
3768#endif 3763#endif
3769 3764
3770#if EV_CHECK_ENABLE 3765#if EV_CHECK_ENABLE
3771 /* queue check watchers, to be executed first */ 3766 /* queue check watchers, to be executed first */
3772 if (expect_false (checkcnt)) 3767 if (ecb_expect_false (checkcnt))
3773 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 3768 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
3774#endif 3769#endif
3775 3770
3776 EV_INVOKE_PENDING; 3771 EV_INVOKE_PENDING;
3777 } 3772 }
3778 while (expect_true ( 3773 while (ecb_expect_true (
3779 activecnt 3774 activecnt
3780 && !loop_done 3775 && !loop_done
3781 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) 3776 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
3782 )); 3777 ));
3783 3778
3847inline_size void 3842inline_size void
3848wlist_del (WL *head, WL elem) 3843wlist_del (WL *head, WL elem)
3849{ 3844{
3850 while (*head) 3845 while (*head)
3851 { 3846 {
3852 if (expect_true (*head == elem)) 3847 if (ecb_expect_true (*head == elem))
3853 { 3848 {
3854 *head = elem->next; 3849 *head = elem->next;
3855 break; 3850 break;
3856 } 3851 }
3857 3852
3874ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT 3869ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3875{ 3870{
3876 W w_ = (W)w; 3871 W w_ = (W)w;
3877 int pending = w_->pending; 3872 int pending = w_->pending;
3878 3873
3879 if (expect_true (pending)) 3874 if (ecb_expect_true (pending))
3880 { 3875 {
3881 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; 3876 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
3882 p->w = (W)&pending_w; 3877 p->w = (W)&pending_w;
3883 w_->pending = 0; 3878 w_->pending = 0;
3884 return p->events; 3879 return p->events;
3911 w->active = 0; 3906 w->active = 0;
3912} 3907}
3913 3908
3914/*****************************************************************************/ 3909/*****************************************************************************/
3915 3910
3916noinline 3911ecb_noinline
3917void 3912void
3918ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT 3913ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3919{ 3914{
3920 int fd = w->fd; 3915 int fd = w->fd;
3921 3916
3922 if (expect_false (ev_is_active (w))) 3917 if (ecb_expect_false (ev_is_active (w)))
3923 return; 3918 return;
3924 3919
3925 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3920 assert (("libev: ev_io_start called with negative fd", fd >= 0));
3926 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3921 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3927 3922
3941 w->events &= ~EV__IOFDSET; 3936 w->events &= ~EV__IOFDSET;
3942 3937
3943 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3944} 3939}
3945 3940
3946noinline 3941ecb_noinline
3947void 3942void
3948ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT 3943ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3949{ 3944{
3950 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3951 if (expect_false (!ev_is_active (w))) 3946 if (ecb_expect_false (!ev_is_active (w)))
3952 return; 3947 return;
3953 3948
3954 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 3949 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
3955 3950
3956#if EV_VERIFY >= 2 3951#if EV_VERIFY >= 2
3964 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3959 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3965 3960
3966 EV_FREQUENT_CHECK; 3961 EV_FREQUENT_CHECK;
3967} 3962}
3968 3963
3969noinline 3964ecb_noinline
3970void 3965void
3971ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT 3966ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3972{ 3967{
3973 if (expect_false (ev_is_active (w))) 3968 if (ecb_expect_false (ev_is_active (w)))
3974 return; 3969 return;
3975 3970
3976 ev_at (w) += mn_now; 3971 ev_at (w) += mn_now;
3977 3972
3978 assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 3973 assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
3989 EV_FREQUENT_CHECK; 3984 EV_FREQUENT_CHECK;
3990 3985
3991 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3986 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3992} 3987}
3993 3988
3994noinline 3989ecb_noinline
3995void 3990void
3996ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT 3991ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3997{ 3992{
3998 clear_pending (EV_A_ (W)w); 3993 clear_pending (EV_A_ (W)w);
3999 if (expect_false (!ev_is_active (w))) 3994 if (ecb_expect_false (!ev_is_active (w)))
4000 return; 3995 return;
4001 3996
4002 EV_FREQUENT_CHECK; 3997 EV_FREQUENT_CHECK;
4003 3998
4004 { 3999 {
4006 4001
4007 assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); 4002 assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w));
4008 4003
4009 --timercnt; 4004 --timercnt;
4010 4005
4011 if (expect_true (active < timercnt + HEAP0)) 4006 if (ecb_expect_true (active < timercnt + HEAP0))
4012 { 4007 {
4013 timers [active] = timers [timercnt + HEAP0]; 4008 timers [active] = timers [timercnt + HEAP0];
4014 adjustheap (timers, timercnt, active); 4009 adjustheap (timers, timercnt, active);
4015 } 4010 }
4016 } 4011 }
4020 ev_stop (EV_A_ (W)w); 4015 ev_stop (EV_A_ (W)w);
4021 4016
4022 EV_FREQUENT_CHECK; 4017 EV_FREQUENT_CHECK;
4023} 4018}
4024 4019
4025noinline 4020ecb_noinline
4026void 4021void
4027ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT 4022ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
4028{ 4023{
4029 EV_FREQUENT_CHECK; 4024 EV_FREQUENT_CHECK;
4030 4025
4055{ 4050{
4056 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4051 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
4057} 4052}
4058 4053
4059#if EV_PERIODIC_ENABLE 4054#if EV_PERIODIC_ENABLE
4060noinline 4055ecb_noinline
4061void 4056void
4062ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT 4057ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4063{ 4058{
4064 if (expect_false (ev_is_active (w))) 4059 if (ecb_expect_false (ev_is_active (w)))
4065 return; 4060 return;
4066 4061
4067 if (w->reschedule_cb) 4062 if (w->reschedule_cb)
4068 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 4063 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
4069 else if (w->interval) 4064 else if (w->interval)
4086 EV_FREQUENT_CHECK; 4081 EV_FREQUENT_CHECK;
4087 4082
4088 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4083 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
4089} 4084}
4090 4085
4091noinline 4086ecb_noinline
4092void 4087void
4093ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT 4088ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4094{ 4089{
4095 clear_pending (EV_A_ (W)w); 4090 clear_pending (EV_A_ (W)w);
4096 if (expect_false (!ev_is_active (w))) 4091 if (ecb_expect_false (!ev_is_active (w)))
4097 return; 4092 return;
4098 4093
4099 EV_FREQUENT_CHECK; 4094 EV_FREQUENT_CHECK;
4100 4095
4101 { 4096 {
4103 4098
4104 assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); 4099 assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w));
4105 4100
4106 --periodiccnt; 4101 --periodiccnt;
4107 4102
4108 if (expect_true (active < periodiccnt + HEAP0)) 4103 if (ecb_expect_true (active < periodiccnt + HEAP0))
4109 { 4104 {
4110 periodics [active] = periodics [periodiccnt + HEAP0]; 4105 periodics [active] = periodics [periodiccnt + HEAP0];
4111 adjustheap (periodics, periodiccnt, active); 4106 adjustheap (periodics, periodiccnt, active);
4112 } 4107 }
4113 } 4108 }
4115 ev_stop (EV_A_ (W)w); 4110 ev_stop (EV_A_ (W)w);
4116 4111
4117 EV_FREQUENT_CHECK; 4112 EV_FREQUENT_CHECK;
4118} 4113}
4119 4114
4120noinline 4115ecb_noinline
4121void 4116void
4122ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT 4117ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4123{ 4118{
4124 /* TODO: use adjustheap and recalculation */ 4119 /* TODO: use adjustheap and recalculation */
4125 ev_periodic_stop (EV_A_ w); 4120 ev_periodic_stop (EV_A_ w);
4131# define SA_RESTART 0 4126# define SA_RESTART 0
4132#endif 4127#endif
4133 4128
4134#if EV_SIGNAL_ENABLE 4129#if EV_SIGNAL_ENABLE
4135 4130
4136noinline 4131ecb_noinline
4137void 4132void
4138ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT 4133ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4139{ 4134{
4140 if (expect_false (ev_is_active (w))) 4135 if (ecb_expect_false (ev_is_active (w)))
4141 return; 4136 return;
4142 4137
4143 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4138 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4144 4139
4145#if EV_MULTIPLICITY 4140#if EV_MULTIPLICITY
4214 } 4209 }
4215 4210
4216 EV_FREQUENT_CHECK; 4211 EV_FREQUENT_CHECK;
4217} 4212}
4218 4213
4219noinline 4214ecb_noinline
4220void 4215void
4221ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT 4216ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4222{ 4217{
4223 clear_pending (EV_A_ (W)w); 4218 clear_pending (EV_A_ (W)w);
4224 if (expect_false (!ev_is_active (w))) 4219 if (ecb_expect_false (!ev_is_active (w)))
4225 return; 4220 return;
4226 4221
4227 EV_FREQUENT_CHECK; 4222 EV_FREQUENT_CHECK;
4228 4223
4229 wlist_del (&signals [w->signum - 1].head, (WL)w); 4224 wlist_del (&signals [w->signum - 1].head, (WL)w);
4262ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT 4257ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4263{ 4258{
4264#if EV_MULTIPLICITY 4259#if EV_MULTIPLICITY
4265 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4260 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4266#endif 4261#endif
4267 if (expect_false (ev_is_active (w))) 4262 if (ecb_expect_false (ev_is_active (w)))
4268 return; 4263 return;
4269 4264
4270 EV_FREQUENT_CHECK; 4265 EV_FREQUENT_CHECK;
4271 4266
4272 ev_start (EV_A_ (W)w, 1); 4267 ev_start (EV_A_ (W)w, 1);
4277 4272
4278void 4273void
4279ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT 4274ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4280{ 4275{
4281 clear_pending (EV_A_ (W)w); 4276 clear_pending (EV_A_ (W)w);
4282 if (expect_false (!ev_is_active (w))) 4277 if (ecb_expect_false (!ev_is_active (w)))
4283 return; 4278 return;
4284 4279
4285 EV_FREQUENT_CHECK; 4280 EV_FREQUENT_CHECK;
4286 4281
4287 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); 4282 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
4301 4296
4302#define DEF_STAT_INTERVAL 5.0074891 4297#define DEF_STAT_INTERVAL 5.0074891
4303#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4298#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4304#define MIN_STAT_INTERVAL 0.1074891 4299#define MIN_STAT_INTERVAL 0.1074891
4305 4300
4306noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4301ecb_noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents);
4307 4302
4308#if EV_USE_INOTIFY 4303#if EV_USE_INOTIFY
4309 4304
4310/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ 4305/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */
4311# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 4306# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4312 4307
4313noinline 4308ecb_noinline
4314static void 4309static void
4315infy_add (EV_P_ ev_stat *w) 4310infy_add (EV_P_ ev_stat *w)
4316{ 4311{
4317 w->wd = inotify_add_watch (fs_fd, w->path, 4312 w->wd = inotify_add_watch (fs_fd, w->path,
4318 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4313 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4383 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4378 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4384 ev_timer_again (EV_A_ &w->timer); 4379 ev_timer_again (EV_A_ &w->timer);
4385 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4380 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4386} 4381}
4387 4382
4388noinline 4383ecb_noinline
4389static void 4384static void
4390infy_del (EV_P_ ev_stat *w) 4385infy_del (EV_P_ ev_stat *w)
4391{ 4386{
4392 int slot; 4387 int slot;
4393 int wd = w->wd; 4388 int wd = w->wd;
4401 4396
4402 /* remove this watcher, if others are watching it, they will rearm */ 4397 /* remove this watcher, if others are watching it, they will rearm */
4403 inotify_rm_watch (fs_fd, wd); 4398 inotify_rm_watch (fs_fd, wd);
4404} 4399}
4405 4400
4406noinline 4401ecb_noinline
4407static void 4402static void
4408infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4403infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4409{ 4404{
4410 if (slot < 0) 4405 if (slot < 0)
4411 /* overflow, need to check for all hash slots */ 4406 /* overflow, need to check for all hash slots */
4557 w->attr.st_nlink = 0; 4552 w->attr.st_nlink = 0;
4558 else if (!w->attr.st_nlink) 4553 else if (!w->attr.st_nlink)
4559 w->attr.st_nlink = 1; 4554 w->attr.st_nlink = 1;
4560} 4555}
4561 4556
4562noinline 4557ecb_noinline
4563static void 4558static void
4564stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4559stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4565{ 4560{
4566 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4561 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4567 4562
4601} 4596}
4602 4597
4603void 4598void
4604ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT 4599ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4605{ 4600{
4606 if (expect_false (ev_is_active (w))) 4601 if (ecb_expect_false (ev_is_active (w)))
4607 return; 4602 return;
4608 4603
4609 ev_stat_stat (EV_A_ w); 4604 ev_stat_stat (EV_A_ w);
4610 4605
4611 if (w->interval < MIN_STAT_INTERVAL && w->interval) 4606 if (w->interval < MIN_STAT_INTERVAL && w->interval)
4633 4628
4634void 4629void
4635ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT 4630ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4636{ 4631{
4637 clear_pending (EV_A_ (W)w); 4632 clear_pending (EV_A_ (W)w);
4638 if (expect_false (!ev_is_active (w))) 4633 if (ecb_expect_false (!ev_is_active (w)))
4639 return; 4634 return;
4640 4635
4641 EV_FREQUENT_CHECK; 4636 EV_FREQUENT_CHECK;
4642 4637
4643#if EV_USE_INOTIFY 4638#if EV_USE_INOTIFY
4658 4653
4659#if EV_IDLE_ENABLE 4654#if EV_IDLE_ENABLE
4660void 4655void
4661ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT 4656ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4662{ 4657{
4663 if (expect_false (ev_is_active (w))) 4658 if (ecb_expect_false (ev_is_active (w)))
4664 return; 4659 return;
4665 4660
4666 pri_adjust (EV_A_ (W)w); 4661 pri_adjust (EV_A_ (W)w);
4667 4662
4668 EV_FREQUENT_CHECK; 4663 EV_FREQUENT_CHECK;
4682 4677
4683void 4678void
4684ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT 4679ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4685{ 4680{
4686 clear_pending (EV_A_ (W)w); 4681 clear_pending (EV_A_ (W)w);
4687 if (expect_false (!ev_is_active (w))) 4682 if (ecb_expect_false (!ev_is_active (w)))
4688 return; 4683 return;
4689 4684
4690 EV_FREQUENT_CHECK; 4685 EV_FREQUENT_CHECK;
4691 4686
4692 { 4687 {
4705 4700
4706#if EV_PREPARE_ENABLE 4701#if EV_PREPARE_ENABLE
4707void 4702void
4708ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT 4703ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4709{ 4704{
4710 if (expect_false (ev_is_active (w))) 4705 if (ecb_expect_false (ev_is_active (w)))
4711 return; 4706 return;
4712 4707
4713 EV_FREQUENT_CHECK; 4708 EV_FREQUENT_CHECK;
4714 4709
4715 ev_start (EV_A_ (W)w, ++preparecnt); 4710 ev_start (EV_A_ (W)w, ++preparecnt);
4721 4716
4722void 4717void
4723ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT 4718ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4724{ 4719{
4725 clear_pending (EV_A_ (W)w); 4720 clear_pending (EV_A_ (W)w);
4726 if (expect_false (!ev_is_active (w))) 4721 if (ecb_expect_false (!ev_is_active (w)))
4727 return; 4722 return;
4728 4723
4729 EV_FREQUENT_CHECK; 4724 EV_FREQUENT_CHECK;
4730 4725
4731 { 4726 {
4743 4738
4744#if EV_CHECK_ENABLE 4739#if EV_CHECK_ENABLE
4745void 4740void
4746ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT 4741ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4747{ 4742{
4748 if (expect_false (ev_is_active (w))) 4743 if (ecb_expect_false (ev_is_active (w)))
4749 return; 4744 return;
4750 4745
4751 EV_FREQUENT_CHECK; 4746 EV_FREQUENT_CHECK;
4752 4747
4753 ev_start (EV_A_ (W)w, ++checkcnt); 4748 ev_start (EV_A_ (W)w, ++checkcnt);
4759 4754
4760void 4755void
4761ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT 4756ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4762{ 4757{
4763 clear_pending (EV_A_ (W)w); 4758 clear_pending (EV_A_ (W)w);
4764 if (expect_false (!ev_is_active (w))) 4759 if (ecb_expect_false (!ev_is_active (w)))
4765 return; 4760 return;
4766 4761
4767 EV_FREQUENT_CHECK; 4762 EV_FREQUENT_CHECK;
4768 4763
4769 { 4764 {
4778 EV_FREQUENT_CHECK; 4773 EV_FREQUENT_CHECK;
4779} 4774}
4780#endif 4775#endif
4781 4776
4782#if EV_EMBED_ENABLE 4777#if EV_EMBED_ENABLE
4783noinline 4778ecb_noinline
4784void 4779void
4785ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT 4780ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4786{ 4781{
4787 ev_run (w->other, EVRUN_NOWAIT); 4782 ev_run (w->other, EVRUN_NOWAIT);
4788} 4783}
4840#endif 4835#endif
4841 4836
4842void 4837void
4843ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT 4838ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4844{ 4839{
4845 if (expect_false (ev_is_active (w))) 4840 if (ecb_expect_false (ev_is_active (w)))
4846 return; 4841 return;
4847 4842
4848 { 4843 {
4849 EV_P = w->other; 4844 EV_P = w->other;
4850 assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); 4845 assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
4872 4867
4873void 4868void
4874ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT 4869ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4875{ 4870{
4876 clear_pending (EV_A_ (W)w); 4871 clear_pending (EV_A_ (W)w);
4877 if (expect_false (!ev_is_active (w))) 4872 if (ecb_expect_false (!ev_is_active (w)))
4878 return; 4873 return;
4879 4874
4880 EV_FREQUENT_CHECK; 4875 EV_FREQUENT_CHECK;
4881 4876
4882 ev_io_stop (EV_A_ &w->io); 4877 ev_io_stop (EV_A_ &w->io);
4891 4886
4892#if EV_FORK_ENABLE 4887#if EV_FORK_ENABLE
4893void 4888void
4894ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT 4889ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4895{ 4890{
4896 if (expect_false (ev_is_active (w))) 4891 if (ecb_expect_false (ev_is_active (w)))
4897 return; 4892 return;
4898 4893
4899 EV_FREQUENT_CHECK; 4894 EV_FREQUENT_CHECK;
4900 4895
4901 ev_start (EV_A_ (W)w, ++forkcnt); 4896 ev_start (EV_A_ (W)w, ++forkcnt);
4907 4902
4908void 4903void
4909ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT 4904ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4910{ 4905{
4911 clear_pending (EV_A_ (W)w); 4906 clear_pending (EV_A_ (W)w);
4912 if (expect_false (!ev_is_active (w))) 4907 if (ecb_expect_false (!ev_is_active (w)))
4913 return; 4908 return;
4914 4909
4915 EV_FREQUENT_CHECK; 4910 EV_FREQUENT_CHECK;
4916 4911
4917 { 4912 {
4929 4924
4930#if EV_CLEANUP_ENABLE 4925#if EV_CLEANUP_ENABLE
4931void 4926void
4932ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4927ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4933{ 4928{
4934 if (expect_false (ev_is_active (w))) 4929 if (ecb_expect_false (ev_is_active (w)))
4935 return; 4930 return;
4936 4931
4937 EV_FREQUENT_CHECK; 4932 EV_FREQUENT_CHECK;
4938 4933
4939 ev_start (EV_A_ (W)w, ++cleanupcnt); 4934 ev_start (EV_A_ (W)w, ++cleanupcnt);
4947 4942
4948void 4943void
4949ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4944ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4950{ 4945{
4951 clear_pending (EV_A_ (W)w); 4946 clear_pending (EV_A_ (W)w);
4952 if (expect_false (!ev_is_active (w))) 4947 if (ecb_expect_false (!ev_is_active (w)))
4953 return; 4948 return;
4954 4949
4955 EV_FREQUENT_CHECK; 4950 EV_FREQUENT_CHECK;
4956 ev_ref (EV_A); 4951 ev_ref (EV_A);
4957 4952
4970 4965
4971#if EV_ASYNC_ENABLE 4966#if EV_ASYNC_ENABLE
4972void 4967void
4973ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT 4968ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4974{ 4969{
4975 if (expect_false (ev_is_active (w))) 4970 if (ecb_expect_false (ev_is_active (w)))
4976 return; 4971 return;
4977 4972
4978 w->sent = 0; 4973 w->sent = 0;
4979 4974
4980 evpipe_init (EV_A); 4975 evpipe_init (EV_A);
4990 4985
4991void 4986void
4992ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT 4987ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4993{ 4988{
4994 clear_pending (EV_A_ (W)w); 4989 clear_pending (EV_A_ (W)w);
4995 if (expect_false (!ev_is_active (w))) 4990 if (ecb_expect_false (!ev_is_active (w)))
4996 return; 4991 return;
4997 4992
4998 EV_FREQUENT_CHECK; 4993 EV_FREQUENT_CHECK;
4999 4994
5000 { 4995 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines