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

Comparing libev/ev.c (file contents):
Revision 1.490 by root, Thu Jun 20 22:44:59 2019 UTC vs.
Revision 1.500 by root, Mon Jul 1 20:47:37 2019 UTC

115# else 115# else
116# undef EV_USE_EPOLL 116# undef EV_USE_EPOLL
117# define EV_USE_EPOLL 0 117# define EV_USE_EPOLL 0
118# endif 118# endif
119 119
120# if HAVE_LINUX_AIO_ABI_H
121# ifndef EV_USE_LINUXAIO
122# define EV_USE_LINUXAIO EV_FEATURE_BACKENDS
123# endif
124# else
125# undef EV_USE_LINUXAIO
126# define EV_USE_LINUXAIO 0
127# endif
128
120# if HAVE_KQUEUE && HAVE_SYS_EVENT_H 129# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
121# ifndef EV_USE_KQUEUE 130# ifndef EV_USE_KQUEUE
122# define EV_USE_KQUEUE EV_FEATURE_BACKENDS 131# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
123# endif 132# endif
124# else 133# else
316#ifndef EV_USE_PORT 325#ifndef EV_USE_PORT
317# define EV_USE_PORT 0 326# define EV_USE_PORT 0
318#endif 327#endif
319 328
320#ifndef EV_USE_LINUXAIO 329#ifndef EV_USE_LINUXAIO
330# if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */
331# define EV_USE_LINUXAIO 1
332# else
321# define EV_USE_LINUXAIO 0 333# define EV_USE_LINUXAIO 0
334# endif
322#endif 335#endif
323 336
324#ifndef EV_USE_INOTIFY 337#ifndef EV_USE_INOTIFY
325# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 338# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
326# define EV_USE_INOTIFY EV_FEATURE_OS 339# define EV_USE_INOTIFY EV_FEATURE_OS
383/* aix's poll.h seems to cause lots of trouble */ 396/* aix's poll.h seems to cause lots of trouble */
384#ifdef _AIX 397#ifdef _AIX
385/* AIX has a completely broken poll.h header */ 398/* AIX has a completely broken poll.h header */
386# undef EV_USE_POLL 399# undef EV_USE_POLL
387# define EV_USE_POLL 0 400# define EV_USE_POLL 0
388#endif
389
390#if EV_USE_LINUXAIO
391# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
392#endif 401#endif
393 402
394/* 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, */
395/* which makes programs even slower. might work on other unices, too. */ 404/* which makes programs even slower. might work on other unices, too. */
396#if EV_USE_CLOCK_SYSCALL 405#if EV_USE_CLOCK_SYSCALL
424 433
425#if !EV_USE_NANOSLEEP 434#if !EV_USE_NANOSLEEP
426/* hp-ux has it in sys/time.h, which we unconditionally include above */ 435/* hp-ux has it in sys/time.h, which we unconditionally include above */
427# if !defined _WIN32 && !defined __hpux 436# if !defined _WIN32 && !defined __hpux
428# include <sys/select.h> 437# include <sys/select.h>
438# endif
439#endif
440
441#if EV_USE_LINUXAIO
442# include <sys/syscall.h>
443# if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */
444# undef EV_USE_LINUXAIO
445# define EV_USE_LINUXAIO 0
429# endif 446# endif
430#endif 447#endif
431 448
432#if EV_USE_INOTIFY 449#if EV_USE_INOTIFY
433# include <sys/statfs.h> 450# include <sys/statfs.h>
542 559
543#ifndef ECB_H 560#ifndef ECB_H
544#define ECB_H 561#define ECB_H
545 562
546/* 16 bits major, 16 bits minor */ 563/* 16 bits major, 16 bits minor */
547#define ECB_VERSION 0x00010005 564#define ECB_VERSION 0x00010006
548 565
549#ifdef _WIN32 566#ifdef _WIN32
550 typedef signed char int8_t; 567 typedef signed char int8_t;
551 typedef unsigned char uint8_t; 568 typedef unsigned char uint8_t;
552 typedef signed short int16_t; 569 typedef signed short int16_t;
666 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 683 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
667#endif 684#endif
668 685
669#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
670 #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")
671 #if __i386 || __i386__ 689 #if __i386 || __i386__
672 #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")
673 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 691 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
674 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") 692 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
675 #elif ECB_GCC_AMD64 693 #elif ECB_GCC_AMD64
725 #if ECB_GCC_VERSION(4,7) 743 #if ECB_GCC_VERSION(4,7)
726 /* see comment below (stdatomic.h) about the C11 memory model. */ 744 /* see comment below (stdatomic.h) about the C11 memory model. */
727 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 745 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
728 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 746 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
729 #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)
730 749
731 #elif ECB_CLANG_EXTENSION(c_atomic) 750 #elif ECB_CLANG_EXTENSION(c_atomic)
732 /* see comment below (stdatomic.h) about the C11 memory model. */ 751 /* see comment below (stdatomic.h) about the C11 memory model. */
733 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 752 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
734 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 753 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
735 #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)
736 756
737 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 757 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
738 #define ECB_MEMORY_FENCE __sync_synchronize () 758 #define ECB_MEMORY_FENCE __sync_synchronize ()
739 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 759 #elif _MSC_VER >= 1500 /* VC++ 2008 */
740 /* 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... */
750 #elif defined _WIN32 770 #elif defined _WIN32
751 #include <WinNT.h> 771 #include <WinNT.h>
752 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 772 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
753 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 773 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
754 #include <mbarrier.h> 774 #include <mbarrier.h>
755 #define ECB_MEMORY_FENCE __machine_rw_barrier () 775 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
756 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 776 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
757 #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 ()
758 #elif __xlC__ 779 #elif __xlC__
759 #define ECB_MEMORY_FENCE __sync () 780 #define ECB_MEMORY_FENCE __sync ()
760 #endif 781 #endif
761#endif 782#endif
762 783
763#ifndef ECB_MEMORY_FENCE 784#ifndef ECB_MEMORY_FENCE
764 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
765 /* 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, */
766 /* not just C11 atomics and atomic accesses */ 787 /* not just C11 atomics and atomic accesses */
767 #include <stdatomic.h> 788 #include <stdatomic.h>
768 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
769 /* any fence other than seq_cst, which isn't very efficient for us. */
770 /* Why that is, we don't know - either the C11 memory model is quite useless */
771 /* for most usages, or gcc and clang have a bug */
772 /* I *currently* lean towards the latter, and inefficiently implement */
773 /* all three of ecb's fences as a seq_cst fence */
774 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
775 /* for all __atomic_thread_fence's except seq_cst */
776 #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)
777 #endif 792 #endif
778#endif 793#endif
779 794
780#ifndef ECB_MEMORY_FENCE 795#ifndef ECB_MEMORY_FENCE
781 #if !ECB_AVOID_PTHREADS 796 #if !ECB_AVOID_PTHREADS
799 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 814 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
800#endif 815#endif
801 816
802#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 817#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
803 #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 */
804#endif 823#endif
805 824
806/*****************************************************************************/ 825/*****************************************************************************/
807 826
808#if ECB_CPP 827#if ECB_CPP
1517/* ECB.H END */ 1536/* ECB.H END */
1518 1537
1519#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 1538#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
1520/* 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
1521 * 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
1522 * 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
1523 * libev, in which cases the memory fences become nops. 1542 * libev, in which cases the memory fences become nops.
1524 * alternatively, you can remove this #error and link against libpthread, 1543 * alternatively, you can remove this #error and link against libpthread,
1525 * which will then provide the memory fences. 1544 * which will then provide the memory fences.
1526 */ 1545 */
1527# error "memory fences not defined for your architecture, please report" 1546# error "memory fences not defined for your architecture, please report"
1531# define ECB_MEMORY_FENCE do { } while (0) 1550# define ECB_MEMORY_FENCE do { } while (0)
1532# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 1551# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
1533# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 1552# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
1534#endif 1553#endif
1535 1554
1536#define expect_false(cond) ecb_expect_false (cond)
1537#define expect_true(cond) ecb_expect_true (cond)
1538#define noinline ecb_noinline
1539
1540#define inline_size ecb_inline 1555#define inline_size ecb_inline
1541 1556
1542#if EV_FEATURE_CODE 1557#if EV_FEATURE_CODE
1543# define inline_speed ecb_inline 1558# define inline_speed ecb_inline
1544#else 1559#else
1545# define inline_speed noinline static 1560# define inline_speed ecb_noinline static
1546#endif 1561#endif
1547 1562
1548#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 1563#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
1549 1564
1550#if EV_MINPRI == EV_MAXPRI 1565#if EV_MINPRI == EV_MAXPRI
1586# include "ev_win32.c" 1601# include "ev_win32.c"
1587#endif 1602#endif
1588 1603
1589/*****************************************************************************/ 1604/*****************************************************************************/
1590 1605
1606#if EV_USE_LINUXAIO
1607# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1608#endif
1609
1591/* define a suitable floor function (only used by periodics atm) */ 1610/* define a suitable floor function (only used by periodics atm) */
1592 1611
1593#if EV_USE_FLOOR 1612#if EV_USE_FLOOR
1594# include <math.h> 1613# include <math.h>
1595# define ev_floor(v) floor (v) 1614# define ev_floor(v) floor (v)
1596#else 1615#else
1597 1616
1598#include <float.h> 1617#include <float.h>
1599 1618
1600/* a floor() replacement function, should be independent of ev_tstamp type */ 1619/* a floor() replacement function, should be independent of ev_tstamp type */
1601noinline 1620ecb_noinline
1602static ev_tstamp 1621static ev_tstamp
1603ev_floor (ev_tstamp v) 1622ev_floor (ev_tstamp v)
1604{ 1623{
1605 /* the choice of shift factor is not terribly important */ 1624 /* the choice of shift factor is not terribly important */
1606#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ 1625#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */
1608#else 1627#else
1609 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; 1628 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.;
1610#endif 1629#endif
1611 1630
1612 /* argument too large for an unsigned long? */ 1631 /* argument too large for an unsigned long? */
1613 if (expect_false (v >= shift)) 1632 if (ecb_expect_false (v >= shift))
1614 { 1633 {
1615 ev_tstamp f; 1634 ev_tstamp f;
1616 1635
1617 if (v == v - 1.) 1636 if (v == v - 1.)
1618 return v; /* very large number */ 1637 return v; /* very large number */
1620 f = shift * ev_floor (v * (1. / shift)); 1639 f = shift * ev_floor (v * (1. / shift));
1621 return f + ev_floor (v - f); 1640 return f + ev_floor (v - f);
1622 } 1641 }
1623 1642
1624 /* special treatment for negative args? */ 1643 /* special treatment for negative args? */
1625 if (expect_false (v < 0.)) 1644 if (ecb_expect_false (v < 0.))
1626 { 1645 {
1627 ev_tstamp f = -ev_floor (-v); 1646 ev_tstamp f = -ev_floor (-v);
1628 1647
1629 return f - (f == v ? 0 : 1); 1648 return f - (f == v ? 0 : 1);
1630 } 1649 }
1639 1658
1640#ifdef __linux 1659#ifdef __linux
1641# include <sys/utsname.h> 1660# include <sys/utsname.h>
1642#endif 1661#endif
1643 1662
1644noinline ecb_cold 1663ecb_noinline ecb_cold
1645static unsigned int 1664static unsigned int
1646ev_linux_version (void) 1665ev_linux_version (void)
1647{ 1666{
1648#ifdef __linux 1667#ifdef __linux
1649 unsigned int v = 0; 1668 unsigned int v = 0;
1679} 1698}
1680 1699
1681/*****************************************************************************/ 1700/*****************************************************************************/
1682 1701
1683#if EV_AVOID_STDIO 1702#if EV_AVOID_STDIO
1684noinline ecb_cold 1703ecb_noinline ecb_cold
1685static void 1704static void
1686ev_printerr (const char *msg) 1705ev_printerr (const char *msg)
1687{ 1706{
1688 write (STDERR_FILENO, msg, strlen (msg)); 1707 write (STDERR_FILENO, msg, strlen (msg));
1689} 1708}
1696ev_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
1697{ 1716{
1698 syserr_cb = cb; 1717 syserr_cb = cb;
1699} 1718}
1700 1719
1701noinline ecb_cold 1720ecb_noinline ecb_cold
1702static void 1721static void
1703ev_syserr (const char *msg) 1722ev_syserr (const char *msg)
1704{ 1723{
1705 if (!msg) 1724 if (!msg)
1706 msg = "(libev) system error"; 1725 msg = "(libev) system error";
1852 static int ev_default_loop_ptr; 1871 static int ev_default_loop_ptr;
1853 1872
1854#endif 1873#endif
1855 1874
1856#if EV_FEATURE_API 1875#if EV_FEATURE_API
1857# 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)
1858# 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)
1859# define EV_INVOKE_PENDING invoke_cb (EV_A) 1878# define EV_INVOKE_PENDING invoke_cb (EV_A)
1860#else 1879#else
1861# define EV_RELEASE_CB (void)0 1880# define EV_RELEASE_CB (void)0
1862# define EV_ACQUIRE_CB (void)0 1881# define EV_ACQUIRE_CB (void)0
1863# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 1882# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
1870#ifndef EV_HAVE_EV_TIME 1889#ifndef EV_HAVE_EV_TIME
1871ev_tstamp 1890ev_tstamp
1872ev_time (void) EV_NOEXCEPT 1891ev_time (void) EV_NOEXCEPT
1873{ 1892{
1874#if EV_USE_REALTIME 1893#if EV_USE_REALTIME
1875 if (expect_true (have_realtime)) 1894 if (ecb_expect_true (have_realtime))
1876 { 1895 {
1877 struct timespec ts; 1896 struct timespec ts;
1878 clock_gettime (CLOCK_REALTIME, &ts); 1897 clock_gettime (CLOCK_REALTIME, &ts);
1879 return ts.tv_sec + ts.tv_nsec * 1e-9; 1898 return ts.tv_sec + ts.tv_nsec * 1e-9;
1880 } 1899 }
1888 1907
1889inline_size ev_tstamp 1908inline_size ev_tstamp
1890get_clock (void) 1909get_clock (void)
1891{ 1910{
1892#if EV_USE_MONOTONIC 1911#if EV_USE_MONOTONIC
1893 if (expect_true (have_monotonic)) 1912 if (ecb_expect_true (have_monotonic))
1894 { 1913 {
1895 struct timespec ts; 1914 struct timespec ts;
1896 clock_gettime (CLOCK_MONOTONIC, &ts); 1915 clock_gettime (CLOCK_MONOTONIC, &ts);
1897 return ts.tv_sec + ts.tv_nsec * 1e-9; 1916 return ts.tv_sec + ts.tv_nsec * 1e-9;
1898 } 1917 }
1960 } 1979 }
1961 1980
1962 return ncur; 1981 return ncur;
1963} 1982}
1964 1983
1965noinline ecb_cold 1984ecb_noinline ecb_cold
1966static void * 1985static void *
1967array_realloc (int elem, void *base, int *cur, int cnt) 1986array_realloc (int elem, void *base, int *cur, int cnt)
1968{ 1987{
1969 *cur = array_nextsize (elem, *cur, cnt); 1988 *cur = array_nextsize (elem, *cur, cnt);
1970 return ev_realloc (base, elem * *cur); 1989 return ev_realloc (base, elem * *cur);
1971} 1990}
1972 1991
1973#define array_needsize_noinit(base,count) 1992#define array_needsize_noinit(base,offset,count)
1974 1993
1975#define array_needsize_zerofill(base,count) \ 1994#define array_needsize_zerofill(base,offset,count) \
1976 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1995 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1977 1996
1978#define array_needsize(type,base,cur,cnt,init) \ 1997#define array_needsize(type,base,cur,cnt,init) \
1979 if (expect_false ((cnt) > (cur))) \ 1998 if (ecb_expect_false ((cnt) > (cur))) \
1980 { \ 1999 { \
1981 ecb_unused int ocur_ = (cur); \ 2000 ecb_unused int ocur_ = (cur); \
1982 (base) = (type *)array_realloc \ 2001 (base) = (type *)array_realloc \
1983 (sizeof (type), (base), &(cur), (cnt)); \ 2002 (sizeof (type), (base), &(cur), (cnt)); \
1984 init ((base) + (ocur_), (cur) - ocur_); \ 2003 init ((base), ocur_, ((cur) - ocur_)); \
1985 } 2004 }
1986 2005
1987#if 0 2006#if 0
1988#define array_slim(type,stem) \ 2007#define array_slim(type,stem) \
1989 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2008 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
1998 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
1999 2018
2000/*****************************************************************************/ 2019/*****************************************************************************/
2001 2020
2002/* dummy callback for pending events */ 2021/* dummy callback for pending events */
2003noinline 2022ecb_noinline
2004static void 2023static void
2005pendingcb (EV_P_ ev_prepare *w, int revents) 2024pendingcb (EV_P_ ev_prepare *w, int revents)
2006{ 2025{
2007} 2026}
2008 2027
2009noinline 2028ecb_noinline
2010void 2029void
2011ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT 2030ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
2012{ 2031{
2013 W w_ = (W)w; 2032 W w_ = (W)w;
2014 int pri = ABSPRI (w_); 2033 int pri = ABSPRI (w_);
2015 2034
2016 if (expect_false (w_->pending)) 2035 if (ecb_expect_false (w_->pending))
2017 pendings [pri][w_->pending - 1].events |= revents; 2036 pendings [pri][w_->pending - 1].events |= revents;
2018 else 2037 else
2019 { 2038 {
2020 w_->pending = ++pendingcnt [pri]; 2039 w_->pending = ++pendingcnt [pri];
2021 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);
2072inline_speed void 2091inline_speed void
2073fd_event (EV_P_ int fd, int revents) 2092fd_event (EV_P_ int fd, int revents)
2074{ 2093{
2075 ANFD *anfd = anfds + fd; 2094 ANFD *anfd = anfds + fd;
2076 2095
2077 if (expect_true (!anfd->reify)) 2096 if (ecb_expect_true (!anfd->reify))
2078 fd_event_nocheck (EV_A_ fd, revents); 2097 fd_event_nocheck (EV_A_ fd, revents);
2079} 2098}
2080 2099
2081void 2100void
2082ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT 2101ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2124 ev_io *w; 2143 ev_io *w;
2125 2144
2126 unsigned char o_events = anfd->events; 2145 unsigned char o_events = anfd->events;
2127 unsigned char o_reify = anfd->reify; 2146 unsigned char o_reify = anfd->reify;
2128 2147
2129 anfd->reify = 0; 2148 anfd->reify = 0;
2130 2149
2131 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 2150 /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
2132 { 2151 {
2133 anfd->events = 0; 2152 anfd->events = 0;
2134 2153
2135 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)
2136 anfd->events |= (unsigned char)w->events; 2155 anfd->events |= (unsigned char)w->events;
2152fd_change (EV_P_ int fd, int flags) 2171fd_change (EV_P_ int fd, int flags)
2153{ 2172{
2154 unsigned char reify = anfds [fd].reify; 2173 unsigned char reify = anfds [fd].reify;
2155 anfds [fd].reify |= flags; 2174 anfds [fd].reify |= flags;
2156 2175
2157 if (expect_true (!reify)) 2176 if (ecb_expect_true (!reify))
2158 { 2177 {
2159 ++fdchangecnt; 2178 ++fdchangecnt;
2160 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); 2179 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2161 fdchanges [fdchangecnt - 1] = fd; 2180 fdchanges [fdchangecnt - 1] = fd;
2162 } 2181 }
2185 return fcntl (fd, F_GETFD) != -1; 2204 return fcntl (fd, F_GETFD) != -1;
2186#endif 2205#endif
2187} 2206}
2188 2207
2189/* called on EBADF to verify fds */ 2208/* called on EBADF to verify fds */
2190noinline ecb_cold 2209ecb_noinline ecb_cold
2191static void 2210static void
2192fd_ebadf (EV_P) 2211fd_ebadf (EV_P)
2193{ 2212{
2194 int fd; 2213 int fd;
2195 2214
2198 if (!fd_valid (fd) && errno == EBADF) 2217 if (!fd_valid (fd) && errno == EBADF)
2199 fd_kill (EV_A_ fd); 2218 fd_kill (EV_A_ fd);
2200} 2219}
2201 2220
2202/* 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 */
2203noinline ecb_cold 2222ecb_noinline ecb_cold
2204static void 2223static void
2205fd_enomem (EV_P) 2224fd_enomem (EV_P)
2206{ 2225{
2207 int fd; 2226 int fd;
2208 2227
2213 break; 2232 break;
2214 } 2233 }
2215} 2234}
2216 2235
2217/* 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 */
2218noinline 2237ecb_noinline
2219static void 2238static void
2220fd_rearm_all (EV_P) 2239fd_rearm_all (EV_P)
2221{ 2240{
2222 int fd; 2241 int fd;
2223 2242
2277 ev_tstamp minat; 2296 ev_tstamp minat;
2278 ANHE *minpos; 2297 ANHE *minpos;
2279 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; 2298 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1;
2280 2299
2281 /* find minimum child */ 2300 /* find minimum child */
2282 if (expect_true (pos + DHEAP - 1 < E)) 2301 if (ecb_expect_true (pos + DHEAP - 1 < E))
2283 { 2302 {
2284 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); 2303 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos));
2285 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));
2286 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));
2287 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));
2405 2424
2406/*****************************************************************************/ 2425/*****************************************************************************/
2407 2426
2408#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2427#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2409 2428
2410noinline ecb_cold 2429ecb_noinline ecb_cold
2411static void 2430static void
2412evpipe_init (EV_P) 2431evpipe_init (EV_P)
2413{ 2432{
2414 if (!ev_is_active (&pipe_w)) 2433 if (!ev_is_active (&pipe_w))
2415 { 2434 {
2456inline_speed void 2475inline_speed void
2457evpipe_write (EV_P_ EV_ATOMIC_T *flag) 2476evpipe_write (EV_P_ EV_ATOMIC_T *flag)
2458{ 2477{
2459 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 */
2460 2479
2461 if (expect_true (*flag)) 2480 if (ecb_expect_true (*flag))
2462 return; 2481 return;
2463 2482
2464 *flag = 1; 2483 *flag = 1;
2465 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 */
2466 2485
2543 sig_pending = 0; 2562 sig_pending = 0;
2544 2563
2545 ECB_MEMORY_FENCE; 2564 ECB_MEMORY_FENCE;
2546 2565
2547 for (i = EV_NSIG - 1; i--; ) 2566 for (i = EV_NSIG - 1; i--; )
2548 if (expect_false (signals [i].pending)) 2567 if (ecb_expect_false (signals [i].pending))
2549 ev_feed_signal_event (EV_A_ i + 1); 2568 ev_feed_signal_event (EV_A_ i + 1);
2550 } 2569 }
2551#endif 2570#endif
2552 2571
2553#if EV_ASYNC_ENABLE 2572#if EV_ASYNC_ENABLE
2594#endif 2613#endif
2595 2614
2596 ev_feed_signal (signum); 2615 ev_feed_signal (signum);
2597} 2616}
2598 2617
2599noinline 2618ecb_noinline
2600void 2619void
2601ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT 2620ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2602{ 2621{
2603 WL w; 2622 WL w;
2604 2623
2605 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2624 if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG))
2606 return; 2625 return;
2607 2626
2608 --signum; 2627 --signum;
2609 2628
2610#if EV_MULTIPLICITY 2629#if EV_MULTIPLICITY
2611 /* 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 */
2612 /* or, likely more useful, feeding a signal nobody is waiting for */ 2631 /* or, likely more useful, feeding a signal nobody is waiting for */
2613 2632
2614 if (expect_false (signals [signum].loop != EV_A)) 2633 if (ecb_expect_false (signals [signum].loop != EV_A))
2615 return; 2634 return;
2616#endif 2635#endif
2617 2636
2618 signals [signum].pending = 0; 2637 signals [signum].pending = 0;
2619 ECB_MEMORY_FENCE_RELEASE; 2638 ECB_MEMORY_FENCE_RELEASE;
2712# include "ev_port.c" 2731# include "ev_port.c"
2713#endif 2732#endif
2714#if EV_USE_KQUEUE 2733#if EV_USE_KQUEUE
2715# include "ev_kqueue.c" 2734# include "ev_kqueue.c"
2716#endif 2735#endif
2736#if EV_USE_EPOLL
2737# include "ev_epoll.c"
2738#endif
2717#if EV_USE_LINUXAIO 2739#if EV_USE_LINUXAIO
2718# include "ev_linuxaio.c" 2740# include "ev_linuxaio.c"
2719#endif
2720#if EV_USE_EPOLL
2721# include "ev_epoll.c"
2722#endif 2741#endif
2723#if EV_USE_POLL 2742#if EV_USE_POLL
2724# include "ev_poll.c" 2743# include "ev_poll.c"
2725#endif 2744#endif
2726#if EV_USE_SELECT 2745#if EV_USE_SELECT
2785#endif 2804#endif
2786#ifdef __FreeBSD__ 2805#ifdef __FreeBSD__
2787 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) */
2788#endif 2807#endif
2789 2808
2809 /* TODO: linuxaio is very experimental */
2810#if !EV_RECOMMEND_LINUXAIO
2811 flags &= ~EVBACKEND_LINUXAIO;
2812#endif
2813
2790 return flags; 2814 return flags;
2791} 2815}
2792 2816
2793ecb_cold 2817ecb_cold
2794unsigned int 2818unsigned int
2859 acquire_cb = acquire; 2883 acquire_cb = acquire;
2860} 2884}
2861#endif 2885#endif
2862 2886
2863/* initialise a loop structure, must be zero-initialised */ 2887/* initialise a loop structure, must be zero-initialised */
2864noinline ecb_cold 2888ecb_noinline ecb_cold
2865static void 2889static void
2866loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT 2890loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2867{ 2891{
2868 if (!backend) 2892 if (!backend)
2869 { 2893 {
2974 return; 2998 return;
2975#endif 2999#endif
2976 3000
2977#if EV_CLEANUP_ENABLE 3001#if EV_CLEANUP_ENABLE
2978 /* queue cleanup watchers (and execute them) */ 3002 /* queue cleanup watchers (and execute them) */
2979 if (expect_false (cleanupcnt)) 3003 if (ecb_expect_false (cleanupcnt))
2980 { 3004 {
2981 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); 3005 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
2982 EV_INVOKE_PENDING; 3006 EV_INVOKE_PENDING;
2983 } 3007 }
2984#endif 3008#endif
3138} 3162}
3139 3163
3140#endif /* multiplicity */ 3164#endif /* multiplicity */
3141 3165
3142#if EV_VERIFY 3166#if EV_VERIFY
3143noinline ecb_cold 3167ecb_noinline ecb_cold
3144static void 3168static void
3145verify_watcher (EV_P_ W w) 3169verify_watcher (EV_P_ W w)
3146{ 3170{
3147 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));
3148 3172
3149 if (w->pending) 3173 if (w->pending)
3150 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));
3151} 3175}
3152 3176
3153noinline ecb_cold 3177ecb_noinline ecb_cold
3154static void 3178static void
3155verify_heap (EV_P_ ANHE *heap, int N) 3179verify_heap (EV_P_ ANHE *heap, int N)
3156{ 3180{
3157 int i; 3181 int i;
3158 3182
3164 3188
3165 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 3189 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
3166 } 3190 }
3167} 3191}
3168 3192
3169noinline ecb_cold 3193ecb_noinline ecb_cold
3170static void 3194static void
3171array_verify (EV_P_ W *ws, int cnt) 3195array_verify (EV_P_ W *ws, int cnt)
3172{ 3196{
3173 while (cnt--) 3197 while (cnt--)
3174 { 3198 {
3323 count += pendingcnt [pri]; 3347 count += pendingcnt [pri];
3324 3348
3325 return count; 3349 return count;
3326} 3350}
3327 3351
3328noinline 3352ecb_noinline
3329void 3353void
3330ev_invoke_pending (EV_P) 3354ev_invoke_pending (EV_P)
3331{ 3355{
3332 pendingpri = NUMPRI; 3356 pendingpri = NUMPRI;
3333 3357
3352/* make idle watchers pending. this handles the "call-idle */ 3376/* make idle watchers pending. this handles the "call-idle */
3353/* only when higher priorities are idle" logic */ 3377/* only when higher priorities are idle" logic */
3354inline_size void 3378inline_size void
3355idle_reify (EV_P) 3379idle_reify (EV_P)
3356{ 3380{
3357 if (expect_false (idleall)) 3381 if (ecb_expect_false (idleall))
3358 { 3382 {
3359 int pri; 3383 int pri;
3360 3384
3361 for (pri = NUMPRI; pri--; ) 3385 for (pri = NUMPRI; pri--; )
3362 { 3386 {
3411 } 3435 }
3412} 3436}
3413 3437
3414#if EV_PERIODIC_ENABLE 3438#if EV_PERIODIC_ENABLE
3415 3439
3416noinline 3440ecb_noinline
3417static void 3441static void
3418periodic_recalc (EV_P_ ev_periodic *w) 3442periodic_recalc (EV_P_ ev_periodic *w)
3419{ 3443{
3420 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; 3444 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL;
3421 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);
3424 while (at <= ev_rt_now) 3448 while (at <= ev_rt_now)
3425 { 3449 {
3426 ev_tstamp nat = at + w->interval; 3450 ev_tstamp nat = at + w->interval;
3427 3451
3428 /* when resolution fails us, we use ev_rt_now */ 3452 /* when resolution fails us, we use ev_rt_now */
3429 if (expect_false (nat == at)) 3453 if (ecb_expect_false (nat == at))
3430 { 3454 {
3431 at = ev_rt_now; 3455 at = ev_rt_now;
3432 break; 3456 break;
3433 } 3457 }
3434 3458
3480 } 3504 }
3481} 3505}
3482 3506
3483/* simply recalculate all periodics */ 3507/* simply recalculate all periodics */
3484/* 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? */
3485noinline ecb_cold 3509ecb_noinline ecb_cold
3486static void 3510static void
3487periodics_reschedule (EV_P) 3511periodics_reschedule (EV_P)
3488{ 3512{
3489 int i; 3513 int i;
3490 3514
3504 reheap (periodics, periodiccnt); 3528 reheap (periodics, periodiccnt);
3505} 3529}
3506#endif 3530#endif
3507 3531
3508/* adjust all timers by a given offset */ 3532/* adjust all timers by a given offset */
3509noinline ecb_cold 3533ecb_noinline ecb_cold
3510static void 3534static void
3511timers_reschedule (EV_P_ ev_tstamp adjust) 3535timers_reschedule (EV_P_ ev_tstamp adjust)
3512{ 3536{
3513 int i; 3537 int i;
3514 3538
3524/* also detect if there was a timejump, and act accordingly */ 3548/* also detect if there was a timejump, and act accordingly */
3525inline_speed void 3549inline_speed void
3526time_update (EV_P_ ev_tstamp max_block) 3550time_update (EV_P_ ev_tstamp max_block)
3527{ 3551{
3528#if EV_USE_MONOTONIC 3552#if EV_USE_MONOTONIC
3529 if (expect_true (have_monotonic)) 3553 if (ecb_expect_true (have_monotonic))
3530 { 3554 {
3531 int i; 3555 int i;
3532 ev_tstamp odiff = rtmn_diff; 3556 ev_tstamp odiff = rtmn_diff;
3533 3557
3534 mn_now = get_clock (); 3558 mn_now = get_clock ();
3535 3559
3536 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ 3560 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */
3537 /* interpolate in the meantime */ 3561 /* interpolate in the meantime */
3538 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 3562 if (ecb_expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
3539 { 3563 {
3540 ev_rt_now = rtmn_diff + mn_now; 3564 ev_rt_now = rtmn_diff + mn_now;
3541 return; 3565 return;
3542 } 3566 }
3543 3567
3557 ev_tstamp diff; 3581 ev_tstamp diff;
3558 rtmn_diff = ev_rt_now - mn_now; 3582 rtmn_diff = ev_rt_now - mn_now;
3559 3583
3560 diff = odiff - rtmn_diff; 3584 diff = odiff - rtmn_diff;
3561 3585
3562 if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) 3586 if (ecb_expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP))
3563 return; /* all is well */ 3587 return; /* all is well */
3564 3588
3565 ev_rt_now = ev_time (); 3589 ev_rt_now = ev_time ();
3566 mn_now = get_clock (); 3590 mn_now = get_clock ();
3567 now_floor = mn_now; 3591 now_floor = mn_now;
3576 else 3600 else
3577#endif 3601#endif
3578 { 3602 {
3579 ev_rt_now = ev_time (); 3603 ev_rt_now = ev_time ();
3580 3604
3581 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))
3582 { 3606 {
3583 /* 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 */
3584 timers_reschedule (EV_A_ ev_rt_now - mn_now); 3608 timers_reschedule (EV_A_ ev_rt_now - mn_now);
3585#if EV_PERIODIC_ENABLE 3609#if EV_PERIODIC_ENABLE
3586 periodics_reschedule (EV_A); 3610 periodics_reschedule (EV_A);
3609#if EV_VERIFY >= 2 3633#if EV_VERIFY >= 2
3610 ev_verify (EV_A); 3634 ev_verify (EV_A);
3611#endif 3635#endif
3612 3636
3613#ifndef _WIN32 3637#ifndef _WIN32
3614 if (expect_false (curpid)) /* penalise the forking check even more */ 3638 if (ecb_expect_false (curpid)) /* penalise the forking check even more */
3615 if (expect_false (getpid () != curpid)) 3639 if (ecb_expect_false (getpid () != curpid))
3616 { 3640 {
3617 curpid = getpid (); 3641 curpid = getpid ();
3618 postfork = 1; 3642 postfork = 1;
3619 } 3643 }
3620#endif 3644#endif
3621 3645
3622#if EV_FORK_ENABLE 3646#if EV_FORK_ENABLE
3623 /* we might have forked, so queue fork handlers */ 3647 /* we might have forked, so queue fork handlers */
3624 if (expect_false (postfork)) 3648 if (ecb_expect_false (postfork))
3625 if (forkcnt) 3649 if (forkcnt)
3626 { 3650 {
3627 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 3651 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
3628 EV_INVOKE_PENDING; 3652 EV_INVOKE_PENDING;
3629 } 3653 }
3630#endif 3654#endif
3631 3655
3632#if EV_PREPARE_ENABLE 3656#if EV_PREPARE_ENABLE
3633 /* queue prepare watchers (and execute them) */ 3657 /* queue prepare watchers (and execute them) */
3634 if (expect_false (preparecnt)) 3658 if (ecb_expect_false (preparecnt))
3635 { 3659 {
3636 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 3660 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
3637 EV_INVOKE_PENDING; 3661 EV_INVOKE_PENDING;
3638 } 3662 }
3639#endif 3663#endif
3640 3664
3641 if (expect_false (loop_done)) 3665 if (ecb_expect_false (loop_done))
3642 break; 3666 break;
3643 3667
3644 /* we might have forked, so reify kernel state if necessary */ 3668 /* we might have forked, so reify kernel state if necessary */
3645 if (expect_false (postfork)) 3669 if (ecb_expect_false (postfork))
3646 loop_fork (EV_A); 3670 loop_fork (EV_A);
3647 3671
3648 /* update fd-related kernel structures */ 3672 /* update fd-related kernel structures */
3649 fd_reify (EV_A); 3673 fd_reify (EV_A);
3650 3674
3662 /* from now on, we want a pipe-wake-up */ 3686 /* from now on, we want a pipe-wake-up */
3663 pipe_write_wanted = 1; 3687 pipe_write_wanted = 1;
3664 3688
3665 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 */
3666 3690
3667 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 3691 if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
3668 { 3692 {
3669 waittime = MAX_BLOCKTIME; 3693 waittime = MAX_BLOCKTIME;
3670 3694
3671 if (timercnt) 3695 if (timercnt)
3672 { 3696 {
3681 if (waittime > to) waittime = to; 3705 if (waittime > to) waittime = to;
3682 } 3706 }
3683#endif 3707#endif
3684 3708
3685 /* don't let timeouts decrease the waittime below timeout_blocktime */ 3709 /* don't let timeouts decrease the waittime below timeout_blocktime */
3686 if (expect_false (waittime < timeout_blocktime)) 3710 if (ecb_expect_false (waittime < timeout_blocktime))
3687 waittime = timeout_blocktime; 3711 waittime = timeout_blocktime;
3688 3712
3689 /* 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 */
3690 /* to pass a minimum nonzero value to the backend */ 3714 /* to pass a minimum nonzero value to the backend */
3691 if (expect_false (waittime < backend_mintime)) 3715 if (ecb_expect_false (waittime < backend_mintime))
3692 waittime = backend_mintime; 3716 waittime = backend_mintime;
3693 3717
3694 /* extra check because io_blocktime is commonly 0 */ 3718 /* extra check because io_blocktime is commonly 0 */
3695 if (expect_false (io_blocktime)) 3719 if (ecb_expect_false (io_blocktime))
3696 { 3720 {
3697 sleeptime = io_blocktime - (mn_now - prev_mn_now); 3721 sleeptime = io_blocktime - (mn_now - prev_mn_now);
3698 3722
3699 if (sleeptime > waittime - backend_mintime) 3723 if (sleeptime > waittime - backend_mintime)
3700 sleeptime = waittime - backend_mintime; 3724 sleeptime = waittime - backend_mintime;
3701 3725
3702 if (expect_true (sleeptime > 0.)) 3726 if (ecb_expect_true (sleeptime > 0.))
3703 { 3727 {
3704 ev_sleep (sleeptime); 3728 ev_sleep (sleeptime);
3705 waittime -= sleeptime; 3729 waittime -= sleeptime;
3706 } 3730 }
3707 } 3731 }
3721 { 3745 {
3722 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)));
3723 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3747 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3724 } 3748 }
3725 3749
3726
3727 /* update ev_rt_now, do magic */ 3750 /* update ev_rt_now, do magic */
3728 time_update (EV_A_ waittime + sleeptime); 3751 time_update (EV_A_ waittime + sleeptime);
3729 } 3752 }
3730 3753
3731 /* queue pending timers and reschedule them */ 3754 /* queue pending timers and reschedule them */
3739 idle_reify (EV_A); 3762 idle_reify (EV_A);
3740#endif 3763#endif
3741 3764
3742#if EV_CHECK_ENABLE 3765#if EV_CHECK_ENABLE
3743 /* queue check watchers, to be executed first */ 3766 /* queue check watchers, to be executed first */
3744 if (expect_false (checkcnt)) 3767 if (ecb_expect_false (checkcnt))
3745 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 3768 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
3746#endif 3769#endif
3747 3770
3748 EV_INVOKE_PENDING; 3771 EV_INVOKE_PENDING;
3749 } 3772 }
3750 while (expect_true ( 3773 while (ecb_expect_true (
3751 activecnt 3774 activecnt
3752 && !loop_done 3775 && !loop_done
3753 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) 3776 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
3754 )); 3777 ));
3755 3778
3819inline_size void 3842inline_size void
3820wlist_del (WL *head, WL elem) 3843wlist_del (WL *head, WL elem)
3821{ 3844{
3822 while (*head) 3845 while (*head)
3823 { 3846 {
3824 if (expect_true (*head == elem)) 3847 if (ecb_expect_true (*head == elem))
3825 { 3848 {
3826 *head = elem->next; 3849 *head = elem->next;
3827 break; 3850 break;
3828 } 3851 }
3829 3852
3846ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT 3869ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3847{ 3870{
3848 W w_ = (W)w; 3871 W w_ = (W)w;
3849 int pending = w_->pending; 3872 int pending = w_->pending;
3850 3873
3851 if (expect_true (pending)) 3874 if (ecb_expect_true (pending))
3852 { 3875 {
3853 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; 3876 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
3854 p->w = (W)&pending_w; 3877 p->w = (W)&pending_w;
3855 w_->pending = 0; 3878 w_->pending = 0;
3856 return p->events; 3879 return p->events;
3883 w->active = 0; 3906 w->active = 0;
3884} 3907}
3885 3908
3886/*****************************************************************************/ 3909/*****************************************************************************/
3887 3910
3888noinline 3911ecb_noinline
3889void 3912void
3890ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT 3913ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3891{ 3914{
3892 int fd = w->fd; 3915 int fd = w->fd;
3893 3916
3894 if (expect_false (ev_is_active (w))) 3917 if (ecb_expect_false (ev_is_active (w)))
3895 return; 3918 return;
3896 3919
3897 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3920 assert (("libev: ev_io_start called with negative fd", fd >= 0));
3898 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))));
3899 3922
3923#if EV_VERIFY >= 2
3924 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3925#endif
3900 EV_FREQUENT_CHECK; 3926 EV_FREQUENT_CHECK;
3901 3927
3902 ev_start (EV_A_ (W)w, 1); 3928 ev_start (EV_A_ (W)w, 1);
3903 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); 3929 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3904 wlist_add (&anfds[fd].head, (WL)w); 3930 wlist_add (&anfds[fd].head, (WL)w);
3910 w->events &= ~EV__IOFDSET; 3936 w->events &= ~EV__IOFDSET;
3911 3937
3912 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3913} 3939}
3914 3940
3915noinline 3941ecb_noinline
3916void 3942void
3917ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT 3943ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3918{ 3944{
3919 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3920 if (expect_false (!ev_is_active (w))) 3946 if (ecb_expect_false (!ev_is_active (w)))
3921 return; 3947 return;
3922 3948
3923 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));
3924 3950
3951#if EV_VERIFY >= 2
3952 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3953#endif
3925 EV_FREQUENT_CHECK; 3954 EV_FREQUENT_CHECK;
3926 3955
3927 wlist_del (&anfds[w->fd].head, (WL)w); 3956 wlist_del (&anfds[w->fd].head, (WL)w);
3928 ev_stop (EV_A_ (W)w); 3957 ev_stop (EV_A_ (W)w);
3929 3958
3930 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3959 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3931 3960
3932 EV_FREQUENT_CHECK; 3961 EV_FREQUENT_CHECK;
3933} 3962}
3934 3963
3935noinline 3964ecb_noinline
3936void 3965void
3937ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT 3966ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3938{ 3967{
3939 if (expect_false (ev_is_active (w))) 3968 if (ecb_expect_false (ev_is_active (w)))
3940 return; 3969 return;
3941 3970
3942 ev_at (w) += mn_now; 3971 ev_at (w) += mn_now;
3943 3972
3944 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.));
3955 EV_FREQUENT_CHECK; 3984 EV_FREQUENT_CHECK;
3956 3985
3957 /*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));*/
3958} 3987}
3959 3988
3960noinline 3989ecb_noinline
3961void 3990void
3962ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT 3991ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3963{ 3992{
3964 clear_pending (EV_A_ (W)w); 3993 clear_pending (EV_A_ (W)w);
3965 if (expect_false (!ev_is_active (w))) 3994 if (ecb_expect_false (!ev_is_active (w)))
3966 return; 3995 return;
3967 3996
3968 EV_FREQUENT_CHECK; 3997 EV_FREQUENT_CHECK;
3969 3998
3970 { 3999 {
3972 4001
3973 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));
3974 4003
3975 --timercnt; 4004 --timercnt;
3976 4005
3977 if (expect_true (active < timercnt + HEAP0)) 4006 if (ecb_expect_true (active < timercnt + HEAP0))
3978 { 4007 {
3979 timers [active] = timers [timercnt + HEAP0]; 4008 timers [active] = timers [timercnt + HEAP0];
3980 adjustheap (timers, timercnt, active); 4009 adjustheap (timers, timercnt, active);
3981 } 4010 }
3982 } 4011 }
3986 ev_stop (EV_A_ (W)w); 4015 ev_stop (EV_A_ (W)w);
3987 4016
3988 EV_FREQUENT_CHECK; 4017 EV_FREQUENT_CHECK;
3989} 4018}
3990 4019
3991noinline 4020ecb_noinline
3992void 4021void
3993ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT 4022ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3994{ 4023{
3995 EV_FREQUENT_CHECK; 4024 EV_FREQUENT_CHECK;
3996 4025
4021{ 4050{
4022 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4051 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
4023} 4052}
4024 4053
4025#if EV_PERIODIC_ENABLE 4054#if EV_PERIODIC_ENABLE
4026noinline 4055ecb_noinline
4027void 4056void
4028ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT 4057ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4029{ 4058{
4030 if (expect_false (ev_is_active (w))) 4059 if (ecb_expect_false (ev_is_active (w)))
4031 return; 4060 return;
4032 4061
4033 if (w->reschedule_cb) 4062 if (w->reschedule_cb)
4034 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 4063 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
4035 else if (w->interval) 4064 else if (w->interval)
4052 EV_FREQUENT_CHECK; 4081 EV_FREQUENT_CHECK;
4053 4082
4054 /*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));*/
4055} 4084}
4056 4085
4057noinline 4086ecb_noinline
4058void 4087void
4059ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT 4088ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4060{ 4089{
4061 clear_pending (EV_A_ (W)w); 4090 clear_pending (EV_A_ (W)w);
4062 if (expect_false (!ev_is_active (w))) 4091 if (ecb_expect_false (!ev_is_active (w)))
4063 return; 4092 return;
4064 4093
4065 EV_FREQUENT_CHECK; 4094 EV_FREQUENT_CHECK;
4066 4095
4067 { 4096 {
4069 4098
4070 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));
4071 4100
4072 --periodiccnt; 4101 --periodiccnt;
4073 4102
4074 if (expect_true (active < periodiccnt + HEAP0)) 4103 if (ecb_expect_true (active < periodiccnt + HEAP0))
4075 { 4104 {
4076 periodics [active] = periodics [periodiccnt + HEAP0]; 4105 periodics [active] = periodics [periodiccnt + HEAP0];
4077 adjustheap (periodics, periodiccnt, active); 4106 adjustheap (periodics, periodiccnt, active);
4078 } 4107 }
4079 } 4108 }
4081 ev_stop (EV_A_ (W)w); 4110 ev_stop (EV_A_ (W)w);
4082 4111
4083 EV_FREQUENT_CHECK; 4112 EV_FREQUENT_CHECK;
4084} 4113}
4085 4114
4086noinline 4115ecb_noinline
4087void 4116void
4088ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT 4117ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4089{ 4118{
4090 /* TODO: use adjustheap and recalculation */ 4119 /* TODO: use adjustheap and recalculation */
4091 ev_periodic_stop (EV_A_ w); 4120 ev_periodic_stop (EV_A_ w);
4097# define SA_RESTART 0 4126# define SA_RESTART 0
4098#endif 4127#endif
4099 4128
4100#if EV_SIGNAL_ENABLE 4129#if EV_SIGNAL_ENABLE
4101 4130
4102noinline 4131ecb_noinline
4103void 4132void
4104ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT 4133ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4105{ 4134{
4106 if (expect_false (ev_is_active (w))) 4135 if (ecb_expect_false (ev_is_active (w)))
4107 return; 4136 return;
4108 4137
4109 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));
4110 4139
4111#if EV_MULTIPLICITY 4140#if EV_MULTIPLICITY
4180 } 4209 }
4181 4210
4182 EV_FREQUENT_CHECK; 4211 EV_FREQUENT_CHECK;
4183} 4212}
4184 4213
4185noinline 4214ecb_noinline
4186void 4215void
4187ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT 4216ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4188{ 4217{
4189 clear_pending (EV_A_ (W)w); 4218 clear_pending (EV_A_ (W)w);
4190 if (expect_false (!ev_is_active (w))) 4219 if (ecb_expect_false (!ev_is_active (w)))
4191 return; 4220 return;
4192 4221
4193 EV_FREQUENT_CHECK; 4222 EV_FREQUENT_CHECK;
4194 4223
4195 wlist_del (&signals [w->signum - 1].head, (WL)w); 4224 wlist_del (&signals [w->signum - 1].head, (WL)w);
4228ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT 4257ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4229{ 4258{
4230#if EV_MULTIPLICITY 4259#if EV_MULTIPLICITY
4231 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));
4232#endif 4261#endif
4233 if (expect_false (ev_is_active (w))) 4262 if (ecb_expect_false (ev_is_active (w)))
4234 return; 4263 return;
4235 4264
4236 EV_FREQUENT_CHECK; 4265 EV_FREQUENT_CHECK;
4237 4266
4238 ev_start (EV_A_ (W)w, 1); 4267 ev_start (EV_A_ (W)w, 1);
4243 4272
4244void 4273void
4245ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT 4274ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4246{ 4275{
4247 clear_pending (EV_A_ (W)w); 4276 clear_pending (EV_A_ (W)w);
4248 if (expect_false (!ev_is_active (w))) 4277 if (ecb_expect_false (!ev_is_active (w)))
4249 return; 4278 return;
4250 4279
4251 EV_FREQUENT_CHECK; 4280 EV_FREQUENT_CHECK;
4252 4281
4253 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); 4282 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
4267 4296
4268#define DEF_STAT_INTERVAL 5.0074891 4297#define DEF_STAT_INTERVAL 5.0074891
4269#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4298#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4270#define MIN_STAT_INTERVAL 0.1074891 4299#define MIN_STAT_INTERVAL 0.1074891
4271 4300
4272noinline 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);
4273 4302
4274#if EV_USE_INOTIFY 4303#if EV_USE_INOTIFY
4275 4304
4276/* 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 */
4277# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 4306# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4278 4307
4279noinline 4308ecb_noinline
4280static void 4309static void
4281infy_add (EV_P_ ev_stat *w) 4310infy_add (EV_P_ ev_stat *w)
4282{ 4311{
4283 w->wd = inotify_add_watch (fs_fd, w->path, 4312 w->wd = inotify_add_watch (fs_fd, w->path,
4284 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4313 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4349 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4378 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4350 ev_timer_again (EV_A_ &w->timer); 4379 ev_timer_again (EV_A_ &w->timer);
4351 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4380 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4352} 4381}
4353 4382
4354noinline 4383ecb_noinline
4355static void 4384static void
4356infy_del (EV_P_ ev_stat *w) 4385infy_del (EV_P_ ev_stat *w)
4357{ 4386{
4358 int slot; 4387 int slot;
4359 int wd = w->wd; 4388 int wd = w->wd;
4367 4396
4368 /* remove this watcher, if others are watching it, they will rearm */ 4397 /* remove this watcher, if others are watching it, they will rearm */
4369 inotify_rm_watch (fs_fd, wd); 4398 inotify_rm_watch (fs_fd, wd);
4370} 4399}
4371 4400
4372noinline 4401ecb_noinline
4373static void 4402static void
4374infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4403infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4375{ 4404{
4376 if (slot < 0) 4405 if (slot < 0)
4377 /* overflow, need to check for all hash slots */ 4406 /* overflow, need to check for all hash slots */
4523 w->attr.st_nlink = 0; 4552 w->attr.st_nlink = 0;
4524 else if (!w->attr.st_nlink) 4553 else if (!w->attr.st_nlink)
4525 w->attr.st_nlink = 1; 4554 w->attr.st_nlink = 1;
4526} 4555}
4527 4556
4528noinline 4557ecb_noinline
4529static void 4558static void
4530stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4559stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4531{ 4560{
4532 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4561 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4533 4562
4567} 4596}
4568 4597
4569void 4598void
4570ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT 4599ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4571{ 4600{
4572 if (expect_false (ev_is_active (w))) 4601 if (ecb_expect_false (ev_is_active (w)))
4573 return; 4602 return;
4574 4603
4575 ev_stat_stat (EV_A_ w); 4604 ev_stat_stat (EV_A_ w);
4576 4605
4577 if (w->interval < MIN_STAT_INTERVAL && w->interval) 4606 if (w->interval < MIN_STAT_INTERVAL && w->interval)
4599 4628
4600void 4629void
4601ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT 4630ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4602{ 4631{
4603 clear_pending (EV_A_ (W)w); 4632 clear_pending (EV_A_ (W)w);
4604 if (expect_false (!ev_is_active (w))) 4633 if (ecb_expect_false (!ev_is_active (w)))
4605 return; 4634 return;
4606 4635
4607 EV_FREQUENT_CHECK; 4636 EV_FREQUENT_CHECK;
4608 4637
4609#if EV_USE_INOTIFY 4638#if EV_USE_INOTIFY
4624 4653
4625#if EV_IDLE_ENABLE 4654#if EV_IDLE_ENABLE
4626void 4655void
4627ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT 4656ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4628{ 4657{
4629 if (expect_false (ev_is_active (w))) 4658 if (ecb_expect_false (ev_is_active (w)))
4630 return; 4659 return;
4631 4660
4632 pri_adjust (EV_A_ (W)w); 4661 pri_adjust (EV_A_ (W)w);
4633 4662
4634 EV_FREQUENT_CHECK; 4663 EV_FREQUENT_CHECK;
4648 4677
4649void 4678void
4650ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT 4679ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4651{ 4680{
4652 clear_pending (EV_A_ (W)w); 4681 clear_pending (EV_A_ (W)w);
4653 if (expect_false (!ev_is_active (w))) 4682 if (ecb_expect_false (!ev_is_active (w)))
4654 return; 4683 return;
4655 4684
4656 EV_FREQUENT_CHECK; 4685 EV_FREQUENT_CHECK;
4657 4686
4658 { 4687 {
4671 4700
4672#if EV_PREPARE_ENABLE 4701#if EV_PREPARE_ENABLE
4673void 4702void
4674ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT 4703ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4675{ 4704{
4676 if (expect_false (ev_is_active (w))) 4705 if (ecb_expect_false (ev_is_active (w)))
4677 return; 4706 return;
4678 4707
4679 EV_FREQUENT_CHECK; 4708 EV_FREQUENT_CHECK;
4680 4709
4681 ev_start (EV_A_ (W)w, ++preparecnt); 4710 ev_start (EV_A_ (W)w, ++preparecnt);
4687 4716
4688void 4717void
4689ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT 4718ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4690{ 4719{
4691 clear_pending (EV_A_ (W)w); 4720 clear_pending (EV_A_ (W)w);
4692 if (expect_false (!ev_is_active (w))) 4721 if (ecb_expect_false (!ev_is_active (w)))
4693 return; 4722 return;
4694 4723
4695 EV_FREQUENT_CHECK; 4724 EV_FREQUENT_CHECK;
4696 4725
4697 { 4726 {
4709 4738
4710#if EV_CHECK_ENABLE 4739#if EV_CHECK_ENABLE
4711void 4740void
4712ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT 4741ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4713{ 4742{
4714 if (expect_false (ev_is_active (w))) 4743 if (ecb_expect_false (ev_is_active (w)))
4715 return; 4744 return;
4716 4745
4717 EV_FREQUENT_CHECK; 4746 EV_FREQUENT_CHECK;
4718 4747
4719 ev_start (EV_A_ (W)w, ++checkcnt); 4748 ev_start (EV_A_ (W)w, ++checkcnt);
4725 4754
4726void 4755void
4727ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT 4756ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4728{ 4757{
4729 clear_pending (EV_A_ (W)w); 4758 clear_pending (EV_A_ (W)w);
4730 if (expect_false (!ev_is_active (w))) 4759 if (ecb_expect_false (!ev_is_active (w)))
4731 return; 4760 return;
4732 4761
4733 EV_FREQUENT_CHECK; 4762 EV_FREQUENT_CHECK;
4734 4763
4735 { 4764 {
4744 EV_FREQUENT_CHECK; 4773 EV_FREQUENT_CHECK;
4745} 4774}
4746#endif 4775#endif
4747 4776
4748#if EV_EMBED_ENABLE 4777#if EV_EMBED_ENABLE
4749noinline 4778ecb_noinline
4750void 4779void
4751ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT 4780ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4752{ 4781{
4753 ev_run (w->other, EVRUN_NOWAIT); 4782 ev_run (w->other, EVRUN_NOWAIT);
4754} 4783}
4806#endif 4835#endif
4807 4836
4808void 4837void
4809ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT 4838ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4810{ 4839{
4811 if (expect_false (ev_is_active (w))) 4840 if (ecb_expect_false (ev_is_active (w)))
4812 return; 4841 return;
4813 4842
4814 { 4843 {
4815 EV_P = w->other; 4844 EV_P = w->other;
4816 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 ()));
4838 4867
4839void 4868void
4840ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT 4869ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4841{ 4870{
4842 clear_pending (EV_A_ (W)w); 4871 clear_pending (EV_A_ (W)w);
4843 if (expect_false (!ev_is_active (w))) 4872 if (ecb_expect_false (!ev_is_active (w)))
4844 return; 4873 return;
4845 4874
4846 EV_FREQUENT_CHECK; 4875 EV_FREQUENT_CHECK;
4847 4876
4848 ev_io_stop (EV_A_ &w->io); 4877 ev_io_stop (EV_A_ &w->io);
4857 4886
4858#if EV_FORK_ENABLE 4887#if EV_FORK_ENABLE
4859void 4888void
4860ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT 4889ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4861{ 4890{
4862 if (expect_false (ev_is_active (w))) 4891 if (ecb_expect_false (ev_is_active (w)))
4863 return; 4892 return;
4864 4893
4865 EV_FREQUENT_CHECK; 4894 EV_FREQUENT_CHECK;
4866 4895
4867 ev_start (EV_A_ (W)w, ++forkcnt); 4896 ev_start (EV_A_ (W)w, ++forkcnt);
4873 4902
4874void 4903void
4875ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT 4904ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4876{ 4905{
4877 clear_pending (EV_A_ (W)w); 4906 clear_pending (EV_A_ (W)w);
4878 if (expect_false (!ev_is_active (w))) 4907 if (ecb_expect_false (!ev_is_active (w)))
4879 return; 4908 return;
4880 4909
4881 EV_FREQUENT_CHECK; 4910 EV_FREQUENT_CHECK;
4882 4911
4883 { 4912 {
4895 4924
4896#if EV_CLEANUP_ENABLE 4925#if EV_CLEANUP_ENABLE
4897void 4926void
4898ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4927ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4899{ 4928{
4900 if (expect_false (ev_is_active (w))) 4929 if (ecb_expect_false (ev_is_active (w)))
4901 return; 4930 return;
4902 4931
4903 EV_FREQUENT_CHECK; 4932 EV_FREQUENT_CHECK;
4904 4933
4905 ev_start (EV_A_ (W)w, ++cleanupcnt); 4934 ev_start (EV_A_ (W)w, ++cleanupcnt);
4913 4942
4914void 4943void
4915ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4944ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4916{ 4945{
4917 clear_pending (EV_A_ (W)w); 4946 clear_pending (EV_A_ (W)w);
4918 if (expect_false (!ev_is_active (w))) 4947 if (ecb_expect_false (!ev_is_active (w)))
4919 return; 4948 return;
4920 4949
4921 EV_FREQUENT_CHECK; 4950 EV_FREQUENT_CHECK;
4922 ev_ref (EV_A); 4951 ev_ref (EV_A);
4923 4952
4936 4965
4937#if EV_ASYNC_ENABLE 4966#if EV_ASYNC_ENABLE
4938void 4967void
4939ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT 4968ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4940{ 4969{
4941 if (expect_false (ev_is_active (w))) 4970 if (ecb_expect_false (ev_is_active (w)))
4942 return; 4971 return;
4943 4972
4944 w->sent = 0; 4973 w->sent = 0;
4945 4974
4946 evpipe_init (EV_A); 4975 evpipe_init (EV_A);
4956 4985
4957void 4986void
4958ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT 4987ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4959{ 4988{
4960 clear_pending (EV_A_ (W)w); 4989 clear_pending (EV_A_ (W)w);
4961 if (expect_false (!ev_is_active (w))) 4990 if (ecb_expect_false (!ev_is_active (w)))
4962 return; 4991 return;
4963 4992
4964 EV_FREQUENT_CHECK; 4993 EV_FREQUENT_CHECK;
4965 4994
4966 { 4995 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines