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

Comparing libev/ev.c (file contents):
Revision 1.491 by root, Thu Jun 20 23:14:53 2019 UTC vs.
Revision 1.500 by root, Mon Jul 1 20:47:37 2019 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines