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