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

Comparing libev/ev.c (file contents):
Revision 1.492 by root, Sat Jun 22 16:25:53 2019 UTC vs.
Revision 1.500 by root, Mon Jul 1 20:47:37 2019 UTC

398/* AIX has a completely broken poll.h header */ 398/* AIX has a completely broken poll.h header */
399# undef EV_USE_POLL 399# undef EV_USE_POLL
400# define EV_USE_POLL 0 400# define EV_USE_POLL 0
401#endif 401#endif
402 402
403#if EV_USE_LINUXAIO
404# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
405#endif
406
407/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 403/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
408/* which makes programs even slower. might work on other unices, too. */ 404/* which makes programs even slower. might work on other unices, too. */
409#if EV_USE_CLOCK_SYSCALL 405#if EV_USE_CLOCK_SYSCALL
410# include <sys/syscall.h> 406# include <sys/syscall.h>
411# ifdef SYS_clock_gettime 407# ifdef SYS_clock_gettime
442# endif 438# endif
443#endif 439#endif
444 440
445#if EV_USE_LINUXAIO 441#if EV_USE_LINUXAIO
446# include <sys/syscall.h> 442# include <sys/syscall.h>
447# if !SYS_io_getevents 443# if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */
448# undef EV_USE_LINUXAIO 444# undef EV_USE_LINUXAIO
449# define EV_USE_LINUXAIO 0 445# define EV_USE_LINUXAIO 0
450# endif 446# endif
451#endif 447#endif
452 448
563 559
564#ifndef ECB_H 560#ifndef ECB_H
565#define ECB_H 561#define ECB_H
566 562
567/* 16 bits major, 16 bits minor */ 563/* 16 bits major, 16 bits minor */
568#define ECB_VERSION 0x00010005 564#define ECB_VERSION 0x00010006
569 565
570#ifdef _WIN32 566#ifdef _WIN32
571 typedef signed char int8_t; 567 typedef signed char int8_t;
572 typedef unsigned char uint8_t; 568 typedef unsigned char uint8_t;
573 typedef signed short int16_t; 569 typedef signed short int16_t;
687 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 683 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
688#endif 684#endif
689 685
690#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
691 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 687 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
688 #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory")
692 #if __i386 || __i386__ 689 #if __i386 || __i386__
693 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 690 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
694 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 691 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
695 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") 692 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
696 #elif ECB_GCC_AMD64 693 #elif ECB_GCC_AMD64
746 #if ECB_GCC_VERSION(4,7) 743 #if ECB_GCC_VERSION(4,7)
747 /* see comment below (stdatomic.h) about the C11 memory model. */ 744 /* see comment below (stdatomic.h) about the C11 memory model. */
748 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 745 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
749 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 746 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
750 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) 747 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
748 #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED)
751 749
752 #elif ECB_CLANG_EXTENSION(c_atomic) 750 #elif ECB_CLANG_EXTENSION(c_atomic)
753 /* see comment below (stdatomic.h) about the C11 memory model. */ 751 /* see comment below (stdatomic.h) about the C11 memory model. */
754 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 752 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
755 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 753 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
756 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) 754 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
755 #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED)
757 756
758 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 757 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
759 #define ECB_MEMORY_FENCE __sync_synchronize () 758 #define ECB_MEMORY_FENCE __sync_synchronize ()
760 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 759 #elif _MSC_VER >= 1500 /* VC++ 2008 */
761 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ 760 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */
771 #elif defined _WIN32 770 #elif defined _WIN32
772 #include <WinNT.h> 771 #include <WinNT.h>
773 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 772 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
774 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 773 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
775 #include <mbarrier.h> 774 #include <mbarrier.h>
776 #define ECB_MEMORY_FENCE __machine_rw_barrier () 775 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
777 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 776 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
778 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () 777 #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier ()
778 #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier ()
779 #elif __xlC__ 779 #elif __xlC__
780 #define ECB_MEMORY_FENCE __sync () 780 #define ECB_MEMORY_FENCE __sync ()
781 #endif 781 #endif
782#endif 782#endif
783 783
784#ifndef ECB_MEMORY_FENCE 784#ifndef ECB_MEMORY_FENCE
785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
786 /* we assume that these memory fences work on all variables/all memory accesses, */ 786 /* we assume that these memory fences work on all variables/all memory accesses, */
787 /* not just C11 atomics and atomic accesses */ 787 /* not just C11 atomics and atomic accesses */
788 #include <stdatomic.h> 788 #include <stdatomic.h>
789 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
790 /* any fence other than seq_cst, which isn't very efficient for us. */
791 /* Why that is, we don't know - either the C11 memory model is quite useless */
792 /* for most usages, or gcc and clang have a bug */
793 /* I *currently* lean towards the latter, and inefficiently implement */
794 /* all three of ecb's fences as a seq_cst fence */
795 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
796 /* for all __atomic_thread_fence's except seq_cst */
797 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) 789 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
790 #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire)
791 #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release)
798 #endif 792 #endif
799#endif 793#endif
800 794
801#ifndef ECB_MEMORY_FENCE 795#ifndef ECB_MEMORY_FENCE
802 #if !ECB_AVOID_PTHREADS 796 #if !ECB_AVOID_PTHREADS
820 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 814 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
821#endif 815#endif
822 816
823#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 817#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
824 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 818 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
819#endif
820
821#if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE
822 #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */
825#endif 823#endif
826 824
827/*****************************************************************************/ 825/*****************************************************************************/
828 826
829#if ECB_CPP 827#if ECB_CPP
1538/* ECB.H END */ 1536/* ECB.H END */
1539 1537
1540#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 1538#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
1541/* 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
1542 * 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
1543 * 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
1544 * libev, in which cases the memory fences become nops. 1542 * libev, in which cases the memory fences become nops.
1545 * alternatively, you can remove this #error and link against libpthread, 1543 * alternatively, you can remove this #error and link against libpthread,
1546 * which will then provide the memory fences. 1544 * which will then provide the memory fences.
1547 */ 1545 */
1548# error "memory fences not defined for your architecture, please report" 1546# error "memory fences not defined for your architecture, please report"
1552# define ECB_MEMORY_FENCE do { } while (0) 1550# define ECB_MEMORY_FENCE do { } while (0)
1553# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 1551# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
1554# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 1552# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
1555#endif 1553#endif
1556 1554
1557#define expect_false(cond) ecb_expect_false (cond)
1558#define expect_true(cond) ecb_expect_true (cond)
1559#define noinline ecb_noinline
1560
1561#define inline_size ecb_inline 1555#define inline_size ecb_inline
1562 1556
1563#if EV_FEATURE_CODE 1557#if EV_FEATURE_CODE
1564# define inline_speed ecb_inline 1558# define inline_speed ecb_inline
1565#else 1559#else
1566# define inline_speed noinline static 1560# define inline_speed ecb_noinline static
1567#endif 1561#endif
1568 1562
1569#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 1563#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
1570 1564
1571#if EV_MINPRI == EV_MAXPRI 1565#if EV_MINPRI == EV_MAXPRI
1607# include "ev_win32.c" 1601# include "ev_win32.c"
1608#endif 1602#endif
1609 1603
1610/*****************************************************************************/ 1604/*****************************************************************************/
1611 1605
1606#if EV_USE_LINUXAIO
1607# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1608#endif
1609
1612/* define a suitable floor function (only used by periodics atm) */ 1610/* define a suitable floor function (only used by periodics atm) */
1613 1611
1614#if EV_USE_FLOOR 1612#if EV_USE_FLOOR
1615# include <math.h> 1613# include <math.h>
1616# define ev_floor(v) floor (v) 1614# define ev_floor(v) floor (v)
1617#else 1615#else
1618 1616
1619#include <float.h> 1617#include <float.h>
1620 1618
1621/* a floor() replacement function, should be independent of ev_tstamp type */ 1619/* a floor() replacement function, should be independent of ev_tstamp type */
1622noinline 1620ecb_noinline
1623static ev_tstamp 1621static ev_tstamp
1624ev_floor (ev_tstamp v) 1622ev_floor (ev_tstamp v)
1625{ 1623{
1626 /* the choice of shift factor is not terribly important */ 1624 /* the choice of shift factor is not terribly important */
1627#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ 1625#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */
1629#else 1627#else
1630 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; 1628 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.;
1631#endif 1629#endif
1632 1630
1633 /* argument too large for an unsigned long? */ 1631 /* argument too large for an unsigned long? */
1634 if (expect_false (v >= shift)) 1632 if (ecb_expect_false (v >= shift))
1635 { 1633 {
1636 ev_tstamp f; 1634 ev_tstamp f;
1637 1635
1638 if (v == v - 1.) 1636 if (v == v - 1.)
1639 return v; /* very large number */ 1637 return v; /* very large number */
1641 f = shift * ev_floor (v * (1. / shift)); 1639 f = shift * ev_floor (v * (1. / shift));
1642 return f + ev_floor (v - f); 1640 return f + ev_floor (v - f);
1643 } 1641 }
1644 1642
1645 /* special treatment for negative args? */ 1643 /* special treatment for negative args? */
1646 if (expect_false (v < 0.)) 1644 if (ecb_expect_false (v < 0.))
1647 { 1645 {
1648 ev_tstamp f = -ev_floor (-v); 1646 ev_tstamp f = -ev_floor (-v);
1649 1647
1650 return f - (f == v ? 0 : 1); 1648 return f - (f == v ? 0 : 1);
1651 } 1649 }
1660 1658
1661#ifdef __linux 1659#ifdef __linux
1662# include <sys/utsname.h> 1660# include <sys/utsname.h>
1663#endif 1661#endif
1664 1662
1665noinline ecb_cold 1663ecb_noinline ecb_cold
1666static unsigned int 1664static unsigned int
1667ev_linux_version (void) 1665ev_linux_version (void)
1668{ 1666{
1669#ifdef __linux 1667#ifdef __linux
1670 unsigned int v = 0; 1668 unsigned int v = 0;
1700} 1698}
1701 1699
1702/*****************************************************************************/ 1700/*****************************************************************************/
1703 1701
1704#if EV_AVOID_STDIO 1702#if EV_AVOID_STDIO
1705noinline ecb_cold 1703ecb_noinline ecb_cold
1706static void 1704static void
1707ev_printerr (const char *msg) 1705ev_printerr (const char *msg)
1708{ 1706{
1709 write (STDERR_FILENO, msg, strlen (msg)); 1707 write (STDERR_FILENO, msg, strlen (msg));
1710} 1708}
1717ev_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
1718{ 1716{
1719 syserr_cb = cb; 1717 syserr_cb = cb;
1720} 1718}
1721 1719
1722noinline ecb_cold 1720ecb_noinline ecb_cold
1723static void 1721static void
1724ev_syserr (const char *msg) 1722ev_syserr (const char *msg)
1725{ 1723{
1726 if (!msg) 1724 if (!msg)
1727 msg = "(libev) system error"; 1725 msg = "(libev) system error";
1873 static int ev_default_loop_ptr; 1871 static int ev_default_loop_ptr;
1874 1872
1875#endif 1873#endif
1876 1874
1877#if EV_FEATURE_API 1875#if EV_FEATURE_API
1878# 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)
1879# 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)
1880# define EV_INVOKE_PENDING invoke_cb (EV_A) 1878# define EV_INVOKE_PENDING invoke_cb (EV_A)
1881#else 1879#else
1882# define EV_RELEASE_CB (void)0 1880# define EV_RELEASE_CB (void)0
1883# define EV_ACQUIRE_CB (void)0 1881# define EV_ACQUIRE_CB (void)0
1884# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 1882# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
1891#ifndef EV_HAVE_EV_TIME 1889#ifndef EV_HAVE_EV_TIME
1892ev_tstamp 1890ev_tstamp
1893ev_time (void) EV_NOEXCEPT 1891ev_time (void) EV_NOEXCEPT
1894{ 1892{
1895#if EV_USE_REALTIME 1893#if EV_USE_REALTIME
1896 if (expect_true (have_realtime)) 1894 if (ecb_expect_true (have_realtime))
1897 { 1895 {
1898 struct timespec ts; 1896 struct timespec ts;
1899 clock_gettime (CLOCK_REALTIME, &ts); 1897 clock_gettime (CLOCK_REALTIME, &ts);
1900 return ts.tv_sec + ts.tv_nsec * 1e-9; 1898 return ts.tv_sec + ts.tv_nsec * 1e-9;
1901 } 1899 }
1909 1907
1910inline_size ev_tstamp 1908inline_size ev_tstamp
1911get_clock (void) 1909get_clock (void)
1912{ 1910{
1913#if EV_USE_MONOTONIC 1911#if EV_USE_MONOTONIC
1914 if (expect_true (have_monotonic)) 1912 if (ecb_expect_true (have_monotonic))
1915 { 1913 {
1916 struct timespec ts; 1914 struct timespec ts;
1917 clock_gettime (CLOCK_MONOTONIC, &ts); 1915 clock_gettime (CLOCK_MONOTONIC, &ts);
1918 return ts.tv_sec + ts.tv_nsec * 1e-9; 1916 return ts.tv_sec + ts.tv_nsec * 1e-9;
1919 } 1917 }
1981 } 1979 }
1982 1980
1983 return ncur; 1981 return ncur;
1984} 1982}
1985 1983
1986noinline ecb_cold 1984ecb_noinline ecb_cold
1987static void * 1985static void *
1988array_realloc (int elem, void *base, int *cur, int cnt) 1986array_realloc (int elem, void *base, int *cur, int cnt)
1989{ 1987{
1990 *cur = array_nextsize (elem, *cur, cnt); 1988 *cur = array_nextsize (elem, *cur, cnt);
1991 return ev_realloc (base, elem * *cur); 1989 return ev_realloc (base, elem * *cur);
1992} 1990}
1993 1991
1994#define array_needsize_noinit(base,count) 1992#define array_needsize_noinit(base,offset,count)
1995 1993
1996#define array_needsize_zerofill(base,count) \ 1994#define array_needsize_zerofill(base,offset,count) \
1997 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1995 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1998 1996
1999#define array_needsize(type,base,cur,cnt,init) \ 1997#define array_needsize(type,base,cur,cnt,init) \
2000 if (expect_false ((cnt) > (cur))) \ 1998 if (ecb_expect_false ((cnt) > (cur))) \
2001 { \ 1999 { \
2002 ecb_unused int ocur_ = (cur); \ 2000 ecb_unused int ocur_ = (cur); \
2003 (base) = (type *)array_realloc \ 2001 (base) = (type *)array_realloc \
2004 (sizeof (type), (base), &(cur), (cnt)); \ 2002 (sizeof (type), (base), &(cur), (cnt)); \
2005 init ((base) + (ocur_), (cur) - ocur_); \ 2003 init ((base), ocur_, ((cur) - ocur_)); \
2006 } 2004 }
2007 2005
2008#if 0 2006#if 0
2009#define array_slim(type,stem) \ 2007#define array_slim(type,stem) \
2010 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2008 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
2019 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
2020 2018
2021/*****************************************************************************/ 2019/*****************************************************************************/
2022 2020
2023/* dummy callback for pending events */ 2021/* dummy callback for pending events */
2024noinline 2022ecb_noinline
2025static void 2023static void
2026pendingcb (EV_P_ ev_prepare *w, int revents) 2024pendingcb (EV_P_ ev_prepare *w, int revents)
2027{ 2025{
2028} 2026}
2029 2027
2030noinline 2028ecb_noinline
2031void 2029void
2032ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT 2030ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
2033{ 2031{
2034 W w_ = (W)w; 2032 W w_ = (W)w;
2035 int pri = ABSPRI (w_); 2033 int pri = ABSPRI (w_);
2036 2034
2037 if (expect_false (w_->pending)) 2035 if (ecb_expect_false (w_->pending))
2038 pendings [pri][w_->pending - 1].events |= revents; 2036 pendings [pri][w_->pending - 1].events |= revents;
2039 else 2037 else
2040 { 2038 {
2041 w_->pending = ++pendingcnt [pri]; 2039 w_->pending = ++pendingcnt [pri];
2042 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);
2093inline_speed void 2091inline_speed void
2094fd_event (EV_P_ int fd, int revents) 2092fd_event (EV_P_ int fd, int revents)
2095{ 2093{
2096 ANFD *anfd = anfds + fd; 2094 ANFD *anfd = anfds + fd;
2097 2095
2098 if (expect_true (!anfd->reify)) 2096 if (ecb_expect_true (!anfd->reify))
2099 fd_event_nocheck (EV_A_ fd, revents); 2097 fd_event_nocheck (EV_A_ fd, revents);
2100} 2098}
2101 2099
2102void 2100void
2103ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT 2101ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2145 ev_io *w; 2143 ev_io *w;
2146 2144
2147 unsigned char o_events = anfd->events; 2145 unsigned char o_events = anfd->events;
2148 unsigned char o_reify = anfd->reify; 2146 unsigned char o_reify = anfd->reify;
2149 2147
2150 anfd->reify = 0; 2148 anfd->reify = 0;
2151 2149
2152 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 2150 /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
2153 { 2151 {
2154 anfd->events = 0; 2152 anfd->events = 0;
2155 2153
2156 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)
2157 anfd->events |= (unsigned char)w->events; 2155 anfd->events |= (unsigned char)w->events;
2173fd_change (EV_P_ int fd, int flags) 2171fd_change (EV_P_ int fd, int flags)
2174{ 2172{
2175 unsigned char reify = anfds [fd].reify; 2173 unsigned char reify = anfds [fd].reify;
2176 anfds [fd].reify |= flags; 2174 anfds [fd].reify |= flags;
2177 2175
2178 if (expect_true (!reify)) 2176 if (ecb_expect_true (!reify))
2179 { 2177 {
2180 ++fdchangecnt; 2178 ++fdchangecnt;
2181 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); 2179 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2182 fdchanges [fdchangecnt - 1] = fd; 2180 fdchanges [fdchangecnt - 1] = fd;
2183 } 2181 }
2206 return fcntl (fd, F_GETFD) != -1; 2204 return fcntl (fd, F_GETFD) != -1;
2207#endif 2205#endif
2208} 2206}
2209 2207
2210/* called on EBADF to verify fds */ 2208/* called on EBADF to verify fds */
2211noinline ecb_cold 2209ecb_noinline ecb_cold
2212static void 2210static void
2213fd_ebadf (EV_P) 2211fd_ebadf (EV_P)
2214{ 2212{
2215 int fd; 2213 int fd;
2216 2214
2219 if (!fd_valid (fd) && errno == EBADF) 2217 if (!fd_valid (fd) && errno == EBADF)
2220 fd_kill (EV_A_ fd); 2218 fd_kill (EV_A_ fd);
2221} 2219}
2222 2220
2223/* 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 */
2224noinline ecb_cold 2222ecb_noinline ecb_cold
2225static void 2223static void
2226fd_enomem (EV_P) 2224fd_enomem (EV_P)
2227{ 2225{
2228 int fd; 2226 int fd;
2229 2227
2234 break; 2232 break;
2235 } 2233 }
2236} 2234}
2237 2235
2238/* 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 */
2239noinline 2237ecb_noinline
2240static void 2238static void
2241fd_rearm_all (EV_P) 2239fd_rearm_all (EV_P)
2242{ 2240{
2243 int fd; 2241 int fd;
2244 2242
2298 ev_tstamp minat; 2296 ev_tstamp minat;
2299 ANHE *minpos; 2297 ANHE *minpos;
2300 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; 2298 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1;
2301 2299
2302 /* find minimum child */ 2300 /* find minimum child */
2303 if (expect_true (pos + DHEAP - 1 < E)) 2301 if (ecb_expect_true (pos + DHEAP - 1 < E))
2304 { 2302 {
2305 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); 2303 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos));
2306 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));
2307 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));
2308 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));
2426 2424
2427/*****************************************************************************/ 2425/*****************************************************************************/
2428 2426
2429#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2427#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2430 2428
2431noinline ecb_cold 2429ecb_noinline ecb_cold
2432static void 2430static void
2433evpipe_init (EV_P) 2431evpipe_init (EV_P)
2434{ 2432{
2435 if (!ev_is_active (&pipe_w)) 2433 if (!ev_is_active (&pipe_w))
2436 { 2434 {
2477inline_speed void 2475inline_speed void
2478evpipe_write (EV_P_ EV_ATOMIC_T *flag) 2476evpipe_write (EV_P_ EV_ATOMIC_T *flag)
2479{ 2477{
2480 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 */
2481 2479
2482 if (expect_true (*flag)) 2480 if (ecb_expect_true (*flag))
2483 return; 2481 return;
2484 2482
2485 *flag = 1; 2483 *flag = 1;
2486 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 */
2487 2485
2564 sig_pending = 0; 2562 sig_pending = 0;
2565 2563
2566 ECB_MEMORY_FENCE; 2564 ECB_MEMORY_FENCE;
2567 2565
2568 for (i = EV_NSIG - 1; i--; ) 2566 for (i = EV_NSIG - 1; i--; )
2569 if (expect_false (signals [i].pending)) 2567 if (ecb_expect_false (signals [i].pending))
2570 ev_feed_signal_event (EV_A_ i + 1); 2568 ev_feed_signal_event (EV_A_ i + 1);
2571 } 2569 }
2572#endif 2570#endif
2573 2571
2574#if EV_ASYNC_ENABLE 2572#if EV_ASYNC_ENABLE
2615#endif 2613#endif
2616 2614
2617 ev_feed_signal (signum); 2615 ev_feed_signal (signum);
2618} 2616}
2619 2617
2620noinline 2618ecb_noinline
2621void 2619void
2622ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT 2620ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2623{ 2621{
2624 WL w; 2622 WL w;
2625 2623
2626 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2624 if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG))
2627 return; 2625 return;
2628 2626
2629 --signum; 2627 --signum;
2630 2628
2631#if EV_MULTIPLICITY 2629#if EV_MULTIPLICITY
2632 /* 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 */
2633 /* or, likely more useful, feeding a signal nobody is waiting for */ 2631 /* or, likely more useful, feeding a signal nobody is waiting for */
2634 2632
2635 if (expect_false (signals [signum].loop != EV_A)) 2633 if (ecb_expect_false (signals [signum].loop != EV_A))
2636 return; 2634 return;
2637#endif 2635#endif
2638 2636
2639 signals [signum].pending = 0; 2637 signals [signum].pending = 0;
2640 ECB_MEMORY_FENCE_RELEASE; 2638 ECB_MEMORY_FENCE_RELEASE;
2733# include "ev_port.c" 2731# include "ev_port.c"
2734#endif 2732#endif
2735#if EV_USE_KQUEUE 2733#if EV_USE_KQUEUE
2736# include "ev_kqueue.c" 2734# include "ev_kqueue.c"
2737#endif 2735#endif
2736#if EV_USE_EPOLL
2737# include "ev_epoll.c"
2738#endif
2738#if EV_USE_LINUXAIO 2739#if EV_USE_LINUXAIO
2739# include "ev_linuxaio.c" 2740# include "ev_linuxaio.c"
2740#endif
2741#if EV_USE_EPOLL
2742# include "ev_epoll.c"
2743#endif 2741#endif
2744#if EV_USE_POLL 2742#if EV_USE_POLL
2745# include "ev_poll.c" 2743# include "ev_poll.c"
2746#endif 2744#endif
2747#if EV_USE_SELECT 2745#if EV_USE_SELECT
2807#ifdef __FreeBSD__ 2805#ifdef __FreeBSD__
2808 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ 2806 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
2809#endif 2807#endif
2810 2808
2811 /* TODO: linuxaio is very experimental */ 2809 /* TODO: linuxaio is very experimental */
2810#if !EV_RECOMMEND_LINUXAIO
2812 flags &= ~EVBACKEND_LINUXAIO; 2811 flags &= ~EVBACKEND_LINUXAIO;
2812#endif
2813 2813
2814 return flags; 2814 return flags;
2815} 2815}
2816 2816
2817ecb_cold 2817ecb_cold
2883 acquire_cb = acquire; 2883 acquire_cb = acquire;
2884} 2884}
2885#endif 2885#endif
2886 2886
2887/* initialise a loop structure, must be zero-initialised */ 2887/* initialise a loop structure, must be zero-initialised */
2888noinline ecb_cold 2888ecb_noinline ecb_cold
2889static void 2889static void
2890loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT 2890loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2891{ 2891{
2892 if (!backend) 2892 if (!backend)
2893 { 2893 {
2998 return; 2998 return;
2999#endif 2999#endif
3000 3000
3001#if EV_CLEANUP_ENABLE 3001#if EV_CLEANUP_ENABLE
3002 /* queue cleanup watchers (and execute them) */ 3002 /* queue cleanup watchers (and execute them) */
3003 if (expect_false (cleanupcnt)) 3003 if (ecb_expect_false (cleanupcnt))
3004 { 3004 {
3005 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); 3005 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
3006 EV_INVOKE_PENDING; 3006 EV_INVOKE_PENDING;
3007 } 3007 }
3008#endif 3008#endif
3162} 3162}
3163 3163
3164#endif /* multiplicity */ 3164#endif /* multiplicity */
3165 3165
3166#if EV_VERIFY 3166#if EV_VERIFY
3167noinline ecb_cold 3167ecb_noinline ecb_cold
3168static void 3168static void
3169verify_watcher (EV_P_ W w) 3169verify_watcher (EV_P_ W w)
3170{ 3170{
3171 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));
3172 3172
3173 if (w->pending) 3173 if (w->pending)
3174 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));
3175} 3175}
3176 3176
3177noinline ecb_cold 3177ecb_noinline ecb_cold
3178static void 3178static void
3179verify_heap (EV_P_ ANHE *heap, int N) 3179verify_heap (EV_P_ ANHE *heap, int N)
3180{ 3180{
3181 int i; 3181 int i;
3182 3182
3188 3188
3189 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 3189 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
3190 } 3190 }
3191} 3191}
3192 3192
3193noinline ecb_cold 3193ecb_noinline ecb_cold
3194static void 3194static void
3195array_verify (EV_P_ W *ws, int cnt) 3195array_verify (EV_P_ W *ws, int cnt)
3196{ 3196{
3197 while (cnt--) 3197 while (cnt--)
3198 { 3198 {
3347 count += pendingcnt [pri]; 3347 count += pendingcnt [pri];
3348 3348
3349 return count; 3349 return count;
3350} 3350}
3351 3351
3352noinline 3352ecb_noinline
3353void 3353void
3354ev_invoke_pending (EV_P) 3354ev_invoke_pending (EV_P)
3355{ 3355{
3356 pendingpri = NUMPRI; 3356 pendingpri = NUMPRI;
3357 3357
3376/* make idle watchers pending. this handles the "call-idle */ 3376/* make idle watchers pending. this handles the "call-idle */
3377/* only when higher priorities are idle" logic */ 3377/* only when higher priorities are idle" logic */
3378inline_size void 3378inline_size void
3379idle_reify (EV_P) 3379idle_reify (EV_P)
3380{ 3380{
3381 if (expect_false (idleall)) 3381 if (ecb_expect_false (idleall))
3382 { 3382 {
3383 int pri; 3383 int pri;
3384 3384
3385 for (pri = NUMPRI; pri--; ) 3385 for (pri = NUMPRI; pri--; )
3386 { 3386 {
3435 } 3435 }
3436} 3436}
3437 3437
3438#if EV_PERIODIC_ENABLE 3438#if EV_PERIODIC_ENABLE
3439 3439
3440noinline 3440ecb_noinline
3441static void 3441static void
3442periodic_recalc (EV_P_ ev_periodic *w) 3442periodic_recalc (EV_P_ ev_periodic *w)
3443{ 3443{
3444 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; 3444 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL;
3445 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);
3448 while (at <= ev_rt_now) 3448 while (at <= ev_rt_now)
3449 { 3449 {
3450 ev_tstamp nat = at + w->interval; 3450 ev_tstamp nat = at + w->interval;
3451 3451
3452 /* when resolution fails us, we use ev_rt_now */ 3452 /* when resolution fails us, we use ev_rt_now */
3453 if (expect_false (nat == at)) 3453 if (ecb_expect_false (nat == at))
3454 { 3454 {
3455 at = ev_rt_now; 3455 at = ev_rt_now;
3456 break; 3456 break;
3457 } 3457 }
3458 3458
3504 } 3504 }
3505} 3505}
3506 3506
3507/* simply recalculate all periodics */ 3507/* simply recalculate all periodics */
3508/* 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? */
3509noinline ecb_cold 3509ecb_noinline ecb_cold
3510static void 3510static void
3511periodics_reschedule (EV_P) 3511periodics_reschedule (EV_P)
3512{ 3512{
3513 int i; 3513 int i;
3514 3514
3528 reheap (periodics, periodiccnt); 3528 reheap (periodics, periodiccnt);
3529} 3529}
3530#endif 3530#endif
3531 3531
3532/* adjust all timers by a given offset */ 3532/* adjust all timers by a given offset */
3533noinline ecb_cold 3533ecb_noinline ecb_cold
3534static void 3534static void
3535timers_reschedule (EV_P_ ev_tstamp adjust) 3535timers_reschedule (EV_P_ ev_tstamp adjust)
3536{ 3536{
3537 int i; 3537 int i;
3538 3538
3548/* also detect if there was a timejump, and act accordingly */ 3548/* also detect if there was a timejump, and act accordingly */
3549inline_speed void 3549inline_speed void
3550time_update (EV_P_ ev_tstamp max_block) 3550time_update (EV_P_ ev_tstamp max_block)
3551{ 3551{
3552#if EV_USE_MONOTONIC 3552#if EV_USE_MONOTONIC
3553 if (expect_true (have_monotonic)) 3553 if (ecb_expect_true (have_monotonic))
3554 { 3554 {
3555 int i; 3555 int i;
3556 ev_tstamp odiff = rtmn_diff; 3556 ev_tstamp odiff = rtmn_diff;
3557 3557
3558 mn_now = get_clock (); 3558 mn_now = get_clock ();
3559 3559
3560 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ 3560 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */
3561 /* interpolate in the meantime */ 3561 /* interpolate in the meantime */
3562 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 3562 if (ecb_expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
3563 { 3563 {
3564 ev_rt_now = rtmn_diff + mn_now; 3564 ev_rt_now = rtmn_diff + mn_now;
3565 return; 3565 return;
3566 } 3566 }
3567 3567
3581 ev_tstamp diff; 3581 ev_tstamp diff;
3582 rtmn_diff = ev_rt_now - mn_now; 3582 rtmn_diff = ev_rt_now - mn_now;
3583 3583
3584 diff = odiff - rtmn_diff; 3584 diff = odiff - rtmn_diff;
3585 3585
3586 if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) 3586 if (ecb_expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP))
3587 return; /* all is well */ 3587 return; /* all is well */
3588 3588
3589 ev_rt_now = ev_time (); 3589 ev_rt_now = ev_time ();
3590 mn_now = get_clock (); 3590 mn_now = get_clock ();
3591 now_floor = mn_now; 3591 now_floor = mn_now;
3600 else 3600 else
3601#endif 3601#endif
3602 { 3602 {
3603 ev_rt_now = ev_time (); 3603 ev_rt_now = ev_time ();
3604 3604
3605 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))
3606 { 3606 {
3607 /* 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 */
3608 timers_reschedule (EV_A_ ev_rt_now - mn_now); 3608 timers_reschedule (EV_A_ ev_rt_now - mn_now);
3609#if EV_PERIODIC_ENABLE 3609#if EV_PERIODIC_ENABLE
3610 periodics_reschedule (EV_A); 3610 periodics_reschedule (EV_A);
3633#if EV_VERIFY >= 2 3633#if EV_VERIFY >= 2
3634 ev_verify (EV_A); 3634 ev_verify (EV_A);
3635#endif 3635#endif
3636 3636
3637#ifndef _WIN32 3637#ifndef _WIN32
3638 if (expect_false (curpid)) /* penalise the forking check even more */ 3638 if (ecb_expect_false (curpid)) /* penalise the forking check even more */
3639 if (expect_false (getpid () != curpid)) 3639 if (ecb_expect_false (getpid () != curpid))
3640 { 3640 {
3641 curpid = getpid (); 3641 curpid = getpid ();
3642 postfork = 1; 3642 postfork = 1;
3643 } 3643 }
3644#endif 3644#endif
3645 3645
3646#if EV_FORK_ENABLE 3646#if EV_FORK_ENABLE
3647 /* we might have forked, so queue fork handlers */ 3647 /* we might have forked, so queue fork handlers */
3648 if (expect_false (postfork)) 3648 if (ecb_expect_false (postfork))
3649 if (forkcnt) 3649 if (forkcnt)
3650 { 3650 {
3651 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 3651 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
3652 EV_INVOKE_PENDING; 3652 EV_INVOKE_PENDING;
3653 } 3653 }
3654#endif 3654#endif
3655 3655
3656#if EV_PREPARE_ENABLE 3656#if EV_PREPARE_ENABLE
3657 /* queue prepare watchers (and execute them) */ 3657 /* queue prepare watchers (and execute them) */
3658 if (expect_false (preparecnt)) 3658 if (ecb_expect_false (preparecnt))
3659 { 3659 {
3660 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 3660 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
3661 EV_INVOKE_PENDING; 3661 EV_INVOKE_PENDING;
3662 } 3662 }
3663#endif 3663#endif
3664 3664
3665 if (expect_false (loop_done)) 3665 if (ecb_expect_false (loop_done))
3666 break; 3666 break;
3667 3667
3668 /* we might have forked, so reify kernel state if necessary */ 3668 /* we might have forked, so reify kernel state if necessary */
3669 if (expect_false (postfork)) 3669 if (ecb_expect_false (postfork))
3670 loop_fork (EV_A); 3670 loop_fork (EV_A);
3671 3671
3672 /* update fd-related kernel structures */ 3672 /* update fd-related kernel structures */
3673 fd_reify (EV_A); 3673 fd_reify (EV_A);
3674 3674
3686 /* from now on, we want a pipe-wake-up */ 3686 /* from now on, we want a pipe-wake-up */
3687 pipe_write_wanted = 1; 3687 pipe_write_wanted = 1;
3688 3688
3689 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 */
3690 3690
3691 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 3691 if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
3692 { 3692 {
3693 waittime = MAX_BLOCKTIME; 3693 waittime = MAX_BLOCKTIME;
3694 3694
3695 if (timercnt) 3695 if (timercnt)
3696 { 3696 {
3705 if (waittime > to) waittime = to; 3705 if (waittime > to) waittime = to;
3706 } 3706 }
3707#endif 3707#endif
3708 3708
3709 /* don't let timeouts decrease the waittime below timeout_blocktime */ 3709 /* don't let timeouts decrease the waittime below timeout_blocktime */
3710 if (expect_false (waittime < timeout_blocktime)) 3710 if (ecb_expect_false (waittime < timeout_blocktime))
3711 waittime = timeout_blocktime; 3711 waittime = timeout_blocktime;
3712 3712
3713 /* 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 */
3714 /* to pass a minimum nonzero value to the backend */ 3714 /* to pass a minimum nonzero value to the backend */
3715 if (expect_false (waittime < backend_mintime)) 3715 if (ecb_expect_false (waittime < backend_mintime))
3716 waittime = backend_mintime; 3716 waittime = backend_mintime;
3717 3717
3718 /* extra check because io_blocktime is commonly 0 */ 3718 /* extra check because io_blocktime is commonly 0 */
3719 if (expect_false (io_blocktime)) 3719 if (ecb_expect_false (io_blocktime))
3720 { 3720 {
3721 sleeptime = io_blocktime - (mn_now - prev_mn_now); 3721 sleeptime = io_blocktime - (mn_now - prev_mn_now);
3722 3722
3723 if (sleeptime > waittime - backend_mintime) 3723 if (sleeptime > waittime - backend_mintime)
3724 sleeptime = waittime - backend_mintime; 3724 sleeptime = waittime - backend_mintime;
3725 3725
3726 if (expect_true (sleeptime > 0.)) 3726 if (ecb_expect_true (sleeptime > 0.))
3727 { 3727 {
3728 ev_sleep (sleeptime); 3728 ev_sleep (sleeptime);
3729 waittime -= sleeptime; 3729 waittime -= sleeptime;
3730 } 3730 }
3731 } 3731 }
3745 { 3745 {
3746 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)));
3747 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3747 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3748 } 3748 }
3749 3749
3750
3751 /* update ev_rt_now, do magic */ 3750 /* update ev_rt_now, do magic */
3752 time_update (EV_A_ waittime + sleeptime); 3751 time_update (EV_A_ waittime + sleeptime);
3753 } 3752 }
3754 3753
3755 /* queue pending timers and reschedule them */ 3754 /* queue pending timers and reschedule them */
3763 idle_reify (EV_A); 3762 idle_reify (EV_A);
3764#endif 3763#endif
3765 3764
3766#if EV_CHECK_ENABLE 3765#if EV_CHECK_ENABLE
3767 /* queue check watchers, to be executed first */ 3766 /* queue check watchers, to be executed first */
3768 if (expect_false (checkcnt)) 3767 if (ecb_expect_false (checkcnt))
3769 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 3768 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
3770#endif 3769#endif
3771 3770
3772 EV_INVOKE_PENDING; 3771 EV_INVOKE_PENDING;
3773 } 3772 }
3774 while (expect_true ( 3773 while (ecb_expect_true (
3775 activecnt 3774 activecnt
3776 && !loop_done 3775 && !loop_done
3777 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) 3776 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
3778 )); 3777 ));
3779 3778
3843inline_size void 3842inline_size void
3844wlist_del (WL *head, WL elem) 3843wlist_del (WL *head, WL elem)
3845{ 3844{
3846 while (*head) 3845 while (*head)
3847 { 3846 {
3848 if (expect_true (*head == elem)) 3847 if (ecb_expect_true (*head == elem))
3849 { 3848 {
3850 *head = elem->next; 3849 *head = elem->next;
3851 break; 3850 break;
3852 } 3851 }
3853 3852
3870ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT 3869ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3871{ 3870{
3872 W w_ = (W)w; 3871 W w_ = (W)w;
3873 int pending = w_->pending; 3872 int pending = w_->pending;
3874 3873
3875 if (expect_true (pending)) 3874 if (ecb_expect_true (pending))
3876 { 3875 {
3877 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; 3876 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
3878 p->w = (W)&pending_w; 3877 p->w = (W)&pending_w;
3879 w_->pending = 0; 3878 w_->pending = 0;
3880 return p->events; 3879 return p->events;
3907 w->active = 0; 3906 w->active = 0;
3908} 3907}
3909 3908
3910/*****************************************************************************/ 3909/*****************************************************************************/
3911 3910
3912noinline 3911ecb_noinline
3913void 3912void
3914ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT 3913ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3915{ 3914{
3916 int fd = w->fd; 3915 int fd = w->fd;
3917 3916
3918 if (expect_false (ev_is_active (w))) 3917 if (ecb_expect_false (ev_is_active (w)))
3919 return; 3918 return;
3920 3919
3921 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3920 assert (("libev: ev_io_start called with negative fd", fd >= 0));
3922 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))));
3923 3922
3923#if EV_VERIFY >= 2
3924 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3925#endif
3924 EV_FREQUENT_CHECK; 3926 EV_FREQUENT_CHECK;
3925 3927
3926 ev_start (EV_A_ (W)w, 1); 3928 ev_start (EV_A_ (W)w, 1);
3927 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); 3929 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3928 wlist_add (&anfds[fd].head, (WL)w); 3930 wlist_add (&anfds[fd].head, (WL)w);
3934 w->events &= ~EV__IOFDSET; 3936 w->events &= ~EV__IOFDSET;
3935 3937
3936 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3937} 3939}
3938 3940
3939noinline 3941ecb_noinline
3940void 3942void
3941ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT 3943ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3942{ 3944{
3943 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3944 if (expect_false (!ev_is_active (w))) 3946 if (ecb_expect_false (!ev_is_active (w)))
3945 return; 3947 return;
3946 3948
3947 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));
3948 3950
3951#if EV_VERIFY >= 2
3952 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3953#endif
3949 EV_FREQUENT_CHECK; 3954 EV_FREQUENT_CHECK;
3950 3955
3951 wlist_del (&anfds[w->fd].head, (WL)w); 3956 wlist_del (&anfds[w->fd].head, (WL)w);
3952 ev_stop (EV_A_ (W)w); 3957 ev_stop (EV_A_ (W)w);
3953 3958
3954 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3959 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3955 3960
3956 EV_FREQUENT_CHECK; 3961 EV_FREQUENT_CHECK;
3957} 3962}
3958 3963
3959noinline 3964ecb_noinline
3960void 3965void
3961ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT 3966ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3962{ 3967{
3963 if (expect_false (ev_is_active (w))) 3968 if (ecb_expect_false (ev_is_active (w)))
3964 return; 3969 return;
3965 3970
3966 ev_at (w) += mn_now; 3971 ev_at (w) += mn_now;
3967 3972
3968 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.));
3979 EV_FREQUENT_CHECK; 3984 EV_FREQUENT_CHECK;
3980 3985
3981 /*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));*/
3982} 3987}
3983 3988
3984noinline 3989ecb_noinline
3985void 3990void
3986ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT 3991ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3987{ 3992{
3988 clear_pending (EV_A_ (W)w); 3993 clear_pending (EV_A_ (W)w);
3989 if (expect_false (!ev_is_active (w))) 3994 if (ecb_expect_false (!ev_is_active (w)))
3990 return; 3995 return;
3991 3996
3992 EV_FREQUENT_CHECK; 3997 EV_FREQUENT_CHECK;
3993 3998
3994 { 3999 {
3996 4001
3997 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));
3998 4003
3999 --timercnt; 4004 --timercnt;
4000 4005
4001 if (expect_true (active < timercnt + HEAP0)) 4006 if (ecb_expect_true (active < timercnt + HEAP0))
4002 { 4007 {
4003 timers [active] = timers [timercnt + HEAP0]; 4008 timers [active] = timers [timercnt + HEAP0];
4004 adjustheap (timers, timercnt, active); 4009 adjustheap (timers, timercnt, active);
4005 } 4010 }
4006 } 4011 }
4010 ev_stop (EV_A_ (W)w); 4015 ev_stop (EV_A_ (W)w);
4011 4016
4012 EV_FREQUENT_CHECK; 4017 EV_FREQUENT_CHECK;
4013} 4018}
4014 4019
4015noinline 4020ecb_noinline
4016void 4021void
4017ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT 4022ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
4018{ 4023{
4019 EV_FREQUENT_CHECK; 4024 EV_FREQUENT_CHECK;
4020 4025
4045{ 4050{
4046 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4051 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
4047} 4052}
4048 4053
4049#if EV_PERIODIC_ENABLE 4054#if EV_PERIODIC_ENABLE
4050noinline 4055ecb_noinline
4051void 4056void
4052ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT 4057ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4053{ 4058{
4054 if (expect_false (ev_is_active (w))) 4059 if (ecb_expect_false (ev_is_active (w)))
4055 return; 4060 return;
4056 4061
4057 if (w->reschedule_cb) 4062 if (w->reschedule_cb)
4058 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 4063 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
4059 else if (w->interval) 4064 else if (w->interval)
4076 EV_FREQUENT_CHECK; 4081 EV_FREQUENT_CHECK;
4077 4082
4078 /*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));*/
4079} 4084}
4080 4085
4081noinline 4086ecb_noinline
4082void 4087void
4083ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT 4088ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4084{ 4089{
4085 clear_pending (EV_A_ (W)w); 4090 clear_pending (EV_A_ (W)w);
4086 if (expect_false (!ev_is_active (w))) 4091 if (ecb_expect_false (!ev_is_active (w)))
4087 return; 4092 return;
4088 4093
4089 EV_FREQUENT_CHECK; 4094 EV_FREQUENT_CHECK;
4090 4095
4091 { 4096 {
4093 4098
4094 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));
4095 4100
4096 --periodiccnt; 4101 --periodiccnt;
4097 4102
4098 if (expect_true (active < periodiccnt + HEAP0)) 4103 if (ecb_expect_true (active < periodiccnt + HEAP0))
4099 { 4104 {
4100 periodics [active] = periodics [periodiccnt + HEAP0]; 4105 periodics [active] = periodics [periodiccnt + HEAP0];
4101 adjustheap (periodics, periodiccnt, active); 4106 adjustheap (periodics, periodiccnt, active);
4102 } 4107 }
4103 } 4108 }
4105 ev_stop (EV_A_ (W)w); 4110 ev_stop (EV_A_ (W)w);
4106 4111
4107 EV_FREQUENT_CHECK; 4112 EV_FREQUENT_CHECK;
4108} 4113}
4109 4114
4110noinline 4115ecb_noinline
4111void 4116void
4112ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT 4117ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4113{ 4118{
4114 /* TODO: use adjustheap and recalculation */ 4119 /* TODO: use adjustheap and recalculation */
4115 ev_periodic_stop (EV_A_ w); 4120 ev_periodic_stop (EV_A_ w);
4121# define SA_RESTART 0 4126# define SA_RESTART 0
4122#endif 4127#endif
4123 4128
4124#if EV_SIGNAL_ENABLE 4129#if EV_SIGNAL_ENABLE
4125 4130
4126noinline 4131ecb_noinline
4127void 4132void
4128ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT 4133ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4129{ 4134{
4130 if (expect_false (ev_is_active (w))) 4135 if (ecb_expect_false (ev_is_active (w)))
4131 return; 4136 return;
4132 4137
4133 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));
4134 4139
4135#if EV_MULTIPLICITY 4140#if EV_MULTIPLICITY
4204 } 4209 }
4205 4210
4206 EV_FREQUENT_CHECK; 4211 EV_FREQUENT_CHECK;
4207} 4212}
4208 4213
4209noinline 4214ecb_noinline
4210void 4215void
4211ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT 4216ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4212{ 4217{
4213 clear_pending (EV_A_ (W)w); 4218 clear_pending (EV_A_ (W)w);
4214 if (expect_false (!ev_is_active (w))) 4219 if (ecb_expect_false (!ev_is_active (w)))
4215 return; 4220 return;
4216 4221
4217 EV_FREQUENT_CHECK; 4222 EV_FREQUENT_CHECK;
4218 4223
4219 wlist_del (&signals [w->signum - 1].head, (WL)w); 4224 wlist_del (&signals [w->signum - 1].head, (WL)w);
4252ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT 4257ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4253{ 4258{
4254#if EV_MULTIPLICITY 4259#if EV_MULTIPLICITY
4255 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));
4256#endif 4261#endif
4257 if (expect_false (ev_is_active (w))) 4262 if (ecb_expect_false (ev_is_active (w)))
4258 return; 4263 return;
4259 4264
4260 EV_FREQUENT_CHECK; 4265 EV_FREQUENT_CHECK;
4261 4266
4262 ev_start (EV_A_ (W)w, 1); 4267 ev_start (EV_A_ (W)w, 1);
4267 4272
4268void 4273void
4269ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT 4274ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4270{ 4275{
4271 clear_pending (EV_A_ (W)w); 4276 clear_pending (EV_A_ (W)w);
4272 if (expect_false (!ev_is_active (w))) 4277 if (ecb_expect_false (!ev_is_active (w)))
4273 return; 4278 return;
4274 4279
4275 EV_FREQUENT_CHECK; 4280 EV_FREQUENT_CHECK;
4276 4281
4277 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); 4282 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
4291 4296
4292#define DEF_STAT_INTERVAL 5.0074891 4297#define DEF_STAT_INTERVAL 5.0074891
4293#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4298#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4294#define MIN_STAT_INTERVAL 0.1074891 4299#define MIN_STAT_INTERVAL 0.1074891
4295 4300
4296noinline 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);
4297 4302
4298#if EV_USE_INOTIFY 4303#if EV_USE_INOTIFY
4299 4304
4300/* 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 */
4301# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 4306# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4302 4307
4303noinline 4308ecb_noinline
4304static void 4309static void
4305infy_add (EV_P_ ev_stat *w) 4310infy_add (EV_P_ ev_stat *w)
4306{ 4311{
4307 w->wd = inotify_add_watch (fs_fd, w->path, 4312 w->wd = inotify_add_watch (fs_fd, w->path,
4308 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4313 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4373 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4378 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4374 ev_timer_again (EV_A_ &w->timer); 4379 ev_timer_again (EV_A_ &w->timer);
4375 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4380 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4376} 4381}
4377 4382
4378noinline 4383ecb_noinline
4379static void 4384static void
4380infy_del (EV_P_ ev_stat *w) 4385infy_del (EV_P_ ev_stat *w)
4381{ 4386{
4382 int slot; 4387 int slot;
4383 int wd = w->wd; 4388 int wd = w->wd;
4391 4396
4392 /* remove this watcher, if others are watching it, they will rearm */ 4397 /* remove this watcher, if others are watching it, they will rearm */
4393 inotify_rm_watch (fs_fd, wd); 4398 inotify_rm_watch (fs_fd, wd);
4394} 4399}
4395 4400
4396noinline 4401ecb_noinline
4397static void 4402static void
4398infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4403infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4399{ 4404{
4400 if (slot < 0) 4405 if (slot < 0)
4401 /* overflow, need to check for all hash slots */ 4406 /* overflow, need to check for all hash slots */
4547 w->attr.st_nlink = 0; 4552 w->attr.st_nlink = 0;
4548 else if (!w->attr.st_nlink) 4553 else if (!w->attr.st_nlink)
4549 w->attr.st_nlink = 1; 4554 w->attr.st_nlink = 1;
4550} 4555}
4551 4556
4552noinline 4557ecb_noinline
4553static void 4558static void
4554stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4559stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4555{ 4560{
4556 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4561 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4557 4562
4591} 4596}
4592 4597
4593void 4598void
4594ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT 4599ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4595{ 4600{
4596 if (expect_false (ev_is_active (w))) 4601 if (ecb_expect_false (ev_is_active (w)))
4597 return; 4602 return;
4598 4603
4599 ev_stat_stat (EV_A_ w); 4604 ev_stat_stat (EV_A_ w);
4600 4605
4601 if (w->interval < MIN_STAT_INTERVAL && w->interval) 4606 if (w->interval < MIN_STAT_INTERVAL && w->interval)
4623 4628
4624void 4629void
4625ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT 4630ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4626{ 4631{
4627 clear_pending (EV_A_ (W)w); 4632 clear_pending (EV_A_ (W)w);
4628 if (expect_false (!ev_is_active (w))) 4633 if (ecb_expect_false (!ev_is_active (w)))
4629 return; 4634 return;
4630 4635
4631 EV_FREQUENT_CHECK; 4636 EV_FREQUENT_CHECK;
4632 4637
4633#if EV_USE_INOTIFY 4638#if EV_USE_INOTIFY
4648 4653
4649#if EV_IDLE_ENABLE 4654#if EV_IDLE_ENABLE
4650void 4655void
4651ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT 4656ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4652{ 4657{
4653 if (expect_false (ev_is_active (w))) 4658 if (ecb_expect_false (ev_is_active (w)))
4654 return; 4659 return;
4655 4660
4656 pri_adjust (EV_A_ (W)w); 4661 pri_adjust (EV_A_ (W)w);
4657 4662
4658 EV_FREQUENT_CHECK; 4663 EV_FREQUENT_CHECK;
4672 4677
4673void 4678void
4674ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT 4679ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4675{ 4680{
4676 clear_pending (EV_A_ (W)w); 4681 clear_pending (EV_A_ (W)w);
4677 if (expect_false (!ev_is_active (w))) 4682 if (ecb_expect_false (!ev_is_active (w)))
4678 return; 4683 return;
4679 4684
4680 EV_FREQUENT_CHECK; 4685 EV_FREQUENT_CHECK;
4681 4686
4682 { 4687 {
4695 4700
4696#if EV_PREPARE_ENABLE 4701#if EV_PREPARE_ENABLE
4697void 4702void
4698ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT 4703ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4699{ 4704{
4700 if (expect_false (ev_is_active (w))) 4705 if (ecb_expect_false (ev_is_active (w)))
4701 return; 4706 return;
4702 4707
4703 EV_FREQUENT_CHECK; 4708 EV_FREQUENT_CHECK;
4704 4709
4705 ev_start (EV_A_ (W)w, ++preparecnt); 4710 ev_start (EV_A_ (W)w, ++preparecnt);
4711 4716
4712void 4717void
4713ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT 4718ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4714{ 4719{
4715 clear_pending (EV_A_ (W)w); 4720 clear_pending (EV_A_ (W)w);
4716 if (expect_false (!ev_is_active (w))) 4721 if (ecb_expect_false (!ev_is_active (w)))
4717 return; 4722 return;
4718 4723
4719 EV_FREQUENT_CHECK; 4724 EV_FREQUENT_CHECK;
4720 4725
4721 { 4726 {
4733 4738
4734#if EV_CHECK_ENABLE 4739#if EV_CHECK_ENABLE
4735void 4740void
4736ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT 4741ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4737{ 4742{
4738 if (expect_false (ev_is_active (w))) 4743 if (ecb_expect_false (ev_is_active (w)))
4739 return; 4744 return;
4740 4745
4741 EV_FREQUENT_CHECK; 4746 EV_FREQUENT_CHECK;
4742 4747
4743 ev_start (EV_A_ (W)w, ++checkcnt); 4748 ev_start (EV_A_ (W)w, ++checkcnt);
4749 4754
4750void 4755void
4751ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT 4756ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4752{ 4757{
4753 clear_pending (EV_A_ (W)w); 4758 clear_pending (EV_A_ (W)w);
4754 if (expect_false (!ev_is_active (w))) 4759 if (ecb_expect_false (!ev_is_active (w)))
4755 return; 4760 return;
4756 4761
4757 EV_FREQUENT_CHECK; 4762 EV_FREQUENT_CHECK;
4758 4763
4759 { 4764 {
4768 EV_FREQUENT_CHECK; 4773 EV_FREQUENT_CHECK;
4769} 4774}
4770#endif 4775#endif
4771 4776
4772#if EV_EMBED_ENABLE 4777#if EV_EMBED_ENABLE
4773noinline 4778ecb_noinline
4774void 4779void
4775ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT 4780ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4776{ 4781{
4777 ev_run (w->other, EVRUN_NOWAIT); 4782 ev_run (w->other, EVRUN_NOWAIT);
4778} 4783}
4830#endif 4835#endif
4831 4836
4832void 4837void
4833ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT 4838ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4834{ 4839{
4835 if (expect_false (ev_is_active (w))) 4840 if (ecb_expect_false (ev_is_active (w)))
4836 return; 4841 return;
4837 4842
4838 { 4843 {
4839 EV_P = w->other; 4844 EV_P = w->other;
4840 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 ()));
4862 4867
4863void 4868void
4864ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT 4869ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4865{ 4870{
4866 clear_pending (EV_A_ (W)w); 4871 clear_pending (EV_A_ (W)w);
4867 if (expect_false (!ev_is_active (w))) 4872 if (ecb_expect_false (!ev_is_active (w)))
4868 return; 4873 return;
4869 4874
4870 EV_FREQUENT_CHECK; 4875 EV_FREQUENT_CHECK;
4871 4876
4872 ev_io_stop (EV_A_ &w->io); 4877 ev_io_stop (EV_A_ &w->io);
4881 4886
4882#if EV_FORK_ENABLE 4887#if EV_FORK_ENABLE
4883void 4888void
4884ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT 4889ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4885{ 4890{
4886 if (expect_false (ev_is_active (w))) 4891 if (ecb_expect_false (ev_is_active (w)))
4887 return; 4892 return;
4888 4893
4889 EV_FREQUENT_CHECK; 4894 EV_FREQUENT_CHECK;
4890 4895
4891 ev_start (EV_A_ (W)w, ++forkcnt); 4896 ev_start (EV_A_ (W)w, ++forkcnt);
4897 4902
4898void 4903void
4899ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT 4904ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4900{ 4905{
4901 clear_pending (EV_A_ (W)w); 4906 clear_pending (EV_A_ (W)w);
4902 if (expect_false (!ev_is_active (w))) 4907 if (ecb_expect_false (!ev_is_active (w)))
4903 return; 4908 return;
4904 4909
4905 EV_FREQUENT_CHECK; 4910 EV_FREQUENT_CHECK;
4906 4911
4907 { 4912 {
4919 4924
4920#if EV_CLEANUP_ENABLE 4925#if EV_CLEANUP_ENABLE
4921void 4926void
4922ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4927ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4923{ 4928{
4924 if (expect_false (ev_is_active (w))) 4929 if (ecb_expect_false (ev_is_active (w)))
4925 return; 4930 return;
4926 4931
4927 EV_FREQUENT_CHECK; 4932 EV_FREQUENT_CHECK;
4928 4933
4929 ev_start (EV_A_ (W)w, ++cleanupcnt); 4934 ev_start (EV_A_ (W)w, ++cleanupcnt);
4937 4942
4938void 4943void
4939ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4944ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4940{ 4945{
4941 clear_pending (EV_A_ (W)w); 4946 clear_pending (EV_A_ (W)w);
4942 if (expect_false (!ev_is_active (w))) 4947 if (ecb_expect_false (!ev_is_active (w)))
4943 return; 4948 return;
4944 4949
4945 EV_FREQUENT_CHECK; 4950 EV_FREQUENT_CHECK;
4946 ev_ref (EV_A); 4951 ev_ref (EV_A);
4947 4952
4960 4965
4961#if EV_ASYNC_ENABLE 4966#if EV_ASYNC_ENABLE
4962void 4967void
4963ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT 4968ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4964{ 4969{
4965 if (expect_false (ev_is_active (w))) 4970 if (ecb_expect_false (ev_is_active (w)))
4966 return; 4971 return;
4967 4972
4968 w->sent = 0; 4973 w->sent = 0;
4969 4974
4970 evpipe_init (EV_A); 4975 evpipe_init (EV_A);
4980 4985
4981void 4986void
4982ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT 4987ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4983{ 4988{
4984 clear_pending (EV_A_ (W)w); 4989 clear_pending (EV_A_ (W)w);
4985 if (expect_false (!ev_is_active (w))) 4990 if (ecb_expect_false (!ev_is_active (w)))
4986 return; 4991 return;
4987 4992
4988 EV_FREQUENT_CHECK; 4993 EV_FREQUENT_CHECK;
4989 4994
4990 { 4995 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines