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

Comparing libev/ev.c (file contents):
Revision 1.497 by root, Tue Jun 25 04:52:30 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
3923#if EV_VERIFY >= 2
3924 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3925#endif
3928 EV_FREQUENT_CHECK; 3926 EV_FREQUENT_CHECK;
3929 3927
3930 ev_start (EV_A_ (W)w, 1); 3928 ev_start (EV_A_ (W)w, 1);
3931 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); 3929 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3932 wlist_add (&anfds[fd].head, (WL)w); 3930 wlist_add (&anfds[fd].head, (WL)w);
3938 w->events &= ~EV__IOFDSET; 3936 w->events &= ~EV__IOFDSET;
3939 3937
3940 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3941} 3939}
3942 3940
3943noinline 3941ecb_noinline
3944void 3942void
3945ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT 3943ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3946{ 3944{
3947 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3948 if (expect_false (!ev_is_active (w))) 3946 if (ecb_expect_false (!ev_is_active (w)))
3949 return; 3947 return;
3950 3948
3951 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));
3952 3950
3951#if EV_VERIFY >= 2
3952 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3953#endif
3953 EV_FREQUENT_CHECK; 3954 EV_FREQUENT_CHECK;
3954 3955
3955 wlist_del (&anfds[w->fd].head, (WL)w); 3956 wlist_del (&anfds[w->fd].head, (WL)w);
3956 ev_stop (EV_A_ (W)w); 3957 ev_stop (EV_A_ (W)w);
3957 3958
3958 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3959 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3959 3960
3960 EV_FREQUENT_CHECK; 3961 EV_FREQUENT_CHECK;
3961} 3962}
3962 3963
3963noinline 3964ecb_noinline
3964void 3965void
3965ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT 3966ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3966{ 3967{
3967 if (expect_false (ev_is_active (w))) 3968 if (ecb_expect_false (ev_is_active (w)))
3968 return; 3969 return;
3969 3970
3970 ev_at (w) += mn_now; 3971 ev_at (w) += mn_now;
3971 3972
3972 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.));
3983 EV_FREQUENT_CHECK; 3984 EV_FREQUENT_CHECK;
3984 3985
3985 /*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));*/
3986} 3987}
3987 3988
3988noinline 3989ecb_noinline
3989void 3990void
3990ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT 3991ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3991{ 3992{
3992 clear_pending (EV_A_ (W)w); 3993 clear_pending (EV_A_ (W)w);
3993 if (expect_false (!ev_is_active (w))) 3994 if (ecb_expect_false (!ev_is_active (w)))
3994 return; 3995 return;
3995 3996
3996 EV_FREQUENT_CHECK; 3997 EV_FREQUENT_CHECK;
3997 3998
3998 { 3999 {
4000 4001
4001 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));
4002 4003
4003 --timercnt; 4004 --timercnt;
4004 4005
4005 if (expect_true (active < timercnt + HEAP0)) 4006 if (ecb_expect_true (active < timercnt + HEAP0))
4006 { 4007 {
4007 timers [active] = timers [timercnt + HEAP0]; 4008 timers [active] = timers [timercnt + HEAP0];
4008 adjustheap (timers, timercnt, active); 4009 adjustheap (timers, timercnt, active);
4009 } 4010 }
4010 } 4011 }
4014 ev_stop (EV_A_ (W)w); 4015 ev_stop (EV_A_ (W)w);
4015 4016
4016 EV_FREQUENT_CHECK; 4017 EV_FREQUENT_CHECK;
4017} 4018}
4018 4019
4019noinline 4020ecb_noinline
4020void 4021void
4021ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT 4022ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
4022{ 4023{
4023 EV_FREQUENT_CHECK; 4024 EV_FREQUENT_CHECK;
4024 4025
4049{ 4050{
4050 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4051 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
4051} 4052}
4052 4053
4053#if EV_PERIODIC_ENABLE 4054#if EV_PERIODIC_ENABLE
4054noinline 4055ecb_noinline
4055void 4056void
4056ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT 4057ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4057{ 4058{
4058 if (expect_false (ev_is_active (w))) 4059 if (ecb_expect_false (ev_is_active (w)))
4059 return; 4060 return;
4060 4061
4061 if (w->reschedule_cb) 4062 if (w->reschedule_cb)
4062 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 4063 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
4063 else if (w->interval) 4064 else if (w->interval)
4080 EV_FREQUENT_CHECK; 4081 EV_FREQUENT_CHECK;
4081 4082
4082 /*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));*/
4083} 4084}
4084 4085
4085noinline 4086ecb_noinline
4086void 4087void
4087ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT 4088ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4088{ 4089{
4089 clear_pending (EV_A_ (W)w); 4090 clear_pending (EV_A_ (W)w);
4090 if (expect_false (!ev_is_active (w))) 4091 if (ecb_expect_false (!ev_is_active (w)))
4091 return; 4092 return;
4092 4093
4093 EV_FREQUENT_CHECK; 4094 EV_FREQUENT_CHECK;
4094 4095
4095 { 4096 {
4097 4098
4098 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));
4099 4100
4100 --periodiccnt; 4101 --periodiccnt;
4101 4102
4102 if (expect_true (active < periodiccnt + HEAP0)) 4103 if (ecb_expect_true (active < periodiccnt + HEAP0))
4103 { 4104 {
4104 periodics [active] = periodics [periodiccnt + HEAP0]; 4105 periodics [active] = periodics [periodiccnt + HEAP0];
4105 adjustheap (periodics, periodiccnt, active); 4106 adjustheap (periodics, periodiccnt, active);
4106 } 4107 }
4107 } 4108 }
4109 ev_stop (EV_A_ (W)w); 4110 ev_stop (EV_A_ (W)w);
4110 4111
4111 EV_FREQUENT_CHECK; 4112 EV_FREQUENT_CHECK;
4112} 4113}
4113 4114
4114noinline 4115ecb_noinline
4115void 4116void
4116ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT 4117ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4117{ 4118{
4118 /* TODO: use adjustheap and recalculation */ 4119 /* TODO: use adjustheap and recalculation */
4119 ev_periodic_stop (EV_A_ w); 4120 ev_periodic_stop (EV_A_ w);
4125# define SA_RESTART 0 4126# define SA_RESTART 0
4126#endif 4127#endif
4127 4128
4128#if EV_SIGNAL_ENABLE 4129#if EV_SIGNAL_ENABLE
4129 4130
4130noinline 4131ecb_noinline
4131void 4132void
4132ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT 4133ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4133{ 4134{
4134 if (expect_false (ev_is_active (w))) 4135 if (ecb_expect_false (ev_is_active (w)))
4135 return; 4136 return;
4136 4137
4137 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));
4138 4139
4139#if EV_MULTIPLICITY 4140#if EV_MULTIPLICITY
4208 } 4209 }
4209 4210
4210 EV_FREQUENT_CHECK; 4211 EV_FREQUENT_CHECK;
4211} 4212}
4212 4213
4213noinline 4214ecb_noinline
4214void 4215void
4215ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT 4216ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4216{ 4217{
4217 clear_pending (EV_A_ (W)w); 4218 clear_pending (EV_A_ (W)w);
4218 if (expect_false (!ev_is_active (w))) 4219 if (ecb_expect_false (!ev_is_active (w)))
4219 return; 4220 return;
4220 4221
4221 EV_FREQUENT_CHECK; 4222 EV_FREQUENT_CHECK;
4222 4223
4223 wlist_del (&signals [w->signum - 1].head, (WL)w); 4224 wlist_del (&signals [w->signum - 1].head, (WL)w);
4256ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT 4257ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4257{ 4258{
4258#if EV_MULTIPLICITY 4259#if EV_MULTIPLICITY
4259 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));
4260#endif 4261#endif
4261 if (expect_false (ev_is_active (w))) 4262 if (ecb_expect_false (ev_is_active (w)))
4262 return; 4263 return;
4263 4264
4264 EV_FREQUENT_CHECK; 4265 EV_FREQUENT_CHECK;
4265 4266
4266 ev_start (EV_A_ (W)w, 1); 4267 ev_start (EV_A_ (W)w, 1);
4271 4272
4272void 4273void
4273ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT 4274ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4274{ 4275{
4275 clear_pending (EV_A_ (W)w); 4276 clear_pending (EV_A_ (W)w);
4276 if (expect_false (!ev_is_active (w))) 4277 if (ecb_expect_false (!ev_is_active (w)))
4277 return; 4278 return;
4278 4279
4279 EV_FREQUENT_CHECK; 4280 EV_FREQUENT_CHECK;
4280 4281
4281 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); 4282 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
4295 4296
4296#define DEF_STAT_INTERVAL 5.0074891 4297#define DEF_STAT_INTERVAL 5.0074891
4297#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4298#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4298#define MIN_STAT_INTERVAL 0.1074891 4299#define MIN_STAT_INTERVAL 0.1074891
4299 4300
4300noinline 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);
4301 4302
4302#if EV_USE_INOTIFY 4303#if EV_USE_INOTIFY
4303 4304
4304/* 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 */
4305# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 4306# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4306 4307
4307noinline 4308ecb_noinline
4308static void 4309static void
4309infy_add (EV_P_ ev_stat *w) 4310infy_add (EV_P_ ev_stat *w)
4310{ 4311{
4311 w->wd = inotify_add_watch (fs_fd, w->path, 4312 w->wd = inotify_add_watch (fs_fd, w->path,
4312 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4313 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4377 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4378 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4378 ev_timer_again (EV_A_ &w->timer); 4379 ev_timer_again (EV_A_ &w->timer);
4379 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4380 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4380} 4381}
4381 4382
4382noinline 4383ecb_noinline
4383static void 4384static void
4384infy_del (EV_P_ ev_stat *w) 4385infy_del (EV_P_ ev_stat *w)
4385{ 4386{
4386 int slot; 4387 int slot;
4387 int wd = w->wd; 4388 int wd = w->wd;
4395 4396
4396 /* remove this watcher, if others are watching it, they will rearm */ 4397 /* remove this watcher, if others are watching it, they will rearm */
4397 inotify_rm_watch (fs_fd, wd); 4398 inotify_rm_watch (fs_fd, wd);
4398} 4399}
4399 4400
4400noinline 4401ecb_noinline
4401static void 4402static void
4402infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4403infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4403{ 4404{
4404 if (slot < 0) 4405 if (slot < 0)
4405 /* overflow, need to check for all hash slots */ 4406 /* overflow, need to check for all hash slots */
4551 w->attr.st_nlink = 0; 4552 w->attr.st_nlink = 0;
4552 else if (!w->attr.st_nlink) 4553 else if (!w->attr.st_nlink)
4553 w->attr.st_nlink = 1; 4554 w->attr.st_nlink = 1;
4554} 4555}
4555 4556
4556noinline 4557ecb_noinline
4557static void 4558static void
4558stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4559stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4559{ 4560{
4560 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4561 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4561 4562
4595} 4596}
4596 4597
4597void 4598void
4598ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT 4599ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4599{ 4600{
4600 if (expect_false (ev_is_active (w))) 4601 if (ecb_expect_false (ev_is_active (w)))
4601 return; 4602 return;
4602 4603
4603 ev_stat_stat (EV_A_ w); 4604 ev_stat_stat (EV_A_ w);
4604 4605
4605 if (w->interval < MIN_STAT_INTERVAL && w->interval) 4606 if (w->interval < MIN_STAT_INTERVAL && w->interval)
4627 4628
4628void 4629void
4629ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT 4630ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4630{ 4631{
4631 clear_pending (EV_A_ (W)w); 4632 clear_pending (EV_A_ (W)w);
4632 if (expect_false (!ev_is_active (w))) 4633 if (ecb_expect_false (!ev_is_active (w)))
4633 return; 4634 return;
4634 4635
4635 EV_FREQUENT_CHECK; 4636 EV_FREQUENT_CHECK;
4636 4637
4637#if EV_USE_INOTIFY 4638#if EV_USE_INOTIFY
4652 4653
4653#if EV_IDLE_ENABLE 4654#if EV_IDLE_ENABLE
4654void 4655void
4655ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT 4656ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4656{ 4657{
4657 if (expect_false (ev_is_active (w))) 4658 if (ecb_expect_false (ev_is_active (w)))
4658 return; 4659 return;
4659 4660
4660 pri_adjust (EV_A_ (W)w); 4661 pri_adjust (EV_A_ (W)w);
4661 4662
4662 EV_FREQUENT_CHECK; 4663 EV_FREQUENT_CHECK;
4676 4677
4677void 4678void
4678ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT 4679ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4679{ 4680{
4680 clear_pending (EV_A_ (W)w); 4681 clear_pending (EV_A_ (W)w);
4681 if (expect_false (!ev_is_active (w))) 4682 if (ecb_expect_false (!ev_is_active (w)))
4682 return; 4683 return;
4683 4684
4684 EV_FREQUENT_CHECK; 4685 EV_FREQUENT_CHECK;
4685 4686
4686 { 4687 {
4699 4700
4700#if EV_PREPARE_ENABLE 4701#if EV_PREPARE_ENABLE
4701void 4702void
4702ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT 4703ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4703{ 4704{
4704 if (expect_false (ev_is_active (w))) 4705 if (ecb_expect_false (ev_is_active (w)))
4705 return; 4706 return;
4706 4707
4707 EV_FREQUENT_CHECK; 4708 EV_FREQUENT_CHECK;
4708 4709
4709 ev_start (EV_A_ (W)w, ++preparecnt); 4710 ev_start (EV_A_ (W)w, ++preparecnt);
4715 4716
4716void 4717void
4717ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT 4718ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4718{ 4719{
4719 clear_pending (EV_A_ (W)w); 4720 clear_pending (EV_A_ (W)w);
4720 if (expect_false (!ev_is_active (w))) 4721 if (ecb_expect_false (!ev_is_active (w)))
4721 return; 4722 return;
4722 4723
4723 EV_FREQUENT_CHECK; 4724 EV_FREQUENT_CHECK;
4724 4725
4725 { 4726 {
4737 4738
4738#if EV_CHECK_ENABLE 4739#if EV_CHECK_ENABLE
4739void 4740void
4740ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT 4741ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4741{ 4742{
4742 if (expect_false (ev_is_active (w))) 4743 if (ecb_expect_false (ev_is_active (w)))
4743 return; 4744 return;
4744 4745
4745 EV_FREQUENT_CHECK; 4746 EV_FREQUENT_CHECK;
4746 4747
4747 ev_start (EV_A_ (W)w, ++checkcnt); 4748 ev_start (EV_A_ (W)w, ++checkcnt);
4753 4754
4754void 4755void
4755ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT 4756ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4756{ 4757{
4757 clear_pending (EV_A_ (W)w); 4758 clear_pending (EV_A_ (W)w);
4758 if (expect_false (!ev_is_active (w))) 4759 if (ecb_expect_false (!ev_is_active (w)))
4759 return; 4760 return;
4760 4761
4761 EV_FREQUENT_CHECK; 4762 EV_FREQUENT_CHECK;
4762 4763
4763 { 4764 {
4772 EV_FREQUENT_CHECK; 4773 EV_FREQUENT_CHECK;
4773} 4774}
4774#endif 4775#endif
4775 4776
4776#if EV_EMBED_ENABLE 4777#if EV_EMBED_ENABLE
4777noinline 4778ecb_noinline
4778void 4779void
4779ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT 4780ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4780{ 4781{
4781 ev_run (w->other, EVRUN_NOWAIT); 4782 ev_run (w->other, EVRUN_NOWAIT);
4782} 4783}
4834#endif 4835#endif
4835 4836
4836void 4837void
4837ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT 4838ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4838{ 4839{
4839 if (expect_false (ev_is_active (w))) 4840 if (ecb_expect_false (ev_is_active (w)))
4840 return; 4841 return;
4841 4842
4842 { 4843 {
4843 EV_P = w->other; 4844 EV_P = w->other;
4844 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 ()));
4866 4867
4867void 4868void
4868ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT 4869ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4869{ 4870{
4870 clear_pending (EV_A_ (W)w); 4871 clear_pending (EV_A_ (W)w);
4871 if (expect_false (!ev_is_active (w))) 4872 if (ecb_expect_false (!ev_is_active (w)))
4872 return; 4873 return;
4873 4874
4874 EV_FREQUENT_CHECK; 4875 EV_FREQUENT_CHECK;
4875 4876
4876 ev_io_stop (EV_A_ &w->io); 4877 ev_io_stop (EV_A_ &w->io);
4885 4886
4886#if EV_FORK_ENABLE 4887#if EV_FORK_ENABLE
4887void 4888void
4888ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT 4889ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4889{ 4890{
4890 if (expect_false (ev_is_active (w))) 4891 if (ecb_expect_false (ev_is_active (w)))
4891 return; 4892 return;
4892 4893
4893 EV_FREQUENT_CHECK; 4894 EV_FREQUENT_CHECK;
4894 4895
4895 ev_start (EV_A_ (W)w, ++forkcnt); 4896 ev_start (EV_A_ (W)w, ++forkcnt);
4901 4902
4902void 4903void
4903ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT 4904ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4904{ 4905{
4905 clear_pending (EV_A_ (W)w); 4906 clear_pending (EV_A_ (W)w);
4906 if (expect_false (!ev_is_active (w))) 4907 if (ecb_expect_false (!ev_is_active (w)))
4907 return; 4908 return;
4908 4909
4909 EV_FREQUENT_CHECK; 4910 EV_FREQUENT_CHECK;
4910 4911
4911 { 4912 {
4923 4924
4924#if EV_CLEANUP_ENABLE 4925#if EV_CLEANUP_ENABLE
4925void 4926void
4926ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4927ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4927{ 4928{
4928 if (expect_false (ev_is_active (w))) 4929 if (ecb_expect_false (ev_is_active (w)))
4929 return; 4930 return;
4930 4931
4931 EV_FREQUENT_CHECK; 4932 EV_FREQUENT_CHECK;
4932 4933
4933 ev_start (EV_A_ (W)w, ++cleanupcnt); 4934 ev_start (EV_A_ (W)w, ++cleanupcnt);
4941 4942
4942void 4943void
4943ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4944ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4944{ 4945{
4945 clear_pending (EV_A_ (W)w); 4946 clear_pending (EV_A_ (W)w);
4946 if (expect_false (!ev_is_active (w))) 4947 if (ecb_expect_false (!ev_is_active (w)))
4947 return; 4948 return;
4948 4949
4949 EV_FREQUENT_CHECK; 4950 EV_FREQUENT_CHECK;
4950 ev_ref (EV_A); 4951 ev_ref (EV_A);
4951 4952
4964 4965
4965#if EV_ASYNC_ENABLE 4966#if EV_ASYNC_ENABLE
4966void 4967void
4967ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT 4968ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4968{ 4969{
4969 if (expect_false (ev_is_active (w))) 4970 if (ecb_expect_false (ev_is_active (w)))
4970 return; 4971 return;
4971 4972
4972 w->sent = 0; 4973 w->sent = 0;
4973 4974
4974 evpipe_init (EV_A); 4975 evpipe_init (EV_A);
4984 4985
4985void 4986void
4986ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT 4987ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4987{ 4988{
4988 clear_pending (EV_A_ (W)w); 4989 clear_pending (EV_A_ (W)w);
4989 if (expect_false (!ev_is_active (w))) 4990 if (ecb_expect_false (!ev_is_active (w)))
4990 return; 4991 return;
4991 4992
4992 EV_FREQUENT_CHECK; 4993 EV_FREQUENT_CHECK;
4993 4994
4994 { 4995 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines