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-2019 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 |
… | |
… | |
313 | |
315 | |
314 | #ifndef EV_USE_PORT |
316 | #ifndef EV_USE_PORT |
315 | # define EV_USE_PORT 0 |
317 | # define EV_USE_PORT 0 |
316 | #endif |
318 | #endif |
317 | |
319 | |
|
|
320 | #ifndef EV_USE_LINUXAIO |
|
|
321 | # define EV_USE_LINUXAIO 0 |
|
|
322 | #endif |
|
|
323 | |
318 | #ifndef EV_USE_INOTIFY |
324 | #ifndef EV_USE_INOTIFY |
319 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
325 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
320 | # define EV_USE_INOTIFY EV_FEATURE_OS |
326 | # define EV_USE_INOTIFY EV_FEATURE_OS |
321 | # else |
327 | # else |
322 | # define EV_USE_INOTIFY 0 |
328 | # define EV_USE_INOTIFY 0 |
… | |
… | |
363 | |
369 | |
364 | #ifndef EV_HEAP_CACHE_AT |
370 | #ifndef EV_HEAP_CACHE_AT |
365 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
371 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
366 | #endif |
372 | #endif |
367 | |
373 | |
368 | #ifdef ANDROID |
374 | #ifdef __ANDROID__ |
369 | /* supposedly, android doesn't typedef fd_mask */ |
375 | /* supposedly, android doesn't typedef fd_mask */ |
370 | # undef EV_USE_SELECT |
376 | # undef EV_USE_SELECT |
371 | # define EV_USE_SELECT 0 |
377 | # define EV_USE_SELECT 0 |
372 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
378 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
373 | # undef EV_USE_CLOCK_SYSCALL |
379 | # undef EV_USE_CLOCK_SYSCALL |
… | |
… | |
377 | /* aix's poll.h seems to cause lots of trouble */ |
383 | /* aix's poll.h seems to cause lots of trouble */ |
378 | #ifdef _AIX |
384 | #ifdef _AIX |
379 | /* AIX has a completely broken poll.h header */ |
385 | /* AIX has a completely broken poll.h header */ |
380 | # undef EV_USE_POLL |
386 | # undef EV_USE_POLL |
381 | # define EV_USE_POLL 0 |
387 | # define EV_USE_POLL 0 |
|
|
388 | #endif |
|
|
389 | |
|
|
390 | #if EV_USE_LINUXAIO |
|
|
391 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
382 | #endif |
392 | #endif |
383 | |
393 | |
384 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
394 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
385 | /* which makes programs even slower. might work on other unices, too. */ |
395 | /* which makes programs even slower. might work on other unices, too. */ |
386 | #if EV_USE_CLOCK_SYSCALL |
396 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
607 | #define ECB_CLANG_EXTENSION(x) 0 |
617 | #define ECB_CLANG_EXTENSION(x) 0 |
608 | #endif |
618 | #endif |
609 | |
619 | |
610 | #define ECB_CPP (__cplusplus+0) |
620 | #define ECB_CPP (__cplusplus+0) |
611 | #define ECB_CPP11 (__cplusplus >= 201103L) |
621 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
622 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
623 | #define ECB_CPP17 (__cplusplus >= 201703L) |
612 | |
624 | |
613 | #if ECB_CPP |
625 | #if ECB_CPP |
614 | #define ECB_C 0 |
626 | #define ECB_C 0 |
615 | #define ECB_STDC_VERSION 0 |
627 | #define ECB_STDC_VERSION 0 |
616 | #else |
628 | #else |
… | |
… | |
618 | #define ECB_STDC_VERSION __STDC_VERSION__ |
630 | #define ECB_STDC_VERSION __STDC_VERSION__ |
619 | #endif |
631 | #endif |
620 | |
632 | |
621 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
633 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
622 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
634 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
635 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
623 | |
636 | |
624 | #if ECB_CPP |
637 | #if ECB_CPP |
625 | #define ECB_EXTERN_C extern "C" |
638 | #define ECB_EXTERN_C extern "C" |
626 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
639 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
627 | #define ECB_EXTERN_C_END } |
640 | #define ECB_EXTERN_C_END } |
… | |
… | |
656 | #ifndef ECB_MEMORY_FENCE |
669 | #ifndef ECB_MEMORY_FENCE |
657 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
670 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
658 | #if __i386 || __i386__ |
671 | #if __i386 || __i386__ |
659 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
672 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
660 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
673 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
661 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
674 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
662 | #elif ECB_GCC_AMD64 |
675 | #elif ECB_GCC_AMD64 |
663 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
676 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
664 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
677 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
678 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
666 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
679 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
667 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
680 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
668 | #elif defined __ARM_ARCH_2__ \ |
681 | #elif defined __ARM_ARCH_2__ \ |
669 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
682 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
670 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
683 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
1538 | # define ABSPRI(w) (((W)w), 0) |
1551 | # define ABSPRI(w) (((W)w), 0) |
1539 | #else |
1552 | #else |
1540 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1553 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1541 | #endif |
1554 | #endif |
1542 | |
1555 | |
1543 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1556 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1544 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1545 | |
1557 | |
1546 | typedef ev_watcher *W; |
1558 | typedef ev_watcher *W; |
1547 | typedef ev_watcher_list *WL; |
1559 | typedef ev_watcher_list *WL; |
1548 | typedef ev_watcher_time *WT; |
1560 | typedef ev_watcher_time *WT; |
1549 | |
1561 | |
… | |
… | |
1675 | { |
1687 | { |
1676 | write (STDERR_FILENO, msg, strlen (msg)); |
1688 | write (STDERR_FILENO, msg, strlen (msg)); |
1677 | } |
1689 | } |
1678 | #endif |
1690 | #endif |
1679 | |
1691 | |
1680 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1692 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1681 | |
1693 | |
1682 | ecb_cold |
1694 | ecb_cold |
1683 | void |
1695 | void |
1684 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1696 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1685 | { |
1697 | { |
1686 | syserr_cb = cb; |
1698 | syserr_cb = cb; |
1687 | } |
1699 | } |
1688 | |
1700 | |
1689 | noinline ecb_cold |
1701 | noinline ecb_cold |
… | |
… | |
1708 | abort (); |
1720 | abort (); |
1709 | } |
1721 | } |
1710 | } |
1722 | } |
1711 | |
1723 | |
1712 | static void * |
1724 | static void * |
1713 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1725 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1714 | { |
1726 | { |
1715 | /* some systems, notably openbsd and darwin, fail to properly |
1727 | /* some systems, notably openbsd and darwin, fail to properly |
1716 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1728 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1717 | * the single unix specification, so work around them here. |
1729 | * the single unix specification, so work around them here. |
1718 | * recently, also (at least) fedora and debian started breaking it, |
1730 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1724 | |
1736 | |
1725 | free (ptr); |
1737 | free (ptr); |
1726 | return 0; |
1738 | return 0; |
1727 | } |
1739 | } |
1728 | |
1740 | |
1729 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1741 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1730 | |
1742 | |
1731 | ecb_cold |
1743 | ecb_cold |
1732 | void |
1744 | void |
1733 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1745 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1734 | { |
1746 | { |
1735 | alloc = cb; |
1747 | alloc = cb; |
1736 | } |
1748 | } |
1737 | |
1749 | |
1738 | inline_speed void * |
1750 | inline_speed void * |
… | |
… | |
1765 | typedef struct |
1777 | typedef struct |
1766 | { |
1778 | { |
1767 | WL head; |
1779 | WL head; |
1768 | unsigned char events; /* the events watched for */ |
1780 | unsigned char events; /* the events watched for */ |
1769 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1781 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1770 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
1782 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1771 | unsigned char unused; |
1783 | unsigned char unused; |
1772 | #if EV_USE_EPOLL |
1784 | #if EV_USE_EPOLL |
1773 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1785 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1774 | #endif |
1786 | #endif |
1775 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1787 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1855 | |
1867 | |
1856 | /*****************************************************************************/ |
1868 | /*****************************************************************************/ |
1857 | |
1869 | |
1858 | #ifndef EV_HAVE_EV_TIME |
1870 | #ifndef EV_HAVE_EV_TIME |
1859 | ev_tstamp |
1871 | ev_tstamp |
1860 | ev_time (void) EV_THROW |
1872 | ev_time (void) EV_NOEXCEPT |
1861 | { |
1873 | { |
1862 | #if EV_USE_REALTIME |
1874 | #if EV_USE_REALTIME |
1863 | if (expect_true (have_realtime)) |
1875 | if (expect_true (have_realtime)) |
1864 | { |
1876 | { |
1865 | struct timespec ts; |
1877 | struct timespec ts; |
… | |
… | |
1889 | return ev_time (); |
1901 | return ev_time (); |
1890 | } |
1902 | } |
1891 | |
1903 | |
1892 | #if EV_MULTIPLICITY |
1904 | #if EV_MULTIPLICITY |
1893 | ev_tstamp |
1905 | ev_tstamp |
1894 | ev_now (EV_P) EV_THROW |
1906 | ev_now (EV_P) EV_NOEXCEPT |
1895 | { |
1907 | { |
1896 | return ev_rt_now; |
1908 | return ev_rt_now; |
1897 | } |
1909 | } |
1898 | #endif |
1910 | #endif |
1899 | |
1911 | |
1900 | void |
1912 | void |
1901 | ev_sleep (ev_tstamp delay) EV_THROW |
1913 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1902 | { |
1914 | { |
1903 | if (delay > 0.) |
1915 | if (delay > 0.) |
1904 | { |
1916 | { |
1905 | #if EV_USE_NANOSLEEP |
1917 | #if EV_USE_NANOSLEEP |
1906 | struct timespec ts; |
1918 | struct timespec ts; |
1907 | |
1919 | |
1908 | EV_TS_SET (ts, delay); |
1920 | EV_TS_SET (ts, delay); |
1909 | nanosleep (&ts, 0); |
1921 | nanosleep (&ts, 0); |
1910 | #elif defined _WIN32 |
1922 | #elif defined _WIN32 |
|
|
1923 | /* maybe this should round up, as ms is very low resolution */ |
|
|
1924 | /* compared to select (µs) or nanosleep (ns) */ |
1911 | Sleep ((unsigned long)(delay * 1e3)); |
1925 | Sleep ((unsigned long)(delay * 1e3)); |
1912 | #else |
1926 | #else |
1913 | struct timeval tv; |
1927 | struct timeval tv; |
1914 | |
1928 | |
1915 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1929 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1954 | { |
1968 | { |
1955 | *cur = array_nextsize (elem, *cur, cnt); |
1969 | *cur = array_nextsize (elem, *cur, cnt); |
1956 | return ev_realloc (base, elem * *cur); |
1970 | return ev_realloc (base, elem * *cur); |
1957 | } |
1971 | } |
1958 | |
1972 | |
|
|
1973 | #define array_needsize_noinit(base,count) |
|
|
1974 | |
1959 | #define array_init_zero(base,count) \ |
1975 | #define array_needsize_zerofill(base,count) \ |
1960 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1976 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1961 | |
1977 | |
1962 | #define array_needsize(type,base,cur,cnt,init) \ |
1978 | #define array_needsize(type,base,cur,cnt,init) \ |
1963 | if (expect_false ((cnt) > (cur))) \ |
1979 | if (expect_false ((cnt) > (cur))) \ |
1964 | { \ |
1980 | { \ |
… | |
… | |
1990 | { |
2006 | { |
1991 | } |
2007 | } |
1992 | |
2008 | |
1993 | noinline |
2009 | noinline |
1994 | void |
2010 | void |
1995 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2011 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1996 | { |
2012 | { |
1997 | W w_ = (W)w; |
2013 | W w_ = (W)w; |
1998 | int pri = ABSPRI (w_); |
2014 | int pri = ABSPRI (w_); |
1999 | |
2015 | |
2000 | if (expect_false (w_->pending)) |
2016 | if (expect_false (w_->pending)) |
2001 | pendings [pri][w_->pending - 1].events |= revents; |
2017 | pendings [pri][w_->pending - 1].events |= revents; |
2002 | else |
2018 | else |
2003 | { |
2019 | { |
2004 | w_->pending = ++pendingcnt [pri]; |
2020 | w_->pending = ++pendingcnt [pri]; |
2005 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2021 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2006 | pendings [pri][w_->pending - 1].w = w_; |
2022 | pendings [pri][w_->pending - 1].w = w_; |
2007 | pendings [pri][w_->pending - 1].events = revents; |
2023 | pendings [pri][w_->pending - 1].events = revents; |
2008 | } |
2024 | } |
2009 | |
2025 | |
2010 | pendingpri = NUMPRI - 1; |
2026 | pendingpri = NUMPRI - 1; |
2011 | } |
2027 | } |
2012 | |
2028 | |
2013 | inline_speed void |
2029 | inline_speed void |
2014 | feed_reverse (EV_P_ W w) |
2030 | feed_reverse (EV_P_ W w) |
2015 | { |
2031 | { |
2016 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2032 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2017 | rfeeds [rfeedcnt++] = w; |
2033 | rfeeds [rfeedcnt++] = w; |
2018 | } |
2034 | } |
2019 | |
2035 | |
2020 | inline_size void |
2036 | inline_size void |
2021 | feed_reverse_done (EV_P_ int revents) |
2037 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2061 | if (expect_true (!anfd->reify)) |
2077 | if (expect_true (!anfd->reify)) |
2062 | fd_event_nocheck (EV_A_ fd, revents); |
2078 | fd_event_nocheck (EV_A_ fd, revents); |
2063 | } |
2079 | } |
2064 | |
2080 | |
2065 | void |
2081 | void |
2066 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2082 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2067 | { |
2083 | { |
2068 | if (fd >= 0 && fd < anfdmax) |
2084 | if (fd >= 0 && fd < anfdmax) |
2069 | fd_event_nocheck (EV_A_ fd, revents); |
2085 | fd_event_nocheck (EV_A_ fd, revents); |
2070 | } |
2086 | } |
2071 | |
2087 | |
… | |
… | |
2139 | anfds [fd].reify |= flags; |
2155 | anfds [fd].reify |= flags; |
2140 | |
2156 | |
2141 | if (expect_true (!reify)) |
2157 | if (expect_true (!reify)) |
2142 | { |
2158 | { |
2143 | ++fdchangecnt; |
2159 | ++fdchangecnt; |
2144 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2160 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2145 | fdchanges [fdchangecnt - 1] = fd; |
2161 | fdchanges [fdchangecnt - 1] = fd; |
2146 | } |
2162 | } |
2147 | } |
2163 | } |
2148 | |
2164 | |
2149 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2165 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
… | |
… | |
2471 | #endif |
2487 | #endif |
2472 | { |
2488 | { |
2473 | #ifdef _WIN32 |
2489 | #ifdef _WIN32 |
2474 | WSABUF buf; |
2490 | WSABUF buf; |
2475 | DWORD sent; |
2491 | DWORD sent; |
2476 | buf.buf = &buf; |
2492 | buf.buf = (char *)&buf; |
2477 | buf.len = 1; |
2493 | buf.len = 1; |
2478 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2494 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2479 | #else |
2495 | #else |
2480 | write (evpipe [1], &(evpipe [1]), 1); |
2496 | write (evpipe [1], &(evpipe [1]), 1); |
2481 | #endif |
2497 | #endif |
… | |
… | |
2553 | } |
2569 | } |
2554 | |
2570 | |
2555 | /*****************************************************************************/ |
2571 | /*****************************************************************************/ |
2556 | |
2572 | |
2557 | void |
2573 | void |
2558 | ev_feed_signal (int signum) EV_THROW |
2574 | ev_feed_signal (int signum) EV_NOEXCEPT |
2559 | { |
2575 | { |
2560 | #if EV_MULTIPLICITY |
2576 | #if EV_MULTIPLICITY |
2561 | EV_P; |
2577 | EV_P; |
2562 | ECB_MEMORY_FENCE_ACQUIRE; |
2578 | ECB_MEMORY_FENCE_ACQUIRE; |
2563 | EV_A = signals [signum - 1].loop; |
2579 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2580 | ev_feed_signal (signum); |
2596 | ev_feed_signal (signum); |
2581 | } |
2597 | } |
2582 | |
2598 | |
2583 | noinline |
2599 | noinline |
2584 | void |
2600 | void |
2585 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2601 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2586 | { |
2602 | { |
2587 | WL w; |
2603 | WL w; |
2588 | |
2604 | |
2589 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2605 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2590 | return; |
2606 | return; |
… | |
… | |
2696 | # include "ev_port.c" |
2712 | # include "ev_port.c" |
2697 | #endif |
2713 | #endif |
2698 | #if EV_USE_KQUEUE |
2714 | #if EV_USE_KQUEUE |
2699 | # include "ev_kqueue.c" |
2715 | # include "ev_kqueue.c" |
2700 | #endif |
2716 | #endif |
|
|
2717 | #if EV_USE_LINUXAIO |
|
|
2718 | # include "ev_linuxaio.c" |
|
|
2719 | #endif |
2701 | #if EV_USE_EPOLL |
2720 | #if EV_USE_EPOLL |
2702 | # include "ev_epoll.c" |
2721 | # include "ev_epoll.c" |
2703 | #endif |
2722 | #endif |
2704 | #if EV_USE_POLL |
2723 | #if EV_USE_POLL |
2705 | # include "ev_poll.c" |
2724 | # include "ev_poll.c" |
… | |
… | |
2707 | #if EV_USE_SELECT |
2726 | #if EV_USE_SELECT |
2708 | # include "ev_select.c" |
2727 | # include "ev_select.c" |
2709 | #endif |
2728 | #endif |
2710 | |
2729 | |
2711 | ecb_cold int |
2730 | ecb_cold int |
2712 | ev_version_major (void) EV_THROW |
2731 | ev_version_major (void) EV_NOEXCEPT |
2713 | { |
2732 | { |
2714 | return EV_VERSION_MAJOR; |
2733 | return EV_VERSION_MAJOR; |
2715 | } |
2734 | } |
2716 | |
2735 | |
2717 | ecb_cold int |
2736 | ecb_cold int |
2718 | ev_version_minor (void) EV_THROW |
2737 | ev_version_minor (void) EV_NOEXCEPT |
2719 | { |
2738 | { |
2720 | return EV_VERSION_MINOR; |
2739 | return EV_VERSION_MINOR; |
2721 | } |
2740 | } |
2722 | |
2741 | |
2723 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2742 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2732 | #endif |
2751 | #endif |
2733 | } |
2752 | } |
2734 | |
2753 | |
2735 | ecb_cold |
2754 | ecb_cold |
2736 | unsigned int |
2755 | unsigned int |
2737 | ev_supported_backends (void) EV_THROW |
2756 | ev_supported_backends (void) EV_NOEXCEPT |
2738 | { |
2757 | { |
2739 | unsigned int flags = 0; |
2758 | unsigned int flags = 0; |
2740 | |
2759 | |
2741 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2760 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2742 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2761 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2743 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2762 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2763 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2744 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2764 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2745 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2765 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2746 | |
2766 | |
2747 | return flags; |
2767 | return flags; |
2748 | } |
2768 | } |
2749 | |
2769 | |
2750 | ecb_cold |
2770 | ecb_cold |
2751 | unsigned int |
2771 | unsigned int |
2752 | ev_recommended_backends (void) EV_THROW |
2772 | ev_recommended_backends (void) EV_NOEXCEPT |
2753 | { |
2773 | { |
2754 | unsigned int flags = ev_supported_backends (); |
2774 | unsigned int flags = ev_supported_backends (); |
2755 | |
2775 | |
2756 | #ifndef __NetBSD__ |
2776 | #ifndef __NetBSD__ |
2757 | /* kqueue is borked on everything but netbsd apparently */ |
2777 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2770 | return flags; |
2790 | return flags; |
2771 | } |
2791 | } |
2772 | |
2792 | |
2773 | ecb_cold |
2793 | ecb_cold |
2774 | unsigned int |
2794 | unsigned int |
2775 | ev_embeddable_backends (void) EV_THROW |
2795 | ev_embeddable_backends (void) EV_NOEXCEPT |
2776 | { |
2796 | { |
2777 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2797 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2778 | |
2798 | |
2779 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2799 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2780 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2800 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2782 | |
2802 | |
2783 | return flags; |
2803 | return flags; |
2784 | } |
2804 | } |
2785 | |
2805 | |
2786 | unsigned int |
2806 | unsigned int |
2787 | ev_backend (EV_P) EV_THROW |
2807 | ev_backend (EV_P) EV_NOEXCEPT |
2788 | { |
2808 | { |
2789 | return backend; |
2809 | return backend; |
2790 | } |
2810 | } |
2791 | |
2811 | |
2792 | #if EV_FEATURE_API |
2812 | #if EV_FEATURE_API |
2793 | unsigned int |
2813 | unsigned int |
2794 | ev_iteration (EV_P) EV_THROW |
2814 | ev_iteration (EV_P) EV_NOEXCEPT |
2795 | { |
2815 | { |
2796 | return loop_count; |
2816 | return loop_count; |
2797 | } |
2817 | } |
2798 | |
2818 | |
2799 | unsigned int |
2819 | unsigned int |
2800 | ev_depth (EV_P) EV_THROW |
2820 | ev_depth (EV_P) EV_NOEXCEPT |
2801 | { |
2821 | { |
2802 | return loop_depth; |
2822 | return loop_depth; |
2803 | } |
2823 | } |
2804 | |
2824 | |
2805 | void |
2825 | void |
2806 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2826 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2807 | { |
2827 | { |
2808 | io_blocktime = interval; |
2828 | io_blocktime = interval; |
2809 | } |
2829 | } |
2810 | |
2830 | |
2811 | void |
2831 | void |
2812 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2832 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2813 | { |
2833 | { |
2814 | timeout_blocktime = interval; |
2834 | timeout_blocktime = interval; |
2815 | } |
2835 | } |
2816 | |
2836 | |
2817 | void |
2837 | void |
2818 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2838 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2819 | { |
2839 | { |
2820 | userdata = data; |
2840 | userdata = data; |
2821 | } |
2841 | } |
2822 | |
2842 | |
2823 | void * |
2843 | void * |
2824 | ev_userdata (EV_P) EV_THROW |
2844 | ev_userdata (EV_P) EV_NOEXCEPT |
2825 | { |
2845 | { |
2826 | return userdata; |
2846 | return userdata; |
2827 | } |
2847 | } |
2828 | |
2848 | |
2829 | void |
2849 | void |
2830 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
2850 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2831 | { |
2851 | { |
2832 | invoke_cb = invoke_pending_cb; |
2852 | invoke_cb = invoke_pending_cb; |
2833 | } |
2853 | } |
2834 | |
2854 | |
2835 | void |
2855 | void |
2836 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2856 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2837 | { |
2857 | { |
2838 | release_cb = release; |
2858 | release_cb = release; |
2839 | acquire_cb = acquire; |
2859 | acquire_cb = acquire; |
2840 | } |
2860 | } |
2841 | #endif |
2861 | #endif |
2842 | |
2862 | |
2843 | /* initialise a loop structure, must be zero-initialised */ |
2863 | /* initialise a loop structure, must be zero-initialised */ |
2844 | noinline ecb_cold |
2864 | noinline ecb_cold |
2845 | static void |
2865 | static void |
2846 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2866 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2847 | { |
2867 | { |
2848 | if (!backend) |
2868 | if (!backend) |
2849 | { |
2869 | { |
2850 | origflags = flags; |
2870 | origflags = flags; |
2851 | |
2871 | |
… | |
… | |
2909 | |
2929 | |
2910 | if (!(flags & EVBACKEND_MASK)) |
2930 | if (!(flags & EVBACKEND_MASK)) |
2911 | flags |= ev_recommended_backends (); |
2931 | flags |= ev_recommended_backends (); |
2912 | |
2932 | |
2913 | #if EV_USE_IOCP |
2933 | #if EV_USE_IOCP |
2914 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2934 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2915 | #endif |
2935 | #endif |
2916 | #if EV_USE_PORT |
2936 | #if EV_USE_PORT |
2917 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2937 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2918 | #endif |
2938 | #endif |
2919 | #if EV_USE_KQUEUE |
2939 | #if EV_USE_KQUEUE |
2920 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
2940 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
|
|
2941 | #endif |
|
|
2942 | #if EV_USE_LINUXAIO |
|
|
2943 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2921 | #endif |
2944 | #endif |
2922 | #if EV_USE_EPOLL |
2945 | #if EV_USE_EPOLL |
2923 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2946 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2924 | #endif |
2947 | #endif |
2925 | #if EV_USE_POLL |
2948 | #if EV_USE_POLL |
2926 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2949 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2927 | #endif |
2950 | #endif |
2928 | #if EV_USE_SELECT |
2951 | #if EV_USE_SELECT |
2929 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2952 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2930 | #endif |
2953 | #endif |
2931 | |
2954 | |
2932 | ev_prepare_init (&pending_w, pendingcb); |
2955 | ev_prepare_init (&pending_w, pendingcb); |
2933 | |
2956 | |
2934 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2957 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2989 | |
3012 | |
2990 | if (backend_fd >= 0) |
3013 | if (backend_fd >= 0) |
2991 | close (backend_fd); |
3014 | close (backend_fd); |
2992 | |
3015 | |
2993 | #if EV_USE_IOCP |
3016 | #if EV_USE_IOCP |
2994 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3017 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2995 | #endif |
3018 | #endif |
2996 | #if EV_USE_PORT |
3019 | #if EV_USE_PORT |
2997 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3020 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
2998 | #endif |
3021 | #endif |
2999 | #if EV_USE_KQUEUE |
3022 | #if EV_USE_KQUEUE |
3000 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
3023 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3024 | #endif |
|
|
3025 | #if EV_USE_LINUXAIO |
|
|
3026 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3001 | #endif |
3027 | #endif |
3002 | #if EV_USE_EPOLL |
3028 | #if EV_USE_EPOLL |
3003 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3029 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3004 | #endif |
3030 | #endif |
3005 | #if EV_USE_POLL |
3031 | #if EV_USE_POLL |
3006 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3032 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3007 | #endif |
3033 | #endif |
3008 | #if EV_USE_SELECT |
3034 | #if EV_USE_SELECT |
3009 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3035 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3010 | #endif |
3036 | #endif |
3011 | |
3037 | |
3012 | for (i = NUMPRI; i--; ) |
3038 | for (i = NUMPRI; i--; ) |
3013 | { |
3039 | { |
3014 | array_free (pending, [i]); |
3040 | array_free (pending, [i]); |
… | |
… | |
3056 | |
3082 | |
3057 | inline_size void |
3083 | inline_size void |
3058 | loop_fork (EV_P) |
3084 | loop_fork (EV_P) |
3059 | { |
3085 | { |
3060 | #if EV_USE_PORT |
3086 | #if EV_USE_PORT |
3061 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3087 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3062 | #endif |
3088 | #endif |
3063 | #if EV_USE_KQUEUE |
3089 | #if EV_USE_KQUEUE |
3064 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
3090 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3091 | #endif |
|
|
3092 | #if EV_USE_LINUXAIO |
|
|
3093 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3065 | #endif |
3094 | #endif |
3066 | #if EV_USE_EPOLL |
3095 | #if EV_USE_EPOLL |
3067 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3096 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3068 | #endif |
3097 | #endif |
3069 | #if EV_USE_INOTIFY |
3098 | #if EV_USE_INOTIFY |
3070 | infy_fork (EV_A); |
3099 | infy_fork (EV_A); |
3071 | #endif |
3100 | #endif |
3072 | |
3101 | |
… | |
… | |
3092 | |
3121 | |
3093 | #if EV_MULTIPLICITY |
3122 | #if EV_MULTIPLICITY |
3094 | |
3123 | |
3095 | ecb_cold |
3124 | ecb_cold |
3096 | struct ev_loop * |
3125 | struct ev_loop * |
3097 | ev_loop_new (unsigned int flags) EV_THROW |
3126 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3098 | { |
3127 | { |
3099 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3128 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3100 | |
3129 | |
3101 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3130 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3102 | loop_init (EV_A_ flags); |
3131 | loop_init (EV_A_ flags); |
… | |
… | |
3149 | } |
3178 | } |
3150 | #endif |
3179 | #endif |
3151 | |
3180 | |
3152 | #if EV_FEATURE_API |
3181 | #if EV_FEATURE_API |
3153 | void ecb_cold |
3182 | void ecb_cold |
3154 | ev_verify (EV_P) EV_THROW |
3183 | ev_verify (EV_P) EV_NOEXCEPT |
3155 | { |
3184 | { |
3156 | #if EV_VERIFY |
3185 | #if EV_VERIFY |
3157 | int i; |
3186 | int i; |
3158 | WL w, w2; |
3187 | WL w, w2; |
3159 | |
3188 | |
… | |
… | |
3240 | ecb_cold |
3269 | ecb_cold |
3241 | struct ev_loop * |
3270 | struct ev_loop * |
3242 | #else |
3271 | #else |
3243 | int |
3272 | int |
3244 | #endif |
3273 | #endif |
3245 | ev_default_loop (unsigned int flags) EV_THROW |
3274 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3246 | { |
3275 | { |
3247 | if (!ev_default_loop_ptr) |
3276 | if (!ev_default_loop_ptr) |
3248 | { |
3277 | { |
3249 | #if EV_MULTIPLICITY |
3278 | #if EV_MULTIPLICITY |
3250 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3279 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3269 | |
3298 | |
3270 | return ev_default_loop_ptr; |
3299 | return ev_default_loop_ptr; |
3271 | } |
3300 | } |
3272 | |
3301 | |
3273 | void |
3302 | void |
3274 | ev_loop_fork (EV_P) EV_THROW |
3303 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3275 | { |
3304 | { |
3276 | postfork = 1; |
3305 | postfork = 1; |
3277 | } |
3306 | } |
3278 | |
3307 | |
3279 | /*****************************************************************************/ |
3308 | /*****************************************************************************/ |
… | |
… | |
3283 | { |
3312 | { |
3284 | EV_CB_INVOKE ((W)w, revents); |
3313 | EV_CB_INVOKE ((W)w, revents); |
3285 | } |
3314 | } |
3286 | |
3315 | |
3287 | unsigned int |
3316 | unsigned int |
3288 | ev_pending_count (EV_P) EV_THROW |
3317 | ev_pending_count (EV_P) EV_NOEXCEPT |
3289 | { |
3318 | { |
3290 | int pri; |
3319 | int pri; |
3291 | unsigned int count = 0; |
3320 | unsigned int count = 0; |
3292 | |
3321 | |
3293 | for (pri = NUMPRI; pri--; ) |
3322 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3300 | void |
3329 | void |
3301 | ev_invoke_pending (EV_P) |
3330 | ev_invoke_pending (EV_P) |
3302 | { |
3331 | { |
3303 | pendingpri = NUMPRI; |
3332 | pendingpri = NUMPRI; |
3304 | |
3333 | |
3305 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3334 | do |
3306 | { |
3335 | { |
3307 | --pendingpri; |
3336 | --pendingpri; |
3308 | |
3337 | |
|
|
3338 | /* pendingpri possibly gets modified in the inner loop */ |
3309 | while (pendingcnt [pendingpri]) |
3339 | while (pendingcnt [pendingpri]) |
3310 | { |
3340 | { |
3311 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3341 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3312 | |
3342 | |
3313 | p->w->pending = 0; |
3343 | p->w->pending = 0; |
3314 | EV_CB_INVOKE (p->w, p->events); |
3344 | EV_CB_INVOKE (p->w, p->events); |
3315 | EV_FREQUENT_CHECK; |
3345 | EV_FREQUENT_CHECK; |
3316 | } |
3346 | } |
3317 | } |
3347 | } |
|
|
3348 | while (pendingpri); |
3318 | } |
3349 | } |
3319 | |
3350 | |
3320 | #if EV_IDLE_ENABLE |
3351 | #if EV_IDLE_ENABLE |
3321 | /* make idle watchers pending. this handles the "call-idle */ |
3352 | /* make idle watchers pending. this handles the "call-idle */ |
3322 | /* only when higher priorities are idle" logic */ |
3353 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3731 | |
3762 | |
3732 | return activecnt; |
3763 | return activecnt; |
3733 | } |
3764 | } |
3734 | |
3765 | |
3735 | void |
3766 | void |
3736 | ev_break (EV_P_ int how) EV_THROW |
3767 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3737 | { |
3768 | { |
3738 | loop_done = how; |
3769 | loop_done = how; |
3739 | } |
3770 | } |
3740 | |
3771 | |
3741 | void |
3772 | void |
3742 | ev_ref (EV_P) EV_THROW |
3773 | ev_ref (EV_P) EV_NOEXCEPT |
3743 | { |
3774 | { |
3744 | ++activecnt; |
3775 | ++activecnt; |
3745 | } |
3776 | } |
3746 | |
3777 | |
3747 | void |
3778 | void |
3748 | ev_unref (EV_P) EV_THROW |
3779 | ev_unref (EV_P) EV_NOEXCEPT |
3749 | { |
3780 | { |
3750 | --activecnt; |
3781 | --activecnt; |
3751 | } |
3782 | } |
3752 | |
3783 | |
3753 | void |
3784 | void |
3754 | ev_now_update (EV_P) EV_THROW |
3785 | ev_now_update (EV_P) EV_NOEXCEPT |
3755 | { |
3786 | { |
3756 | time_update (EV_A_ 1e100); |
3787 | time_update (EV_A_ 1e100); |
3757 | } |
3788 | } |
3758 | |
3789 | |
3759 | void |
3790 | void |
3760 | ev_suspend (EV_P) EV_THROW |
3791 | ev_suspend (EV_P) EV_NOEXCEPT |
3761 | { |
3792 | { |
3762 | ev_now_update (EV_A); |
3793 | ev_now_update (EV_A); |
3763 | } |
3794 | } |
3764 | |
3795 | |
3765 | void |
3796 | void |
3766 | ev_resume (EV_P) EV_THROW |
3797 | ev_resume (EV_P) EV_NOEXCEPT |
3767 | { |
3798 | { |
3768 | ev_tstamp mn_prev = mn_now; |
3799 | ev_tstamp mn_prev = mn_now; |
3769 | |
3800 | |
3770 | ev_now_update (EV_A); |
3801 | ev_now_update (EV_A); |
3771 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3802 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3810 | w->pending = 0; |
3841 | w->pending = 0; |
3811 | } |
3842 | } |
3812 | } |
3843 | } |
3813 | |
3844 | |
3814 | int |
3845 | int |
3815 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3846 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3816 | { |
3847 | { |
3817 | W w_ = (W)w; |
3848 | W w_ = (W)w; |
3818 | int pending = w_->pending; |
3849 | int pending = w_->pending; |
3819 | |
3850 | |
3820 | if (expect_true (pending)) |
3851 | if (expect_true (pending)) |
… | |
… | |
3854 | |
3885 | |
3855 | /*****************************************************************************/ |
3886 | /*****************************************************************************/ |
3856 | |
3887 | |
3857 | noinline |
3888 | noinline |
3858 | void |
3889 | void |
3859 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3890 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3860 | { |
3891 | { |
3861 | int fd = w->fd; |
3892 | int fd = w->fd; |
3862 | |
3893 | |
3863 | if (expect_false (ev_is_active (w))) |
3894 | if (expect_false (ev_is_active (w))) |
3864 | return; |
3895 | return; |
… | |
… | |
3867 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3898 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3868 | |
3899 | |
3869 | EV_FREQUENT_CHECK; |
3900 | EV_FREQUENT_CHECK; |
3870 | |
3901 | |
3871 | ev_start (EV_A_ (W)w, 1); |
3902 | ev_start (EV_A_ (W)w, 1); |
3872 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3903 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3873 | wlist_add (&anfds[fd].head, (WL)w); |
3904 | wlist_add (&anfds[fd].head, (WL)w); |
3874 | |
3905 | |
3875 | /* common bug, apparently */ |
3906 | /* common bug, apparently */ |
3876 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3907 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3877 | |
3908 | |
… | |
… | |
3881 | EV_FREQUENT_CHECK; |
3912 | EV_FREQUENT_CHECK; |
3882 | } |
3913 | } |
3883 | |
3914 | |
3884 | noinline |
3915 | noinline |
3885 | void |
3916 | void |
3886 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3917 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3887 | { |
3918 | { |
3888 | clear_pending (EV_A_ (W)w); |
3919 | clear_pending (EV_A_ (W)w); |
3889 | if (expect_false (!ev_is_active (w))) |
3920 | if (expect_false (!ev_is_active (w))) |
3890 | return; |
3921 | return; |
3891 | |
3922 | |
… | |
… | |
3901 | EV_FREQUENT_CHECK; |
3932 | EV_FREQUENT_CHECK; |
3902 | } |
3933 | } |
3903 | |
3934 | |
3904 | noinline |
3935 | noinline |
3905 | void |
3936 | void |
3906 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3937 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3907 | { |
3938 | { |
3908 | if (expect_false (ev_is_active (w))) |
3939 | if (expect_false (ev_is_active (w))) |
3909 | return; |
3940 | return; |
3910 | |
3941 | |
3911 | ev_at (w) += mn_now; |
3942 | ev_at (w) += mn_now; |
… | |
… | |
3914 | |
3945 | |
3915 | EV_FREQUENT_CHECK; |
3946 | EV_FREQUENT_CHECK; |
3916 | |
3947 | |
3917 | ++timercnt; |
3948 | ++timercnt; |
3918 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3949 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3919 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3950 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3920 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3951 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3921 | ANHE_at_cache (timers [ev_active (w)]); |
3952 | ANHE_at_cache (timers [ev_active (w)]); |
3922 | upheap (timers, ev_active (w)); |
3953 | upheap (timers, ev_active (w)); |
3923 | |
3954 | |
3924 | EV_FREQUENT_CHECK; |
3955 | EV_FREQUENT_CHECK; |
… | |
… | |
3926 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3957 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3927 | } |
3958 | } |
3928 | |
3959 | |
3929 | noinline |
3960 | noinline |
3930 | void |
3961 | void |
3931 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3962 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3932 | { |
3963 | { |
3933 | clear_pending (EV_A_ (W)w); |
3964 | clear_pending (EV_A_ (W)w); |
3934 | if (expect_false (!ev_is_active (w))) |
3965 | if (expect_false (!ev_is_active (w))) |
3935 | return; |
3966 | return; |
3936 | |
3967 | |
… | |
… | |
3957 | EV_FREQUENT_CHECK; |
3988 | EV_FREQUENT_CHECK; |
3958 | } |
3989 | } |
3959 | |
3990 | |
3960 | noinline |
3991 | noinline |
3961 | void |
3992 | void |
3962 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3993 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3963 | { |
3994 | { |
3964 | EV_FREQUENT_CHECK; |
3995 | EV_FREQUENT_CHECK; |
3965 | |
3996 | |
3966 | clear_pending (EV_A_ (W)w); |
3997 | clear_pending (EV_A_ (W)w); |
3967 | |
3998 | |
… | |
… | |
3984 | |
4015 | |
3985 | EV_FREQUENT_CHECK; |
4016 | EV_FREQUENT_CHECK; |
3986 | } |
4017 | } |
3987 | |
4018 | |
3988 | ev_tstamp |
4019 | ev_tstamp |
3989 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4020 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3990 | { |
4021 | { |
3991 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4022 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3992 | } |
4023 | } |
3993 | |
4024 | |
3994 | #if EV_PERIODIC_ENABLE |
4025 | #if EV_PERIODIC_ENABLE |
3995 | noinline |
4026 | noinline |
3996 | void |
4027 | void |
3997 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4028 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3998 | { |
4029 | { |
3999 | if (expect_false (ev_is_active (w))) |
4030 | if (expect_false (ev_is_active (w))) |
4000 | return; |
4031 | return; |
4001 | |
4032 | |
4002 | if (w->reschedule_cb) |
4033 | if (w->reschedule_cb) |
… | |
… | |
4011 | |
4042 | |
4012 | EV_FREQUENT_CHECK; |
4043 | EV_FREQUENT_CHECK; |
4013 | |
4044 | |
4014 | ++periodiccnt; |
4045 | ++periodiccnt; |
4015 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4046 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4016 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4047 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4017 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4048 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4018 | ANHE_at_cache (periodics [ev_active (w)]); |
4049 | ANHE_at_cache (periodics [ev_active (w)]); |
4019 | upheap (periodics, ev_active (w)); |
4050 | upheap (periodics, ev_active (w)); |
4020 | |
4051 | |
4021 | EV_FREQUENT_CHECK; |
4052 | EV_FREQUENT_CHECK; |
… | |
… | |
4023 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4054 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4024 | } |
4055 | } |
4025 | |
4056 | |
4026 | noinline |
4057 | noinline |
4027 | void |
4058 | void |
4028 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4059 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4029 | { |
4060 | { |
4030 | clear_pending (EV_A_ (W)w); |
4061 | clear_pending (EV_A_ (W)w); |
4031 | if (expect_false (!ev_is_active (w))) |
4062 | if (expect_false (!ev_is_active (w))) |
4032 | return; |
4063 | return; |
4033 | |
4064 | |
… | |
… | |
4052 | EV_FREQUENT_CHECK; |
4083 | EV_FREQUENT_CHECK; |
4053 | } |
4084 | } |
4054 | |
4085 | |
4055 | noinline |
4086 | noinline |
4056 | void |
4087 | void |
4057 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4088 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4058 | { |
4089 | { |
4059 | /* TODO: use adjustheap and recalculation */ |
4090 | /* TODO: use adjustheap and recalculation */ |
4060 | ev_periodic_stop (EV_A_ w); |
4091 | ev_periodic_stop (EV_A_ w); |
4061 | ev_periodic_start (EV_A_ w); |
4092 | ev_periodic_start (EV_A_ w); |
4062 | } |
4093 | } |
… | |
… | |
4068 | |
4099 | |
4069 | #if EV_SIGNAL_ENABLE |
4100 | #if EV_SIGNAL_ENABLE |
4070 | |
4101 | |
4071 | noinline |
4102 | noinline |
4072 | void |
4103 | void |
4073 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4104 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4074 | { |
4105 | { |
4075 | if (expect_false (ev_is_active (w))) |
4106 | if (expect_false (ev_is_active (w))) |
4076 | return; |
4107 | return; |
4077 | |
4108 | |
4078 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4109 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4151 | EV_FREQUENT_CHECK; |
4182 | EV_FREQUENT_CHECK; |
4152 | } |
4183 | } |
4153 | |
4184 | |
4154 | noinline |
4185 | noinline |
4155 | void |
4186 | void |
4156 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4187 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4157 | { |
4188 | { |
4158 | clear_pending (EV_A_ (W)w); |
4189 | clear_pending (EV_A_ (W)w); |
4159 | if (expect_false (!ev_is_active (w))) |
4190 | if (expect_false (!ev_is_active (w))) |
4160 | return; |
4191 | return; |
4161 | |
4192 | |
… | |
… | |
4192 | #endif |
4223 | #endif |
4193 | |
4224 | |
4194 | #if EV_CHILD_ENABLE |
4225 | #if EV_CHILD_ENABLE |
4195 | |
4226 | |
4196 | void |
4227 | void |
4197 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4228 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4198 | { |
4229 | { |
4199 | #if EV_MULTIPLICITY |
4230 | #if EV_MULTIPLICITY |
4200 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4231 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4201 | #endif |
4232 | #endif |
4202 | if (expect_false (ev_is_active (w))) |
4233 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4209 | |
4240 | |
4210 | EV_FREQUENT_CHECK; |
4241 | EV_FREQUENT_CHECK; |
4211 | } |
4242 | } |
4212 | |
4243 | |
4213 | void |
4244 | void |
4214 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4245 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4215 | { |
4246 | { |
4216 | clear_pending (EV_A_ (W)w); |
4247 | clear_pending (EV_A_ (W)w); |
4217 | if (expect_false (!ev_is_active (w))) |
4248 | if (expect_false (!ev_is_active (w))) |
4218 | return; |
4249 | return; |
4219 | |
4250 | |
… | |
… | |
4484 | #else |
4515 | #else |
4485 | # define EV_LSTAT(p,b) lstat (p, b) |
4516 | # define EV_LSTAT(p,b) lstat (p, b) |
4486 | #endif |
4517 | #endif |
4487 | |
4518 | |
4488 | void |
4519 | void |
4489 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4520 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4490 | { |
4521 | { |
4491 | if (lstat (w->path, &w->attr) < 0) |
4522 | if (lstat (w->path, &w->attr) < 0) |
4492 | w->attr.st_nlink = 0; |
4523 | w->attr.st_nlink = 0; |
4493 | else if (!w->attr.st_nlink) |
4524 | else if (!w->attr.st_nlink) |
4494 | w->attr.st_nlink = 1; |
4525 | w->attr.st_nlink = 1; |
… | |
… | |
4534 | ev_feed_event (EV_A_ w, EV_STAT); |
4565 | ev_feed_event (EV_A_ w, EV_STAT); |
4535 | } |
4566 | } |
4536 | } |
4567 | } |
4537 | |
4568 | |
4538 | void |
4569 | void |
4539 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4570 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4540 | { |
4571 | { |
4541 | if (expect_false (ev_is_active (w))) |
4572 | if (expect_false (ev_is_active (w))) |
4542 | return; |
4573 | return; |
4543 | |
4574 | |
4544 | ev_stat_stat (EV_A_ w); |
4575 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4565 | |
4596 | |
4566 | EV_FREQUENT_CHECK; |
4597 | EV_FREQUENT_CHECK; |
4567 | } |
4598 | } |
4568 | |
4599 | |
4569 | void |
4600 | void |
4570 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4601 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4571 | { |
4602 | { |
4572 | clear_pending (EV_A_ (W)w); |
4603 | clear_pending (EV_A_ (W)w); |
4573 | if (expect_false (!ev_is_active (w))) |
4604 | if (expect_false (!ev_is_active (w))) |
4574 | return; |
4605 | return; |
4575 | |
4606 | |
… | |
… | |
4591 | } |
4622 | } |
4592 | #endif |
4623 | #endif |
4593 | |
4624 | |
4594 | #if EV_IDLE_ENABLE |
4625 | #if EV_IDLE_ENABLE |
4595 | void |
4626 | void |
4596 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4627 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4597 | { |
4628 | { |
4598 | if (expect_false (ev_is_active (w))) |
4629 | if (expect_false (ev_is_active (w))) |
4599 | return; |
4630 | return; |
4600 | |
4631 | |
4601 | pri_adjust (EV_A_ (W)w); |
4632 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4606 | int active = ++idlecnt [ABSPRI (w)]; |
4637 | int active = ++idlecnt [ABSPRI (w)]; |
4607 | |
4638 | |
4608 | ++idleall; |
4639 | ++idleall; |
4609 | ev_start (EV_A_ (W)w, active); |
4640 | ev_start (EV_A_ (W)w, active); |
4610 | |
4641 | |
4611 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4642 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4612 | idles [ABSPRI (w)][active - 1] = w; |
4643 | idles [ABSPRI (w)][active - 1] = w; |
4613 | } |
4644 | } |
4614 | |
4645 | |
4615 | EV_FREQUENT_CHECK; |
4646 | EV_FREQUENT_CHECK; |
4616 | } |
4647 | } |
4617 | |
4648 | |
4618 | void |
4649 | void |
4619 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4650 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4620 | { |
4651 | { |
4621 | clear_pending (EV_A_ (W)w); |
4652 | clear_pending (EV_A_ (W)w); |
4622 | if (expect_false (!ev_is_active (w))) |
4653 | if (expect_false (!ev_is_active (w))) |
4623 | return; |
4654 | return; |
4624 | |
4655 | |
… | |
… | |
4638 | } |
4669 | } |
4639 | #endif |
4670 | #endif |
4640 | |
4671 | |
4641 | #if EV_PREPARE_ENABLE |
4672 | #if EV_PREPARE_ENABLE |
4642 | void |
4673 | void |
4643 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4674 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4644 | { |
4675 | { |
4645 | if (expect_false (ev_is_active (w))) |
4676 | if (expect_false (ev_is_active (w))) |
4646 | return; |
4677 | return; |
4647 | |
4678 | |
4648 | EV_FREQUENT_CHECK; |
4679 | EV_FREQUENT_CHECK; |
4649 | |
4680 | |
4650 | ev_start (EV_A_ (W)w, ++preparecnt); |
4681 | ev_start (EV_A_ (W)w, ++preparecnt); |
4651 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4682 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4652 | prepares [preparecnt - 1] = w; |
4683 | prepares [preparecnt - 1] = w; |
4653 | |
4684 | |
4654 | EV_FREQUENT_CHECK; |
4685 | EV_FREQUENT_CHECK; |
4655 | } |
4686 | } |
4656 | |
4687 | |
4657 | void |
4688 | void |
4658 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4689 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4659 | { |
4690 | { |
4660 | clear_pending (EV_A_ (W)w); |
4691 | clear_pending (EV_A_ (W)w); |
4661 | if (expect_false (!ev_is_active (w))) |
4692 | if (expect_false (!ev_is_active (w))) |
4662 | return; |
4693 | return; |
4663 | |
4694 | |
… | |
… | |
4676 | } |
4707 | } |
4677 | #endif |
4708 | #endif |
4678 | |
4709 | |
4679 | #if EV_CHECK_ENABLE |
4710 | #if EV_CHECK_ENABLE |
4680 | void |
4711 | void |
4681 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4712 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4682 | { |
4713 | { |
4683 | if (expect_false (ev_is_active (w))) |
4714 | if (expect_false (ev_is_active (w))) |
4684 | return; |
4715 | return; |
4685 | |
4716 | |
4686 | EV_FREQUENT_CHECK; |
4717 | EV_FREQUENT_CHECK; |
4687 | |
4718 | |
4688 | ev_start (EV_A_ (W)w, ++checkcnt); |
4719 | ev_start (EV_A_ (W)w, ++checkcnt); |
4689 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4720 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4690 | checks [checkcnt - 1] = w; |
4721 | checks [checkcnt - 1] = w; |
4691 | |
4722 | |
4692 | EV_FREQUENT_CHECK; |
4723 | EV_FREQUENT_CHECK; |
4693 | } |
4724 | } |
4694 | |
4725 | |
4695 | void |
4726 | void |
4696 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4727 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4697 | { |
4728 | { |
4698 | clear_pending (EV_A_ (W)w); |
4729 | clear_pending (EV_A_ (W)w); |
4699 | if (expect_false (!ev_is_active (w))) |
4730 | if (expect_false (!ev_is_active (w))) |
4700 | return; |
4731 | return; |
4701 | |
4732 | |
… | |
… | |
4715 | #endif |
4746 | #endif |
4716 | |
4747 | |
4717 | #if EV_EMBED_ENABLE |
4748 | #if EV_EMBED_ENABLE |
4718 | noinline |
4749 | noinline |
4719 | void |
4750 | void |
4720 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4751 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4721 | { |
4752 | { |
4722 | ev_run (w->other, EVRUN_NOWAIT); |
4753 | ev_run (w->other, EVRUN_NOWAIT); |
4723 | } |
4754 | } |
4724 | |
4755 | |
4725 | static void |
4756 | static void |
… | |
… | |
4773 | ev_idle_stop (EV_A_ idle); |
4804 | ev_idle_stop (EV_A_ idle); |
4774 | } |
4805 | } |
4775 | #endif |
4806 | #endif |
4776 | |
4807 | |
4777 | void |
4808 | void |
4778 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4809 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4779 | { |
4810 | { |
4780 | if (expect_false (ev_is_active (w))) |
4811 | if (expect_false (ev_is_active (w))) |
4781 | return; |
4812 | return; |
4782 | |
4813 | |
4783 | { |
4814 | { |
… | |
… | |
4804 | |
4835 | |
4805 | EV_FREQUENT_CHECK; |
4836 | EV_FREQUENT_CHECK; |
4806 | } |
4837 | } |
4807 | |
4838 | |
4808 | void |
4839 | void |
4809 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4840 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4810 | { |
4841 | { |
4811 | clear_pending (EV_A_ (W)w); |
4842 | clear_pending (EV_A_ (W)w); |
4812 | if (expect_false (!ev_is_active (w))) |
4843 | if (expect_false (!ev_is_active (w))) |
4813 | return; |
4844 | return; |
4814 | |
4845 | |
… | |
… | |
4824 | } |
4855 | } |
4825 | #endif |
4856 | #endif |
4826 | |
4857 | |
4827 | #if EV_FORK_ENABLE |
4858 | #if EV_FORK_ENABLE |
4828 | void |
4859 | void |
4829 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4860 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4830 | { |
4861 | { |
4831 | if (expect_false (ev_is_active (w))) |
4862 | if (expect_false (ev_is_active (w))) |
4832 | return; |
4863 | return; |
4833 | |
4864 | |
4834 | EV_FREQUENT_CHECK; |
4865 | EV_FREQUENT_CHECK; |
4835 | |
4866 | |
4836 | ev_start (EV_A_ (W)w, ++forkcnt); |
4867 | ev_start (EV_A_ (W)w, ++forkcnt); |
4837 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4868 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4838 | forks [forkcnt - 1] = w; |
4869 | forks [forkcnt - 1] = w; |
4839 | |
4870 | |
4840 | EV_FREQUENT_CHECK; |
4871 | EV_FREQUENT_CHECK; |
4841 | } |
4872 | } |
4842 | |
4873 | |
4843 | void |
4874 | void |
4844 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4875 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4845 | { |
4876 | { |
4846 | clear_pending (EV_A_ (W)w); |
4877 | clear_pending (EV_A_ (W)w); |
4847 | if (expect_false (!ev_is_active (w))) |
4878 | if (expect_false (!ev_is_active (w))) |
4848 | return; |
4879 | return; |
4849 | |
4880 | |
… | |
… | |
4862 | } |
4893 | } |
4863 | #endif |
4894 | #endif |
4864 | |
4895 | |
4865 | #if EV_CLEANUP_ENABLE |
4896 | #if EV_CLEANUP_ENABLE |
4866 | void |
4897 | void |
4867 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4898 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4868 | { |
4899 | { |
4869 | if (expect_false (ev_is_active (w))) |
4900 | if (expect_false (ev_is_active (w))) |
4870 | return; |
4901 | return; |
4871 | |
4902 | |
4872 | EV_FREQUENT_CHECK; |
4903 | EV_FREQUENT_CHECK; |
4873 | |
4904 | |
4874 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4905 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4875 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4906 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4876 | cleanups [cleanupcnt - 1] = w; |
4907 | cleanups [cleanupcnt - 1] = w; |
4877 | |
4908 | |
4878 | /* cleanup watchers should never keep a refcount on the loop */ |
4909 | /* cleanup watchers should never keep a refcount on the loop */ |
4879 | ev_unref (EV_A); |
4910 | ev_unref (EV_A); |
4880 | EV_FREQUENT_CHECK; |
4911 | EV_FREQUENT_CHECK; |
4881 | } |
4912 | } |
4882 | |
4913 | |
4883 | void |
4914 | void |
4884 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4915 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4885 | { |
4916 | { |
4886 | clear_pending (EV_A_ (W)w); |
4917 | clear_pending (EV_A_ (W)w); |
4887 | if (expect_false (!ev_is_active (w))) |
4918 | if (expect_false (!ev_is_active (w))) |
4888 | return; |
4919 | return; |
4889 | |
4920 | |
… | |
… | |
4903 | } |
4934 | } |
4904 | #endif |
4935 | #endif |
4905 | |
4936 | |
4906 | #if EV_ASYNC_ENABLE |
4937 | #if EV_ASYNC_ENABLE |
4907 | void |
4938 | void |
4908 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4939 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4909 | { |
4940 | { |
4910 | if (expect_false (ev_is_active (w))) |
4941 | if (expect_false (ev_is_active (w))) |
4911 | return; |
4942 | return; |
4912 | |
4943 | |
4913 | w->sent = 0; |
4944 | w->sent = 0; |
… | |
… | |
4915 | evpipe_init (EV_A); |
4946 | evpipe_init (EV_A); |
4916 | |
4947 | |
4917 | EV_FREQUENT_CHECK; |
4948 | EV_FREQUENT_CHECK; |
4918 | |
4949 | |
4919 | ev_start (EV_A_ (W)w, ++asynccnt); |
4950 | ev_start (EV_A_ (W)w, ++asynccnt); |
4920 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4951 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4921 | asyncs [asynccnt - 1] = w; |
4952 | asyncs [asynccnt - 1] = w; |
4922 | |
4953 | |
4923 | EV_FREQUENT_CHECK; |
4954 | EV_FREQUENT_CHECK; |
4924 | } |
4955 | } |
4925 | |
4956 | |
4926 | void |
4957 | void |
4927 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4958 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4928 | { |
4959 | { |
4929 | clear_pending (EV_A_ (W)w); |
4960 | clear_pending (EV_A_ (W)w); |
4930 | if (expect_false (!ev_is_active (w))) |
4961 | if (expect_false (!ev_is_active (w))) |
4931 | return; |
4962 | return; |
4932 | |
4963 | |
… | |
… | |
4943 | |
4974 | |
4944 | EV_FREQUENT_CHECK; |
4975 | EV_FREQUENT_CHECK; |
4945 | } |
4976 | } |
4946 | |
4977 | |
4947 | void |
4978 | void |
4948 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4979 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4949 | { |
4980 | { |
4950 | w->sent = 1; |
4981 | w->sent = 1; |
4951 | evpipe_write (EV_A_ &async_pending); |
4982 | evpipe_write (EV_A_ &async_pending); |
4952 | } |
4983 | } |
4953 | #endif |
4984 | #endif |
… | |
… | |
4990 | |
5021 | |
4991 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5022 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4992 | } |
5023 | } |
4993 | |
5024 | |
4994 | void |
5025 | void |
4995 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5026 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
4996 | { |
5027 | { |
4997 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5028 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4998 | |
|
|
4999 | if (expect_false (!once)) |
|
|
5000 | { |
|
|
5001 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5002 | return; |
|
|
5003 | } |
|
|
5004 | |
5029 | |
5005 | once->cb = cb; |
5030 | once->cb = cb; |
5006 | once->arg = arg; |
5031 | once->arg = arg; |
5007 | |
5032 | |
5008 | ev_init (&once->io, once_cb_io); |
5033 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5023 | /*****************************************************************************/ |
5048 | /*****************************************************************************/ |
5024 | |
5049 | |
5025 | #if EV_WALK_ENABLE |
5050 | #if EV_WALK_ENABLE |
5026 | ecb_cold |
5051 | ecb_cold |
5027 | void |
5052 | void |
5028 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5053 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
5029 | { |
5054 | { |
5030 | int i, j; |
5055 | int i, j; |
5031 | ev_watcher_list *wl, *wn; |
5056 | ev_watcher_list *wl, *wn; |
5032 | |
5057 | |
5033 | if (types & (EV_IO | EV_EMBED)) |
5058 | if (types & (EV_IO | EV_EMBED)) |