1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007-2018 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
162 | # define EV_USE_EVENTFD 0 |
162 | # define EV_USE_EVENTFD 0 |
163 | # endif |
163 | # endif |
164 | |
164 | |
165 | #endif |
165 | #endif |
166 | |
166 | |
|
|
167 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
168 | * a limit of 1024 into their select. Where people have brains, |
|
|
169 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
170 | * ordered to have a vacuum, or they do anything for money. |
|
|
171 | * This might help. Or not. |
|
|
172 | * Note that this must be defined early, as other include files |
|
|
173 | * will rely on this define as well. |
|
|
174 | */ |
|
|
175 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
176 | |
167 | #include <stdlib.h> |
177 | #include <stdlib.h> |
168 | #include <string.h> |
178 | #include <string.h> |
169 | #include <fcntl.h> |
179 | #include <fcntl.h> |
170 | #include <stddef.h> |
180 | #include <stddef.h> |
171 | |
181 | |
… | |
… | |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
218 | # ifndef EV_SELECT_IS_WINSOCKET |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
219 | # define EV_SELECT_IS_WINSOCKET 1 |
210 | # endif |
220 | # endif |
211 | # undef EV_AVOID_STDIO |
221 | # undef EV_AVOID_STDIO |
212 | #endif |
222 | #endif |
213 | |
|
|
214 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
215 | * a limit of 1024 into their select. Where people have brains, |
|
|
216 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
217 | * ordered to have a vacuum, or they do anything for money. |
|
|
218 | * This might help. Or not. |
|
|
219 | */ |
|
|
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
221 | |
223 | |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
224 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
223 | |
225 | |
224 | /* try to deduce the maximum number of signals on this platform */ |
226 | /* try to deduce the maximum number of signals on this platform */ |
225 | #if defined EV_NSIG |
227 | #if defined EV_NSIG |
… | |
… | |
363 | |
365 | |
364 | #ifndef EV_HEAP_CACHE_AT |
366 | #ifndef EV_HEAP_CACHE_AT |
365 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
367 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
366 | #endif |
368 | #endif |
367 | |
369 | |
368 | #ifdef ANDROID |
370 | #ifdef __ANDROID__ |
369 | /* supposedly, android doesn't typedef fd_mask */ |
371 | /* supposedly, android doesn't typedef fd_mask */ |
370 | # undef EV_USE_SELECT |
372 | # undef EV_USE_SELECT |
371 | # define EV_USE_SELECT 0 |
373 | # define EV_USE_SELECT 0 |
372 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
374 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
373 | # undef EV_USE_CLOCK_SYSCALL |
375 | # undef EV_USE_CLOCK_SYSCALL |
… | |
… | |
607 | #define ECB_CLANG_EXTENSION(x) 0 |
609 | #define ECB_CLANG_EXTENSION(x) 0 |
608 | #endif |
610 | #endif |
609 | |
611 | |
610 | #define ECB_CPP (__cplusplus+0) |
612 | #define ECB_CPP (__cplusplus+0) |
611 | #define ECB_CPP11 (__cplusplus >= 201103L) |
613 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
614 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
615 | #define ECB_CPP17 (__cplusplus >= 201703L) |
612 | |
616 | |
613 | #if ECB_CPP |
617 | #if ECB_CPP |
614 | #define ECB_C 0 |
618 | #define ECB_C 0 |
615 | #define ECB_STDC_VERSION 0 |
619 | #define ECB_STDC_VERSION 0 |
616 | #else |
620 | #else |
… | |
… | |
618 | #define ECB_STDC_VERSION __STDC_VERSION__ |
622 | #define ECB_STDC_VERSION __STDC_VERSION__ |
619 | #endif |
623 | #endif |
620 | |
624 | |
621 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
625 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
622 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
626 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
627 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
623 | |
628 | |
624 | #if ECB_CPP |
629 | #if ECB_CPP |
625 | #define ECB_EXTERN_C extern "C" |
630 | #define ECB_EXTERN_C extern "C" |
626 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
631 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
627 | #define ECB_EXTERN_C_END } |
632 | #define ECB_EXTERN_C_END } |
… | |
… | |
656 | #ifndef ECB_MEMORY_FENCE |
661 | #ifndef ECB_MEMORY_FENCE |
657 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
662 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
658 | #if __i386 || __i386__ |
663 | #if __i386 || __i386__ |
659 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
664 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
660 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
661 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
666 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
662 | #elif ECB_GCC_AMD64 |
667 | #elif ECB_GCC_AMD64 |
663 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
668 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
664 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
669 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
670 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
666 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
671 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
667 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
672 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
668 | #elif defined __ARM_ARCH_2__ \ |
673 | #elif defined __ARM_ARCH_2__ \ |
669 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
674 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
670 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
675 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
1527 | #define inline_size ecb_inline |
1532 | #define inline_size ecb_inline |
1528 | |
1533 | |
1529 | #if EV_FEATURE_CODE |
1534 | #if EV_FEATURE_CODE |
1530 | # define inline_speed ecb_inline |
1535 | # define inline_speed ecb_inline |
1531 | #else |
1536 | #else |
1532 | # define inline_speed static noinline |
1537 | # define inline_speed noinline static |
1533 | #endif |
1538 | #endif |
1534 | |
1539 | |
1535 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1540 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1536 | |
1541 | |
1537 | #if EV_MINPRI == EV_MAXPRI |
1542 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
1584 | #else |
1589 | #else |
1585 | |
1590 | |
1586 | #include <float.h> |
1591 | #include <float.h> |
1587 | |
1592 | |
1588 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1593 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
|
|
1594 | noinline |
1589 | static ev_tstamp noinline |
1595 | static ev_tstamp |
1590 | ev_floor (ev_tstamp v) |
1596 | ev_floor (ev_tstamp v) |
1591 | { |
1597 | { |
1592 | /* the choice of shift factor is not terribly important */ |
1598 | /* the choice of shift factor is not terribly important */ |
1593 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1599 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1594 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1600 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
… | |
… | |
1626 | |
1632 | |
1627 | #ifdef __linux |
1633 | #ifdef __linux |
1628 | # include <sys/utsname.h> |
1634 | # include <sys/utsname.h> |
1629 | #endif |
1635 | #endif |
1630 | |
1636 | |
1631 | static unsigned int noinline ecb_cold |
1637 | noinline ecb_cold |
|
|
1638 | static unsigned int |
1632 | ev_linux_version (void) |
1639 | ev_linux_version (void) |
1633 | { |
1640 | { |
1634 | #ifdef __linux |
1641 | #ifdef __linux |
1635 | unsigned int v = 0; |
1642 | unsigned int v = 0; |
1636 | struct utsname buf; |
1643 | struct utsname buf; |
… | |
… | |
1665 | } |
1672 | } |
1666 | |
1673 | |
1667 | /*****************************************************************************/ |
1674 | /*****************************************************************************/ |
1668 | |
1675 | |
1669 | #if EV_AVOID_STDIO |
1676 | #if EV_AVOID_STDIO |
1670 | static void noinline ecb_cold |
1677 | noinline ecb_cold |
|
|
1678 | static void |
1671 | ev_printerr (const char *msg) |
1679 | ev_printerr (const char *msg) |
1672 | { |
1680 | { |
1673 | write (STDERR_FILENO, msg, strlen (msg)); |
1681 | write (STDERR_FILENO, msg, strlen (msg)); |
1674 | } |
1682 | } |
1675 | #endif |
1683 | #endif |
1676 | |
1684 | |
1677 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1685 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1678 | |
1686 | |
1679 | void ecb_cold |
1687 | ecb_cold |
|
|
1688 | void |
1680 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1689 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1681 | { |
1690 | { |
1682 | syserr_cb = cb; |
1691 | syserr_cb = cb; |
1683 | } |
1692 | } |
1684 | |
1693 | |
1685 | static void noinline ecb_cold |
1694 | noinline ecb_cold |
|
|
1695 | static void |
1686 | ev_syserr (const char *msg) |
1696 | ev_syserr (const char *msg) |
1687 | { |
1697 | { |
1688 | if (!msg) |
1698 | if (!msg) |
1689 | msg = "(libev) system error"; |
1699 | msg = "(libev) system error"; |
1690 | |
1700 | |
… | |
… | |
1703 | abort (); |
1713 | abort (); |
1704 | } |
1714 | } |
1705 | } |
1715 | } |
1706 | |
1716 | |
1707 | static void * |
1717 | static void * |
1708 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1718 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1709 | { |
1719 | { |
1710 | /* some systems, notably openbsd and darwin, fail to properly |
1720 | /* some systems, notably openbsd and darwin, fail to properly |
1711 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1721 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1712 | * the single unix specification, so work around them here. |
1722 | * the single unix specification, so work around them here. |
1713 | * recently, also (at least) fedora and debian started breaking it, |
1723 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1719 | |
1729 | |
1720 | free (ptr); |
1730 | free (ptr); |
1721 | return 0; |
1731 | return 0; |
1722 | } |
1732 | } |
1723 | |
1733 | |
1724 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1734 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1725 | |
1735 | |
1726 | void ecb_cold |
1736 | ecb_cold |
|
|
1737 | void |
1727 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1738 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1728 | { |
1739 | { |
1729 | alloc = cb; |
1740 | alloc = cb; |
1730 | } |
1741 | } |
1731 | |
1742 | |
1732 | inline_speed void * |
1743 | inline_speed void * |
… | |
… | |
1849 | |
1860 | |
1850 | /*****************************************************************************/ |
1861 | /*****************************************************************************/ |
1851 | |
1862 | |
1852 | #ifndef EV_HAVE_EV_TIME |
1863 | #ifndef EV_HAVE_EV_TIME |
1853 | ev_tstamp |
1864 | ev_tstamp |
1854 | ev_time (void) EV_THROW |
1865 | ev_time (void) EV_NOEXCEPT |
1855 | { |
1866 | { |
1856 | #if EV_USE_REALTIME |
1867 | #if EV_USE_REALTIME |
1857 | if (expect_true (have_realtime)) |
1868 | if (expect_true (have_realtime)) |
1858 | { |
1869 | { |
1859 | struct timespec ts; |
1870 | struct timespec ts; |
… | |
… | |
1883 | return ev_time (); |
1894 | return ev_time (); |
1884 | } |
1895 | } |
1885 | |
1896 | |
1886 | #if EV_MULTIPLICITY |
1897 | #if EV_MULTIPLICITY |
1887 | ev_tstamp |
1898 | ev_tstamp |
1888 | ev_now (EV_P) EV_THROW |
1899 | ev_now (EV_P) EV_NOEXCEPT |
1889 | { |
1900 | { |
1890 | return ev_rt_now; |
1901 | return ev_rt_now; |
1891 | } |
1902 | } |
1892 | #endif |
1903 | #endif |
1893 | |
1904 | |
1894 | void |
1905 | void |
1895 | ev_sleep (ev_tstamp delay) EV_THROW |
1906 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1896 | { |
1907 | { |
1897 | if (delay > 0.) |
1908 | if (delay > 0.) |
1898 | { |
1909 | { |
1899 | #if EV_USE_NANOSLEEP |
1910 | #if EV_USE_NANOSLEEP |
1900 | struct timespec ts; |
1911 | struct timespec ts; |
1901 | |
1912 | |
1902 | EV_TS_SET (ts, delay); |
1913 | EV_TS_SET (ts, delay); |
1903 | nanosleep (&ts, 0); |
1914 | nanosleep (&ts, 0); |
1904 | #elif defined _WIN32 |
1915 | #elif defined _WIN32 |
|
|
1916 | /* maybe this should round up, as ms is very low resolution */ |
|
|
1917 | /* compared to select (µs) or nanosleep (ns) */ |
1905 | Sleep ((unsigned long)(delay * 1e3)); |
1918 | Sleep ((unsigned long)(delay * 1e3)); |
1906 | #else |
1919 | #else |
1907 | struct timeval tv; |
1920 | struct timeval tv; |
1908 | |
1921 | |
1909 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1922 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1940 | } |
1953 | } |
1941 | |
1954 | |
1942 | return ncur; |
1955 | return ncur; |
1943 | } |
1956 | } |
1944 | |
1957 | |
1945 | static void * noinline ecb_cold |
1958 | noinline ecb_cold |
|
|
1959 | static void * |
1946 | array_realloc (int elem, void *base, int *cur, int cnt) |
1960 | array_realloc (int elem, void *base, int *cur, int cnt) |
1947 | { |
1961 | { |
1948 | *cur = array_nextsize (elem, *cur, cnt); |
1962 | *cur = array_nextsize (elem, *cur, cnt); |
1949 | return ev_realloc (base, elem * *cur); |
1963 | return ev_realloc (base, elem * *cur); |
1950 | } |
1964 | } |
… | |
… | |
1953 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1967 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1954 | |
1968 | |
1955 | #define array_needsize(type,base,cur,cnt,init) \ |
1969 | #define array_needsize(type,base,cur,cnt,init) \ |
1956 | if (expect_false ((cnt) > (cur))) \ |
1970 | if (expect_false ((cnt) > (cur))) \ |
1957 | { \ |
1971 | { \ |
1958 | int ecb_unused ocur_ = (cur); \ |
1972 | ecb_unused int ocur_ = (cur); \ |
1959 | (base) = (type *)array_realloc \ |
1973 | (base) = (type *)array_realloc \ |
1960 | (sizeof (type), (base), &(cur), (cnt)); \ |
1974 | (sizeof (type), (base), &(cur), (cnt)); \ |
1961 | init ((base) + (ocur_), (cur) - ocur_); \ |
1975 | init ((base) + (ocur_), (cur) - ocur_); \ |
1962 | } |
1976 | } |
1963 | |
1977 | |
… | |
… | |
1975 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
1989 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
1976 | |
1990 | |
1977 | /*****************************************************************************/ |
1991 | /*****************************************************************************/ |
1978 | |
1992 | |
1979 | /* dummy callback for pending events */ |
1993 | /* dummy callback for pending events */ |
1980 | static void noinline |
1994 | noinline |
|
|
1995 | static void |
1981 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1996 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1982 | { |
1997 | { |
1983 | } |
1998 | } |
1984 | |
1999 | |
1985 | void noinline |
2000 | noinline |
|
|
2001 | void |
1986 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2002 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1987 | { |
2003 | { |
1988 | W w_ = (W)w; |
2004 | W w_ = (W)w; |
1989 | int pri = ABSPRI (w_); |
2005 | int pri = ABSPRI (w_); |
1990 | |
2006 | |
1991 | if (expect_false (w_->pending)) |
2007 | if (expect_false (w_->pending)) |
… | |
… | |
2052 | if (expect_true (!anfd->reify)) |
2068 | if (expect_true (!anfd->reify)) |
2053 | fd_event_nocheck (EV_A_ fd, revents); |
2069 | fd_event_nocheck (EV_A_ fd, revents); |
2054 | } |
2070 | } |
2055 | |
2071 | |
2056 | void |
2072 | void |
2057 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2073 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2058 | { |
2074 | { |
2059 | if (fd >= 0 && fd < anfdmax) |
2075 | if (fd >= 0 && fd < anfdmax) |
2060 | fd_event_nocheck (EV_A_ fd, revents); |
2076 | fd_event_nocheck (EV_A_ fd, revents); |
2061 | } |
2077 | } |
2062 | |
2078 | |
… | |
… | |
2120 | |
2136 | |
2121 | fdchangecnt = 0; |
2137 | fdchangecnt = 0; |
2122 | } |
2138 | } |
2123 | |
2139 | |
2124 | /* something about the given fd changed */ |
2140 | /* something about the given fd changed */ |
2125 | inline_size void |
2141 | inline_size |
|
|
2142 | void |
2126 | fd_change (EV_P_ int fd, int flags) |
2143 | fd_change (EV_P_ int fd, int flags) |
2127 | { |
2144 | { |
2128 | unsigned char reify = anfds [fd].reify; |
2145 | unsigned char reify = anfds [fd].reify; |
2129 | anfds [fd].reify |= flags; |
2146 | anfds [fd].reify |= flags; |
2130 | |
2147 | |
… | |
… | |
2135 | fdchanges [fdchangecnt - 1] = fd; |
2152 | fdchanges [fdchangecnt - 1] = fd; |
2136 | } |
2153 | } |
2137 | } |
2154 | } |
2138 | |
2155 | |
2139 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2156 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2140 | inline_speed void ecb_cold |
2157 | inline_speed ecb_cold void |
2141 | fd_kill (EV_P_ int fd) |
2158 | fd_kill (EV_P_ int fd) |
2142 | { |
2159 | { |
2143 | ev_io *w; |
2160 | ev_io *w; |
2144 | |
2161 | |
2145 | while ((w = (ev_io *)anfds [fd].head)) |
2162 | while ((w = (ev_io *)anfds [fd].head)) |
… | |
… | |
2148 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2165 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2149 | } |
2166 | } |
2150 | } |
2167 | } |
2151 | |
2168 | |
2152 | /* check whether the given fd is actually valid, for error recovery */ |
2169 | /* check whether the given fd is actually valid, for error recovery */ |
2153 | inline_size int ecb_cold |
2170 | inline_size ecb_cold int |
2154 | fd_valid (int fd) |
2171 | fd_valid (int fd) |
2155 | { |
2172 | { |
2156 | #ifdef _WIN32 |
2173 | #ifdef _WIN32 |
2157 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2174 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2158 | #else |
2175 | #else |
2159 | return fcntl (fd, F_GETFD) != -1; |
2176 | return fcntl (fd, F_GETFD) != -1; |
2160 | #endif |
2177 | #endif |
2161 | } |
2178 | } |
2162 | |
2179 | |
2163 | /* called on EBADF to verify fds */ |
2180 | /* called on EBADF to verify fds */ |
2164 | static void noinline ecb_cold |
2181 | noinline ecb_cold |
|
|
2182 | static void |
2165 | fd_ebadf (EV_P) |
2183 | fd_ebadf (EV_P) |
2166 | { |
2184 | { |
2167 | int fd; |
2185 | int fd; |
2168 | |
2186 | |
2169 | for (fd = 0; fd < anfdmax; ++fd) |
2187 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2171 | if (!fd_valid (fd) && errno == EBADF) |
2189 | if (!fd_valid (fd) && errno == EBADF) |
2172 | fd_kill (EV_A_ fd); |
2190 | fd_kill (EV_A_ fd); |
2173 | } |
2191 | } |
2174 | |
2192 | |
2175 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2193 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2176 | static void noinline ecb_cold |
2194 | noinline ecb_cold |
|
|
2195 | static void |
2177 | fd_enomem (EV_P) |
2196 | fd_enomem (EV_P) |
2178 | { |
2197 | { |
2179 | int fd; |
2198 | int fd; |
2180 | |
2199 | |
2181 | for (fd = anfdmax; fd--; ) |
2200 | for (fd = anfdmax; fd--; ) |
… | |
… | |
2185 | break; |
2204 | break; |
2186 | } |
2205 | } |
2187 | } |
2206 | } |
2188 | |
2207 | |
2189 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2208 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2190 | static void noinline |
2209 | noinline |
|
|
2210 | static void |
2191 | fd_rearm_all (EV_P) |
2211 | fd_rearm_all (EV_P) |
2192 | { |
2212 | { |
2193 | int fd; |
2213 | int fd; |
2194 | |
2214 | |
2195 | for (fd = 0; fd < anfdmax; ++fd) |
2215 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2376 | |
2396 | |
2377 | /*****************************************************************************/ |
2397 | /*****************************************************************************/ |
2378 | |
2398 | |
2379 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2399 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2380 | |
2400 | |
2381 | static void noinline ecb_cold |
2401 | noinline ecb_cold |
|
|
2402 | static void |
2382 | evpipe_init (EV_P) |
2403 | evpipe_init (EV_P) |
2383 | { |
2404 | { |
2384 | if (!ev_is_active (&pipe_w)) |
2405 | if (!ev_is_active (&pipe_w)) |
2385 | { |
2406 | { |
2386 | int fds [2]; |
2407 | int fds [2]; |
… | |
… | |
2457 | #endif |
2478 | #endif |
2458 | { |
2479 | { |
2459 | #ifdef _WIN32 |
2480 | #ifdef _WIN32 |
2460 | WSABUF buf; |
2481 | WSABUF buf; |
2461 | DWORD sent; |
2482 | DWORD sent; |
2462 | buf.buf = &buf; |
2483 | buf.buf = (char *)&buf; |
2463 | buf.len = 1; |
2484 | buf.len = 1; |
2464 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2485 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2465 | #else |
2486 | #else |
2466 | write (evpipe [1], &(evpipe [1]), 1); |
2487 | write (evpipe [1], &(evpipe [1]), 1); |
2467 | #endif |
2488 | #endif |
… | |
… | |
2539 | } |
2560 | } |
2540 | |
2561 | |
2541 | /*****************************************************************************/ |
2562 | /*****************************************************************************/ |
2542 | |
2563 | |
2543 | void |
2564 | void |
2544 | ev_feed_signal (int signum) EV_THROW |
2565 | ev_feed_signal (int signum) EV_NOEXCEPT |
2545 | { |
2566 | { |
2546 | #if EV_MULTIPLICITY |
2567 | #if EV_MULTIPLICITY |
2547 | EV_P; |
2568 | EV_P; |
2548 | ECB_MEMORY_FENCE_ACQUIRE; |
2569 | ECB_MEMORY_FENCE_ACQUIRE; |
2549 | EV_A = signals [signum - 1].loop; |
2570 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2564 | #endif |
2585 | #endif |
2565 | |
2586 | |
2566 | ev_feed_signal (signum); |
2587 | ev_feed_signal (signum); |
2567 | } |
2588 | } |
2568 | |
2589 | |
2569 | void noinline |
2590 | noinline |
|
|
2591 | void |
2570 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2592 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2571 | { |
2593 | { |
2572 | WL w; |
2594 | WL w; |
2573 | |
2595 | |
2574 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2596 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2575 | return; |
2597 | return; |
… | |
… | |
2691 | #endif |
2713 | #endif |
2692 | #if EV_USE_SELECT |
2714 | #if EV_USE_SELECT |
2693 | # include "ev_select.c" |
2715 | # include "ev_select.c" |
2694 | #endif |
2716 | #endif |
2695 | |
2717 | |
2696 | int ecb_cold |
2718 | ecb_cold int |
2697 | ev_version_major (void) EV_THROW |
2719 | ev_version_major (void) EV_NOEXCEPT |
2698 | { |
2720 | { |
2699 | return EV_VERSION_MAJOR; |
2721 | return EV_VERSION_MAJOR; |
2700 | } |
2722 | } |
2701 | |
2723 | |
2702 | int ecb_cold |
2724 | ecb_cold int |
2703 | ev_version_minor (void) EV_THROW |
2725 | ev_version_minor (void) EV_NOEXCEPT |
2704 | { |
2726 | { |
2705 | return EV_VERSION_MINOR; |
2727 | return EV_VERSION_MINOR; |
2706 | } |
2728 | } |
2707 | |
2729 | |
2708 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2730 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2709 | int inline_size ecb_cold |
2731 | inline_size ecb_cold int |
2710 | enable_secure (void) |
2732 | enable_secure (void) |
2711 | { |
2733 | { |
2712 | #ifdef _WIN32 |
2734 | #ifdef _WIN32 |
2713 | return 0; |
2735 | return 0; |
2714 | #else |
2736 | #else |
2715 | return getuid () != geteuid () |
2737 | return getuid () != geteuid () |
2716 | || getgid () != getegid (); |
2738 | || getgid () != getegid (); |
2717 | #endif |
2739 | #endif |
2718 | } |
2740 | } |
2719 | |
2741 | |
2720 | unsigned int ecb_cold |
2742 | ecb_cold |
|
|
2743 | unsigned int |
2721 | ev_supported_backends (void) EV_THROW |
2744 | ev_supported_backends (void) EV_NOEXCEPT |
2722 | { |
2745 | { |
2723 | unsigned int flags = 0; |
2746 | unsigned int flags = 0; |
2724 | |
2747 | |
2725 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2748 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2726 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2749 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2729 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2752 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2730 | |
2753 | |
2731 | return flags; |
2754 | return flags; |
2732 | } |
2755 | } |
2733 | |
2756 | |
2734 | unsigned int ecb_cold |
2757 | ecb_cold |
|
|
2758 | unsigned int |
2735 | ev_recommended_backends (void) EV_THROW |
2759 | ev_recommended_backends (void) EV_NOEXCEPT |
2736 | { |
2760 | { |
2737 | unsigned int flags = ev_supported_backends (); |
2761 | unsigned int flags = ev_supported_backends (); |
2738 | |
2762 | |
2739 | #ifndef __NetBSD__ |
2763 | #ifndef __NetBSD__ |
2740 | /* kqueue is borked on everything but netbsd apparently */ |
2764 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2751 | #endif |
2775 | #endif |
2752 | |
2776 | |
2753 | return flags; |
2777 | return flags; |
2754 | } |
2778 | } |
2755 | |
2779 | |
2756 | unsigned int ecb_cold |
2780 | ecb_cold |
|
|
2781 | unsigned int |
2757 | ev_embeddable_backends (void) EV_THROW |
2782 | ev_embeddable_backends (void) EV_NOEXCEPT |
2758 | { |
2783 | { |
2759 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2784 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2760 | |
2785 | |
2761 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2786 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2762 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2787 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2764 | |
2789 | |
2765 | return flags; |
2790 | return flags; |
2766 | } |
2791 | } |
2767 | |
2792 | |
2768 | unsigned int |
2793 | unsigned int |
2769 | ev_backend (EV_P) EV_THROW |
2794 | ev_backend (EV_P) EV_NOEXCEPT |
2770 | { |
2795 | { |
2771 | return backend; |
2796 | return backend; |
2772 | } |
2797 | } |
2773 | |
2798 | |
2774 | #if EV_FEATURE_API |
2799 | #if EV_FEATURE_API |
2775 | unsigned int |
2800 | unsigned int |
2776 | ev_iteration (EV_P) EV_THROW |
2801 | ev_iteration (EV_P) EV_NOEXCEPT |
2777 | { |
2802 | { |
2778 | return loop_count; |
2803 | return loop_count; |
2779 | } |
2804 | } |
2780 | |
2805 | |
2781 | unsigned int |
2806 | unsigned int |
2782 | ev_depth (EV_P) EV_THROW |
2807 | ev_depth (EV_P) EV_NOEXCEPT |
2783 | { |
2808 | { |
2784 | return loop_depth; |
2809 | return loop_depth; |
2785 | } |
2810 | } |
2786 | |
2811 | |
2787 | void |
2812 | void |
2788 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2813 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2789 | { |
2814 | { |
2790 | io_blocktime = interval; |
2815 | io_blocktime = interval; |
2791 | } |
2816 | } |
2792 | |
2817 | |
2793 | void |
2818 | void |
2794 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2819 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2795 | { |
2820 | { |
2796 | timeout_blocktime = interval; |
2821 | timeout_blocktime = interval; |
2797 | } |
2822 | } |
2798 | |
2823 | |
2799 | void |
2824 | void |
2800 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2825 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2801 | { |
2826 | { |
2802 | userdata = data; |
2827 | userdata = data; |
2803 | } |
2828 | } |
2804 | |
2829 | |
2805 | void * |
2830 | void * |
2806 | ev_userdata (EV_P) EV_THROW |
2831 | ev_userdata (EV_P) EV_NOEXCEPT |
2807 | { |
2832 | { |
2808 | return userdata; |
2833 | return userdata; |
2809 | } |
2834 | } |
2810 | |
2835 | |
2811 | void |
2836 | void |
2812 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
2837 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2813 | { |
2838 | { |
2814 | invoke_cb = invoke_pending_cb; |
2839 | invoke_cb = invoke_pending_cb; |
2815 | } |
2840 | } |
2816 | |
2841 | |
2817 | void |
2842 | void |
2818 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2843 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2819 | { |
2844 | { |
2820 | release_cb = release; |
2845 | release_cb = release; |
2821 | acquire_cb = acquire; |
2846 | acquire_cb = acquire; |
2822 | } |
2847 | } |
2823 | #endif |
2848 | #endif |
2824 | |
2849 | |
2825 | /* initialise a loop structure, must be zero-initialised */ |
2850 | /* initialise a loop structure, must be zero-initialised */ |
2826 | static void noinline ecb_cold |
2851 | noinline ecb_cold |
|
|
2852 | static void |
2827 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2853 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2828 | { |
2854 | { |
2829 | if (!backend) |
2855 | if (!backend) |
2830 | { |
2856 | { |
2831 | origflags = flags; |
2857 | origflags = flags; |
2832 | |
2858 | |
… | |
… | |
2918 | #endif |
2944 | #endif |
2919 | } |
2945 | } |
2920 | } |
2946 | } |
2921 | |
2947 | |
2922 | /* free up a loop structure */ |
2948 | /* free up a loop structure */ |
2923 | void ecb_cold |
2949 | ecb_cold |
|
|
2950 | void |
2924 | ev_loop_destroy (EV_P) |
2951 | ev_loop_destroy (EV_P) |
2925 | { |
2952 | { |
2926 | int i; |
2953 | int i; |
2927 | |
2954 | |
2928 | #if EV_MULTIPLICITY |
2955 | #if EV_MULTIPLICITY |
… | |
… | |
3070 | postfork = 0; |
3097 | postfork = 0; |
3071 | } |
3098 | } |
3072 | |
3099 | |
3073 | #if EV_MULTIPLICITY |
3100 | #if EV_MULTIPLICITY |
3074 | |
3101 | |
|
|
3102 | ecb_cold |
3075 | struct ev_loop * ecb_cold |
3103 | struct ev_loop * |
3076 | ev_loop_new (unsigned int flags) EV_THROW |
3104 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3077 | { |
3105 | { |
3078 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3106 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3079 | |
3107 | |
3080 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3108 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3081 | loop_init (EV_A_ flags); |
3109 | loop_init (EV_A_ flags); |
… | |
… | |
3088 | } |
3116 | } |
3089 | |
3117 | |
3090 | #endif /* multiplicity */ |
3118 | #endif /* multiplicity */ |
3091 | |
3119 | |
3092 | #if EV_VERIFY |
3120 | #if EV_VERIFY |
3093 | static void noinline ecb_cold |
3121 | noinline ecb_cold |
|
|
3122 | static void |
3094 | verify_watcher (EV_P_ W w) |
3123 | verify_watcher (EV_P_ W w) |
3095 | { |
3124 | { |
3096 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3125 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3097 | |
3126 | |
3098 | if (w->pending) |
3127 | if (w->pending) |
3099 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3128 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3100 | } |
3129 | } |
3101 | |
3130 | |
3102 | static void noinline ecb_cold |
3131 | noinline ecb_cold |
|
|
3132 | static void |
3103 | verify_heap (EV_P_ ANHE *heap, int N) |
3133 | verify_heap (EV_P_ ANHE *heap, int N) |
3104 | { |
3134 | { |
3105 | int i; |
3135 | int i; |
3106 | |
3136 | |
3107 | for (i = HEAP0; i < N + HEAP0; ++i) |
3137 | for (i = HEAP0; i < N + HEAP0; ++i) |
… | |
… | |
3112 | |
3142 | |
3113 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3143 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3114 | } |
3144 | } |
3115 | } |
3145 | } |
3116 | |
3146 | |
3117 | static void noinline ecb_cold |
3147 | noinline ecb_cold |
|
|
3148 | static void |
3118 | array_verify (EV_P_ W *ws, int cnt) |
3149 | array_verify (EV_P_ W *ws, int cnt) |
3119 | { |
3150 | { |
3120 | while (cnt--) |
3151 | while (cnt--) |
3121 | { |
3152 | { |
3122 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
3153 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
… | |
… | |
3125 | } |
3156 | } |
3126 | #endif |
3157 | #endif |
3127 | |
3158 | |
3128 | #if EV_FEATURE_API |
3159 | #if EV_FEATURE_API |
3129 | void ecb_cold |
3160 | void ecb_cold |
3130 | ev_verify (EV_P) EV_THROW |
3161 | ev_verify (EV_P) EV_NOEXCEPT |
3131 | { |
3162 | { |
3132 | #if EV_VERIFY |
3163 | #if EV_VERIFY |
3133 | int i; |
3164 | int i; |
3134 | WL w, w2; |
3165 | WL w, w2; |
3135 | |
3166 | |
… | |
… | |
3211 | #endif |
3242 | #endif |
3212 | } |
3243 | } |
3213 | #endif |
3244 | #endif |
3214 | |
3245 | |
3215 | #if EV_MULTIPLICITY |
3246 | #if EV_MULTIPLICITY |
|
|
3247 | ecb_cold |
3216 | struct ev_loop * ecb_cold |
3248 | struct ev_loop * |
3217 | #else |
3249 | #else |
3218 | int |
3250 | int |
3219 | #endif |
3251 | #endif |
3220 | ev_default_loop (unsigned int flags) EV_THROW |
3252 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3221 | { |
3253 | { |
3222 | if (!ev_default_loop_ptr) |
3254 | if (!ev_default_loop_ptr) |
3223 | { |
3255 | { |
3224 | #if EV_MULTIPLICITY |
3256 | #if EV_MULTIPLICITY |
3225 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3257 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3244 | |
3276 | |
3245 | return ev_default_loop_ptr; |
3277 | return ev_default_loop_ptr; |
3246 | } |
3278 | } |
3247 | |
3279 | |
3248 | void |
3280 | void |
3249 | ev_loop_fork (EV_P) EV_THROW |
3281 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3250 | { |
3282 | { |
3251 | postfork = 1; |
3283 | postfork = 1; |
3252 | } |
3284 | } |
3253 | |
3285 | |
3254 | /*****************************************************************************/ |
3286 | /*****************************************************************************/ |
… | |
… | |
3258 | { |
3290 | { |
3259 | EV_CB_INVOKE ((W)w, revents); |
3291 | EV_CB_INVOKE ((W)w, revents); |
3260 | } |
3292 | } |
3261 | |
3293 | |
3262 | unsigned int |
3294 | unsigned int |
3263 | ev_pending_count (EV_P) EV_THROW |
3295 | ev_pending_count (EV_P) EV_NOEXCEPT |
3264 | { |
3296 | { |
3265 | int pri; |
3297 | int pri; |
3266 | unsigned int count = 0; |
3298 | unsigned int count = 0; |
3267 | |
3299 | |
3268 | for (pri = NUMPRI; pri--; ) |
3300 | for (pri = NUMPRI; pri--; ) |
3269 | count += pendingcnt [pri]; |
3301 | count += pendingcnt [pri]; |
3270 | |
3302 | |
3271 | return count; |
3303 | return count; |
3272 | } |
3304 | } |
3273 | |
3305 | |
3274 | void noinline |
3306 | noinline |
|
|
3307 | void |
3275 | ev_invoke_pending (EV_P) |
3308 | ev_invoke_pending (EV_P) |
3276 | { |
3309 | { |
3277 | pendingpri = NUMPRI; |
3310 | pendingpri = NUMPRI; |
3278 | |
3311 | |
3279 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3312 | do |
3280 | { |
3313 | { |
3281 | --pendingpri; |
3314 | --pendingpri; |
3282 | |
3315 | |
|
|
3316 | /* pendingpri possibly gets modified in the inner loop */ |
3283 | while (pendingcnt [pendingpri]) |
3317 | while (pendingcnt [pendingpri]) |
3284 | { |
3318 | { |
3285 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3319 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3286 | |
3320 | |
3287 | p->w->pending = 0; |
3321 | p->w->pending = 0; |
3288 | EV_CB_INVOKE (p->w, p->events); |
3322 | EV_CB_INVOKE (p->w, p->events); |
3289 | EV_FREQUENT_CHECK; |
3323 | EV_FREQUENT_CHECK; |
3290 | } |
3324 | } |
3291 | } |
3325 | } |
|
|
3326 | while (pendingpri); |
3292 | } |
3327 | } |
3293 | |
3328 | |
3294 | #if EV_IDLE_ENABLE |
3329 | #if EV_IDLE_ENABLE |
3295 | /* make idle watchers pending. this handles the "call-idle */ |
3330 | /* make idle watchers pending. this handles the "call-idle */ |
3296 | /* only when higher priorities are idle" logic */ |
3331 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3354 | } |
3389 | } |
3355 | } |
3390 | } |
3356 | |
3391 | |
3357 | #if EV_PERIODIC_ENABLE |
3392 | #if EV_PERIODIC_ENABLE |
3358 | |
3393 | |
3359 | static void noinline |
3394 | noinline |
|
|
3395 | static void |
3360 | periodic_recalc (EV_P_ ev_periodic *w) |
3396 | periodic_recalc (EV_P_ ev_periodic *w) |
3361 | { |
3397 | { |
3362 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3398 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3363 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3399 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3364 | |
3400 | |
… | |
… | |
3422 | } |
3458 | } |
3423 | } |
3459 | } |
3424 | |
3460 | |
3425 | /* simply recalculate all periodics */ |
3461 | /* simply recalculate all periodics */ |
3426 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3462 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3427 | static void noinline ecb_cold |
3463 | noinline ecb_cold |
|
|
3464 | static void |
3428 | periodics_reschedule (EV_P) |
3465 | periodics_reschedule (EV_P) |
3429 | { |
3466 | { |
3430 | int i; |
3467 | int i; |
3431 | |
3468 | |
3432 | /* adjust periodics after time jump */ |
3469 | /* adjust periodics after time jump */ |
… | |
… | |
3445 | reheap (periodics, periodiccnt); |
3482 | reheap (periodics, periodiccnt); |
3446 | } |
3483 | } |
3447 | #endif |
3484 | #endif |
3448 | |
3485 | |
3449 | /* adjust all timers by a given offset */ |
3486 | /* adjust all timers by a given offset */ |
3450 | static void noinline ecb_cold |
3487 | noinline ecb_cold |
|
|
3488 | static void |
3451 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3489 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3452 | { |
3490 | { |
3453 | int i; |
3491 | int i; |
3454 | |
3492 | |
3455 | for (i = 0; i < timercnt; ++i) |
3493 | for (i = 0; i < timercnt; ++i) |
… | |
… | |
3702 | |
3740 | |
3703 | return activecnt; |
3741 | return activecnt; |
3704 | } |
3742 | } |
3705 | |
3743 | |
3706 | void |
3744 | void |
3707 | ev_break (EV_P_ int how) EV_THROW |
3745 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3708 | { |
3746 | { |
3709 | loop_done = how; |
3747 | loop_done = how; |
3710 | } |
3748 | } |
3711 | |
3749 | |
3712 | void |
3750 | void |
3713 | ev_ref (EV_P) EV_THROW |
3751 | ev_ref (EV_P) EV_NOEXCEPT |
3714 | { |
3752 | { |
3715 | ++activecnt; |
3753 | ++activecnt; |
3716 | } |
3754 | } |
3717 | |
3755 | |
3718 | void |
3756 | void |
3719 | ev_unref (EV_P) EV_THROW |
3757 | ev_unref (EV_P) EV_NOEXCEPT |
3720 | { |
3758 | { |
3721 | --activecnt; |
3759 | --activecnt; |
3722 | } |
3760 | } |
3723 | |
3761 | |
3724 | void |
3762 | void |
3725 | ev_now_update (EV_P) EV_THROW |
3763 | ev_now_update (EV_P) EV_NOEXCEPT |
3726 | { |
3764 | { |
3727 | time_update (EV_A_ 1e100); |
3765 | time_update (EV_A_ 1e100); |
3728 | } |
3766 | } |
3729 | |
3767 | |
3730 | void |
3768 | void |
3731 | ev_suspend (EV_P) EV_THROW |
3769 | ev_suspend (EV_P) EV_NOEXCEPT |
3732 | { |
3770 | { |
3733 | ev_now_update (EV_A); |
3771 | ev_now_update (EV_A); |
3734 | } |
3772 | } |
3735 | |
3773 | |
3736 | void |
3774 | void |
3737 | ev_resume (EV_P) EV_THROW |
3775 | ev_resume (EV_P) EV_NOEXCEPT |
3738 | { |
3776 | { |
3739 | ev_tstamp mn_prev = mn_now; |
3777 | ev_tstamp mn_prev = mn_now; |
3740 | |
3778 | |
3741 | ev_now_update (EV_A); |
3779 | ev_now_update (EV_A); |
3742 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3780 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3781 | w->pending = 0; |
3819 | w->pending = 0; |
3782 | } |
3820 | } |
3783 | } |
3821 | } |
3784 | |
3822 | |
3785 | int |
3823 | int |
3786 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3824 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3787 | { |
3825 | { |
3788 | W w_ = (W)w; |
3826 | W w_ = (W)w; |
3789 | int pending = w_->pending; |
3827 | int pending = w_->pending; |
3790 | |
3828 | |
3791 | if (expect_true (pending)) |
3829 | if (expect_true (pending)) |
… | |
… | |
3823 | w->active = 0; |
3861 | w->active = 0; |
3824 | } |
3862 | } |
3825 | |
3863 | |
3826 | /*****************************************************************************/ |
3864 | /*****************************************************************************/ |
3827 | |
3865 | |
3828 | void noinline |
3866 | noinline |
|
|
3867 | void |
3829 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3868 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3830 | { |
3869 | { |
3831 | int fd = w->fd; |
3870 | int fd = w->fd; |
3832 | |
3871 | |
3833 | if (expect_false (ev_is_active (w))) |
3872 | if (expect_false (ev_is_active (w))) |
3834 | return; |
3873 | return; |
… | |
… | |
3849 | w->events &= ~EV__IOFDSET; |
3888 | w->events &= ~EV__IOFDSET; |
3850 | |
3889 | |
3851 | EV_FREQUENT_CHECK; |
3890 | EV_FREQUENT_CHECK; |
3852 | } |
3891 | } |
3853 | |
3892 | |
3854 | void noinline |
3893 | noinline |
|
|
3894 | void |
3855 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3895 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3856 | { |
3896 | { |
3857 | clear_pending (EV_A_ (W)w); |
3897 | clear_pending (EV_A_ (W)w); |
3858 | if (expect_false (!ev_is_active (w))) |
3898 | if (expect_false (!ev_is_active (w))) |
3859 | return; |
3899 | return; |
3860 | |
3900 | |
… | |
… | |
3868 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3908 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3869 | |
3909 | |
3870 | EV_FREQUENT_CHECK; |
3910 | EV_FREQUENT_CHECK; |
3871 | } |
3911 | } |
3872 | |
3912 | |
3873 | void noinline |
3913 | noinline |
|
|
3914 | void |
3874 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3915 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3875 | { |
3916 | { |
3876 | if (expect_false (ev_is_active (w))) |
3917 | if (expect_false (ev_is_active (w))) |
3877 | return; |
3918 | return; |
3878 | |
3919 | |
3879 | ev_at (w) += mn_now; |
3920 | ev_at (w) += mn_now; |
… | |
… | |
3892 | EV_FREQUENT_CHECK; |
3933 | EV_FREQUENT_CHECK; |
3893 | |
3934 | |
3894 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3935 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3895 | } |
3936 | } |
3896 | |
3937 | |
3897 | void noinline |
3938 | noinline |
|
|
3939 | void |
3898 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3940 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3899 | { |
3941 | { |
3900 | clear_pending (EV_A_ (W)w); |
3942 | clear_pending (EV_A_ (W)w); |
3901 | if (expect_false (!ev_is_active (w))) |
3943 | if (expect_false (!ev_is_active (w))) |
3902 | return; |
3944 | return; |
3903 | |
3945 | |
… | |
… | |
3922 | ev_stop (EV_A_ (W)w); |
3964 | ev_stop (EV_A_ (W)w); |
3923 | |
3965 | |
3924 | EV_FREQUENT_CHECK; |
3966 | EV_FREQUENT_CHECK; |
3925 | } |
3967 | } |
3926 | |
3968 | |
3927 | void noinline |
3969 | noinline |
|
|
3970 | void |
3928 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3971 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3929 | { |
3972 | { |
3930 | EV_FREQUENT_CHECK; |
3973 | EV_FREQUENT_CHECK; |
3931 | |
3974 | |
3932 | clear_pending (EV_A_ (W)w); |
3975 | clear_pending (EV_A_ (W)w); |
3933 | |
3976 | |
… | |
… | |
3950 | |
3993 | |
3951 | EV_FREQUENT_CHECK; |
3994 | EV_FREQUENT_CHECK; |
3952 | } |
3995 | } |
3953 | |
3996 | |
3954 | ev_tstamp |
3997 | ev_tstamp |
3955 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3998 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3956 | { |
3999 | { |
3957 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4000 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3958 | } |
4001 | } |
3959 | |
4002 | |
3960 | #if EV_PERIODIC_ENABLE |
4003 | #if EV_PERIODIC_ENABLE |
3961 | void noinline |
4004 | noinline |
|
|
4005 | void |
3962 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4006 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3963 | { |
4007 | { |
3964 | if (expect_false (ev_is_active (w))) |
4008 | if (expect_false (ev_is_active (w))) |
3965 | return; |
4009 | return; |
3966 | |
4010 | |
3967 | if (w->reschedule_cb) |
4011 | if (w->reschedule_cb) |
… | |
… | |
3986 | EV_FREQUENT_CHECK; |
4030 | EV_FREQUENT_CHECK; |
3987 | |
4031 | |
3988 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4032 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3989 | } |
4033 | } |
3990 | |
4034 | |
3991 | void noinline |
4035 | noinline |
|
|
4036 | void |
3992 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4037 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3993 | { |
4038 | { |
3994 | clear_pending (EV_A_ (W)w); |
4039 | clear_pending (EV_A_ (W)w); |
3995 | if (expect_false (!ev_is_active (w))) |
4040 | if (expect_false (!ev_is_active (w))) |
3996 | return; |
4041 | return; |
3997 | |
4042 | |
… | |
… | |
4014 | ev_stop (EV_A_ (W)w); |
4059 | ev_stop (EV_A_ (W)w); |
4015 | |
4060 | |
4016 | EV_FREQUENT_CHECK; |
4061 | EV_FREQUENT_CHECK; |
4017 | } |
4062 | } |
4018 | |
4063 | |
4019 | void noinline |
4064 | noinline |
|
|
4065 | void |
4020 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4066 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4021 | { |
4067 | { |
4022 | /* TODO: use adjustheap and recalculation */ |
4068 | /* TODO: use adjustheap and recalculation */ |
4023 | ev_periodic_stop (EV_A_ w); |
4069 | ev_periodic_stop (EV_A_ w); |
4024 | ev_periodic_start (EV_A_ w); |
4070 | ev_periodic_start (EV_A_ w); |
4025 | } |
4071 | } |
… | |
… | |
4029 | # define SA_RESTART 0 |
4075 | # define SA_RESTART 0 |
4030 | #endif |
4076 | #endif |
4031 | |
4077 | |
4032 | #if EV_SIGNAL_ENABLE |
4078 | #if EV_SIGNAL_ENABLE |
4033 | |
4079 | |
4034 | void noinline |
4080 | noinline |
|
|
4081 | void |
4035 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4082 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4036 | { |
4083 | { |
4037 | if (expect_false (ev_is_active (w))) |
4084 | if (expect_false (ev_is_active (w))) |
4038 | return; |
4085 | return; |
4039 | |
4086 | |
4040 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4087 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4111 | } |
4158 | } |
4112 | |
4159 | |
4113 | EV_FREQUENT_CHECK; |
4160 | EV_FREQUENT_CHECK; |
4114 | } |
4161 | } |
4115 | |
4162 | |
4116 | void noinline |
4163 | noinline |
|
|
4164 | void |
4117 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4165 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4118 | { |
4166 | { |
4119 | clear_pending (EV_A_ (W)w); |
4167 | clear_pending (EV_A_ (W)w); |
4120 | if (expect_false (!ev_is_active (w))) |
4168 | if (expect_false (!ev_is_active (w))) |
4121 | return; |
4169 | return; |
4122 | |
4170 | |
… | |
… | |
4153 | #endif |
4201 | #endif |
4154 | |
4202 | |
4155 | #if EV_CHILD_ENABLE |
4203 | #if EV_CHILD_ENABLE |
4156 | |
4204 | |
4157 | void |
4205 | void |
4158 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4206 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4159 | { |
4207 | { |
4160 | #if EV_MULTIPLICITY |
4208 | #if EV_MULTIPLICITY |
4161 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4209 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4162 | #endif |
4210 | #endif |
4163 | if (expect_false (ev_is_active (w))) |
4211 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4170 | |
4218 | |
4171 | EV_FREQUENT_CHECK; |
4219 | EV_FREQUENT_CHECK; |
4172 | } |
4220 | } |
4173 | |
4221 | |
4174 | void |
4222 | void |
4175 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4223 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4176 | { |
4224 | { |
4177 | clear_pending (EV_A_ (W)w); |
4225 | clear_pending (EV_A_ (W)w); |
4178 | if (expect_false (!ev_is_active (w))) |
4226 | if (expect_false (!ev_is_active (w))) |
4179 | return; |
4227 | return; |
4180 | |
4228 | |
… | |
… | |
4197 | |
4245 | |
4198 | #define DEF_STAT_INTERVAL 5.0074891 |
4246 | #define DEF_STAT_INTERVAL 5.0074891 |
4199 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4247 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4200 | #define MIN_STAT_INTERVAL 0.1074891 |
4248 | #define MIN_STAT_INTERVAL 0.1074891 |
4201 | |
4249 | |
4202 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4250 | noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4203 | |
4251 | |
4204 | #if EV_USE_INOTIFY |
4252 | #if EV_USE_INOTIFY |
4205 | |
4253 | |
4206 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4254 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4207 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4255 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4208 | |
4256 | |
4209 | static void noinline |
4257 | noinline |
|
|
4258 | static void |
4210 | infy_add (EV_P_ ev_stat *w) |
4259 | infy_add (EV_P_ ev_stat *w) |
4211 | { |
4260 | { |
4212 | w->wd = inotify_add_watch (fs_fd, w->path, |
4261 | w->wd = inotify_add_watch (fs_fd, w->path, |
4213 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4262 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4214 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
4263 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
… | |
… | |
4278 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4327 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4279 | ev_timer_again (EV_A_ &w->timer); |
4328 | ev_timer_again (EV_A_ &w->timer); |
4280 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4329 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4281 | } |
4330 | } |
4282 | |
4331 | |
4283 | static void noinline |
4332 | noinline |
|
|
4333 | static void |
4284 | infy_del (EV_P_ ev_stat *w) |
4334 | infy_del (EV_P_ ev_stat *w) |
4285 | { |
4335 | { |
4286 | int slot; |
4336 | int slot; |
4287 | int wd = w->wd; |
4337 | int wd = w->wd; |
4288 | |
4338 | |
… | |
… | |
4295 | |
4345 | |
4296 | /* remove this watcher, if others are watching it, they will rearm */ |
4346 | /* remove this watcher, if others are watching it, they will rearm */ |
4297 | inotify_rm_watch (fs_fd, wd); |
4347 | inotify_rm_watch (fs_fd, wd); |
4298 | } |
4348 | } |
4299 | |
4349 | |
4300 | static void noinline |
4350 | noinline |
|
|
4351 | static void |
4301 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4352 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4302 | { |
4353 | { |
4303 | if (slot < 0) |
4354 | if (slot < 0) |
4304 | /* overflow, need to check for all hash slots */ |
4355 | /* overflow, need to check for all hash slots */ |
4305 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
4356 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
… | |
… | |
4341 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4392 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4342 | ofs += sizeof (struct inotify_event) + ev->len; |
4393 | ofs += sizeof (struct inotify_event) + ev->len; |
4343 | } |
4394 | } |
4344 | } |
4395 | } |
4345 | |
4396 | |
4346 | inline_size void ecb_cold |
4397 | inline_size ecb_cold |
|
|
4398 | void |
4347 | ev_check_2625 (EV_P) |
4399 | ev_check_2625 (EV_P) |
4348 | { |
4400 | { |
4349 | /* kernels < 2.6.25 are borked |
4401 | /* kernels < 2.6.25 are borked |
4350 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4402 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4351 | */ |
4403 | */ |
… | |
… | |
4441 | #else |
4493 | #else |
4442 | # define EV_LSTAT(p,b) lstat (p, b) |
4494 | # define EV_LSTAT(p,b) lstat (p, b) |
4443 | #endif |
4495 | #endif |
4444 | |
4496 | |
4445 | void |
4497 | void |
4446 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4498 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4447 | { |
4499 | { |
4448 | if (lstat (w->path, &w->attr) < 0) |
4500 | if (lstat (w->path, &w->attr) < 0) |
4449 | w->attr.st_nlink = 0; |
4501 | w->attr.st_nlink = 0; |
4450 | else if (!w->attr.st_nlink) |
4502 | else if (!w->attr.st_nlink) |
4451 | w->attr.st_nlink = 1; |
4503 | w->attr.st_nlink = 1; |
4452 | } |
4504 | } |
4453 | |
4505 | |
4454 | static void noinline |
4506 | noinline |
|
|
4507 | static void |
4455 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4508 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4456 | { |
4509 | { |
4457 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4510 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4458 | |
4511 | |
4459 | ev_statdata prev = w->attr; |
4512 | ev_statdata prev = w->attr; |
… | |
… | |
4490 | ev_feed_event (EV_A_ w, EV_STAT); |
4543 | ev_feed_event (EV_A_ w, EV_STAT); |
4491 | } |
4544 | } |
4492 | } |
4545 | } |
4493 | |
4546 | |
4494 | void |
4547 | void |
4495 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4548 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4496 | { |
4549 | { |
4497 | if (expect_false (ev_is_active (w))) |
4550 | if (expect_false (ev_is_active (w))) |
4498 | return; |
4551 | return; |
4499 | |
4552 | |
4500 | ev_stat_stat (EV_A_ w); |
4553 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4521 | |
4574 | |
4522 | EV_FREQUENT_CHECK; |
4575 | EV_FREQUENT_CHECK; |
4523 | } |
4576 | } |
4524 | |
4577 | |
4525 | void |
4578 | void |
4526 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4579 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4527 | { |
4580 | { |
4528 | clear_pending (EV_A_ (W)w); |
4581 | clear_pending (EV_A_ (W)w); |
4529 | if (expect_false (!ev_is_active (w))) |
4582 | if (expect_false (!ev_is_active (w))) |
4530 | return; |
4583 | return; |
4531 | |
4584 | |
… | |
… | |
4547 | } |
4600 | } |
4548 | #endif |
4601 | #endif |
4549 | |
4602 | |
4550 | #if EV_IDLE_ENABLE |
4603 | #if EV_IDLE_ENABLE |
4551 | void |
4604 | void |
4552 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4605 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4553 | { |
4606 | { |
4554 | if (expect_false (ev_is_active (w))) |
4607 | if (expect_false (ev_is_active (w))) |
4555 | return; |
4608 | return; |
4556 | |
4609 | |
4557 | pri_adjust (EV_A_ (W)w); |
4610 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4570 | |
4623 | |
4571 | EV_FREQUENT_CHECK; |
4624 | EV_FREQUENT_CHECK; |
4572 | } |
4625 | } |
4573 | |
4626 | |
4574 | void |
4627 | void |
4575 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4628 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4576 | { |
4629 | { |
4577 | clear_pending (EV_A_ (W)w); |
4630 | clear_pending (EV_A_ (W)w); |
4578 | if (expect_false (!ev_is_active (w))) |
4631 | if (expect_false (!ev_is_active (w))) |
4579 | return; |
4632 | return; |
4580 | |
4633 | |
… | |
… | |
4594 | } |
4647 | } |
4595 | #endif |
4648 | #endif |
4596 | |
4649 | |
4597 | #if EV_PREPARE_ENABLE |
4650 | #if EV_PREPARE_ENABLE |
4598 | void |
4651 | void |
4599 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4652 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4600 | { |
4653 | { |
4601 | if (expect_false (ev_is_active (w))) |
4654 | if (expect_false (ev_is_active (w))) |
4602 | return; |
4655 | return; |
4603 | |
4656 | |
4604 | EV_FREQUENT_CHECK; |
4657 | EV_FREQUENT_CHECK; |
… | |
… | |
4609 | |
4662 | |
4610 | EV_FREQUENT_CHECK; |
4663 | EV_FREQUENT_CHECK; |
4611 | } |
4664 | } |
4612 | |
4665 | |
4613 | void |
4666 | void |
4614 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4667 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4615 | { |
4668 | { |
4616 | clear_pending (EV_A_ (W)w); |
4669 | clear_pending (EV_A_ (W)w); |
4617 | if (expect_false (!ev_is_active (w))) |
4670 | if (expect_false (!ev_is_active (w))) |
4618 | return; |
4671 | return; |
4619 | |
4672 | |
… | |
… | |
4632 | } |
4685 | } |
4633 | #endif |
4686 | #endif |
4634 | |
4687 | |
4635 | #if EV_CHECK_ENABLE |
4688 | #if EV_CHECK_ENABLE |
4636 | void |
4689 | void |
4637 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4690 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4638 | { |
4691 | { |
4639 | if (expect_false (ev_is_active (w))) |
4692 | if (expect_false (ev_is_active (w))) |
4640 | return; |
4693 | return; |
4641 | |
4694 | |
4642 | EV_FREQUENT_CHECK; |
4695 | EV_FREQUENT_CHECK; |
… | |
… | |
4647 | |
4700 | |
4648 | EV_FREQUENT_CHECK; |
4701 | EV_FREQUENT_CHECK; |
4649 | } |
4702 | } |
4650 | |
4703 | |
4651 | void |
4704 | void |
4652 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4705 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4653 | { |
4706 | { |
4654 | clear_pending (EV_A_ (W)w); |
4707 | clear_pending (EV_A_ (W)w); |
4655 | if (expect_false (!ev_is_active (w))) |
4708 | if (expect_false (!ev_is_active (w))) |
4656 | return; |
4709 | return; |
4657 | |
4710 | |
… | |
… | |
4669 | EV_FREQUENT_CHECK; |
4722 | EV_FREQUENT_CHECK; |
4670 | } |
4723 | } |
4671 | #endif |
4724 | #endif |
4672 | |
4725 | |
4673 | #if EV_EMBED_ENABLE |
4726 | #if EV_EMBED_ENABLE |
4674 | void noinline |
4727 | noinline |
|
|
4728 | void |
4675 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4729 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4676 | { |
4730 | { |
4677 | ev_run (w->other, EVRUN_NOWAIT); |
4731 | ev_run (w->other, EVRUN_NOWAIT); |
4678 | } |
4732 | } |
4679 | |
4733 | |
4680 | static void |
4734 | static void |
… | |
… | |
4728 | ev_idle_stop (EV_A_ idle); |
4782 | ev_idle_stop (EV_A_ idle); |
4729 | } |
4783 | } |
4730 | #endif |
4784 | #endif |
4731 | |
4785 | |
4732 | void |
4786 | void |
4733 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4787 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4734 | { |
4788 | { |
4735 | if (expect_false (ev_is_active (w))) |
4789 | if (expect_false (ev_is_active (w))) |
4736 | return; |
4790 | return; |
4737 | |
4791 | |
4738 | { |
4792 | { |
… | |
… | |
4759 | |
4813 | |
4760 | EV_FREQUENT_CHECK; |
4814 | EV_FREQUENT_CHECK; |
4761 | } |
4815 | } |
4762 | |
4816 | |
4763 | void |
4817 | void |
4764 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4818 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4765 | { |
4819 | { |
4766 | clear_pending (EV_A_ (W)w); |
4820 | clear_pending (EV_A_ (W)w); |
4767 | if (expect_false (!ev_is_active (w))) |
4821 | if (expect_false (!ev_is_active (w))) |
4768 | return; |
4822 | return; |
4769 | |
4823 | |
… | |
… | |
4779 | } |
4833 | } |
4780 | #endif |
4834 | #endif |
4781 | |
4835 | |
4782 | #if EV_FORK_ENABLE |
4836 | #if EV_FORK_ENABLE |
4783 | void |
4837 | void |
4784 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4838 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4785 | { |
4839 | { |
4786 | if (expect_false (ev_is_active (w))) |
4840 | if (expect_false (ev_is_active (w))) |
4787 | return; |
4841 | return; |
4788 | |
4842 | |
4789 | EV_FREQUENT_CHECK; |
4843 | EV_FREQUENT_CHECK; |
… | |
… | |
4794 | |
4848 | |
4795 | EV_FREQUENT_CHECK; |
4849 | EV_FREQUENT_CHECK; |
4796 | } |
4850 | } |
4797 | |
4851 | |
4798 | void |
4852 | void |
4799 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4853 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4800 | { |
4854 | { |
4801 | clear_pending (EV_A_ (W)w); |
4855 | clear_pending (EV_A_ (W)w); |
4802 | if (expect_false (!ev_is_active (w))) |
4856 | if (expect_false (!ev_is_active (w))) |
4803 | return; |
4857 | return; |
4804 | |
4858 | |
… | |
… | |
4817 | } |
4871 | } |
4818 | #endif |
4872 | #endif |
4819 | |
4873 | |
4820 | #if EV_CLEANUP_ENABLE |
4874 | #if EV_CLEANUP_ENABLE |
4821 | void |
4875 | void |
4822 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4876 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4823 | { |
4877 | { |
4824 | if (expect_false (ev_is_active (w))) |
4878 | if (expect_false (ev_is_active (w))) |
4825 | return; |
4879 | return; |
4826 | |
4880 | |
4827 | EV_FREQUENT_CHECK; |
4881 | EV_FREQUENT_CHECK; |
… | |
… | |
4834 | ev_unref (EV_A); |
4888 | ev_unref (EV_A); |
4835 | EV_FREQUENT_CHECK; |
4889 | EV_FREQUENT_CHECK; |
4836 | } |
4890 | } |
4837 | |
4891 | |
4838 | void |
4892 | void |
4839 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4893 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4840 | { |
4894 | { |
4841 | clear_pending (EV_A_ (W)w); |
4895 | clear_pending (EV_A_ (W)w); |
4842 | if (expect_false (!ev_is_active (w))) |
4896 | if (expect_false (!ev_is_active (w))) |
4843 | return; |
4897 | return; |
4844 | |
4898 | |
… | |
… | |
4858 | } |
4912 | } |
4859 | #endif |
4913 | #endif |
4860 | |
4914 | |
4861 | #if EV_ASYNC_ENABLE |
4915 | #if EV_ASYNC_ENABLE |
4862 | void |
4916 | void |
4863 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4917 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4864 | { |
4918 | { |
4865 | if (expect_false (ev_is_active (w))) |
4919 | if (expect_false (ev_is_active (w))) |
4866 | return; |
4920 | return; |
4867 | |
4921 | |
4868 | w->sent = 0; |
4922 | w->sent = 0; |
… | |
… | |
4877 | |
4931 | |
4878 | EV_FREQUENT_CHECK; |
4932 | EV_FREQUENT_CHECK; |
4879 | } |
4933 | } |
4880 | |
4934 | |
4881 | void |
4935 | void |
4882 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4936 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4883 | { |
4937 | { |
4884 | clear_pending (EV_A_ (W)w); |
4938 | clear_pending (EV_A_ (W)w); |
4885 | if (expect_false (!ev_is_active (w))) |
4939 | if (expect_false (!ev_is_active (w))) |
4886 | return; |
4940 | return; |
4887 | |
4941 | |
… | |
… | |
4898 | |
4952 | |
4899 | EV_FREQUENT_CHECK; |
4953 | EV_FREQUENT_CHECK; |
4900 | } |
4954 | } |
4901 | |
4955 | |
4902 | void |
4956 | void |
4903 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4957 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4904 | { |
4958 | { |
4905 | w->sent = 1; |
4959 | w->sent = 1; |
4906 | evpipe_write (EV_A_ &async_pending); |
4960 | evpipe_write (EV_A_ &async_pending); |
4907 | } |
4961 | } |
4908 | #endif |
4962 | #endif |
… | |
… | |
4945 | |
4999 | |
4946 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5000 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4947 | } |
5001 | } |
4948 | |
5002 | |
4949 | void |
5003 | void |
4950 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5004 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
4951 | { |
5005 | { |
4952 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5006 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4953 | |
|
|
4954 | if (expect_false (!once)) |
|
|
4955 | { |
|
|
4956 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
4957 | return; |
|
|
4958 | } |
|
|
4959 | |
5007 | |
4960 | once->cb = cb; |
5008 | once->cb = cb; |
4961 | once->arg = arg; |
5009 | once->arg = arg; |
4962 | |
5010 | |
4963 | ev_init (&once->io, once_cb_io); |
5011 | ev_init (&once->io, once_cb_io); |
… | |
… | |
4976 | } |
5024 | } |
4977 | |
5025 | |
4978 | /*****************************************************************************/ |
5026 | /*****************************************************************************/ |
4979 | |
5027 | |
4980 | #if EV_WALK_ENABLE |
5028 | #if EV_WALK_ENABLE |
4981 | void ecb_cold |
5029 | ecb_cold |
|
|
5030 | void |
4982 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5031 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
4983 | { |
5032 | { |
4984 | int i, j; |
5033 | int i, j; |
4985 | ev_watcher_list *wl, *wn; |
5034 | ev_watcher_list *wl, *wn; |
4986 | |
5035 | |
4987 | if (types & (EV_IO | EV_EMBED)) |
5036 | if (types & (EV_IO | EV_EMBED)) |