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 | * |
… | |
… | |
115 | # else |
115 | # else |
116 | # undef EV_USE_EPOLL |
116 | # undef EV_USE_EPOLL |
117 | # define EV_USE_EPOLL 0 |
117 | # define EV_USE_EPOLL 0 |
118 | # endif |
118 | # endif |
119 | |
119 | |
|
|
120 | # if HAVE_LINUX_AIO_ABI_H |
|
|
121 | # ifndef EV_USE_LINUXAIO |
|
|
122 | # define EV_USE_LINUXAIO EV_FEATURE_BACKENDS |
|
|
123 | # endif |
|
|
124 | # else |
|
|
125 | # undef EV_USE_LINUXAIO |
|
|
126 | # define EV_USE_LINUXAIO 0 |
|
|
127 | # endif |
|
|
128 | |
120 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
129 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
121 | # ifndef EV_USE_KQUEUE |
130 | # ifndef EV_USE_KQUEUE |
122 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
131 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
123 | # endif |
132 | # endif |
124 | # else |
133 | # else |
… | |
… | |
162 | # define EV_USE_EVENTFD 0 |
171 | # define EV_USE_EVENTFD 0 |
163 | # endif |
172 | # endif |
164 | |
173 | |
165 | #endif |
174 | #endif |
166 | |
175 | |
|
|
176 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
177 | * a limit of 1024 into their select. Where people have brains, |
|
|
178 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
179 | * ordered to have a vacuum, or they do anything for money. |
|
|
180 | * This might help. Or not. |
|
|
181 | * Note that this must be defined early, as other include files |
|
|
182 | * will rely on this define as well. |
|
|
183 | */ |
|
|
184 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
185 | |
167 | #include <stdlib.h> |
186 | #include <stdlib.h> |
168 | #include <string.h> |
187 | #include <string.h> |
169 | #include <fcntl.h> |
188 | #include <fcntl.h> |
170 | #include <stddef.h> |
189 | #include <stddef.h> |
171 | |
190 | |
… | |
… | |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
227 | # ifndef EV_SELECT_IS_WINSOCKET |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
228 | # define EV_SELECT_IS_WINSOCKET 1 |
210 | # endif |
229 | # endif |
211 | # undef EV_AVOID_STDIO |
230 | # undef EV_AVOID_STDIO |
212 | #endif |
231 | #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 | |
232 | |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
233 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
223 | |
234 | |
224 | /* try to deduce the maximum number of signals on this platform */ |
235 | /* try to deduce the maximum number of signals on this platform */ |
225 | #if defined EV_NSIG |
236 | #if defined EV_NSIG |
… | |
… | |
313 | |
324 | |
314 | #ifndef EV_USE_PORT |
325 | #ifndef EV_USE_PORT |
315 | # define EV_USE_PORT 0 |
326 | # define EV_USE_PORT 0 |
316 | #endif |
327 | #endif |
317 | |
328 | |
|
|
329 | #ifndef EV_USE_LINUXAIO |
|
|
330 | # define EV_USE_LINUXAIO 0 |
|
|
331 | #endif |
|
|
332 | |
318 | #ifndef EV_USE_INOTIFY |
333 | #ifndef EV_USE_INOTIFY |
319 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
334 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
320 | # define EV_USE_INOTIFY EV_FEATURE_OS |
335 | # define EV_USE_INOTIFY EV_FEATURE_OS |
321 | # else |
336 | # else |
322 | # define EV_USE_INOTIFY 0 |
337 | # define EV_USE_INOTIFY 0 |
… | |
… | |
377 | /* aix's poll.h seems to cause lots of trouble */ |
392 | /* aix's poll.h seems to cause lots of trouble */ |
378 | #ifdef _AIX |
393 | #ifdef _AIX |
379 | /* AIX has a completely broken poll.h header */ |
394 | /* AIX has a completely broken poll.h header */ |
380 | # undef EV_USE_POLL |
395 | # undef EV_USE_POLL |
381 | # define EV_USE_POLL 0 |
396 | # define EV_USE_POLL 0 |
|
|
397 | #endif |
|
|
398 | |
|
|
399 | #if EV_USE_LINUXAIO |
|
|
400 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
382 | #endif |
401 | #endif |
383 | |
402 | |
384 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
403 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
385 | /* which makes programs even slower. might work on other unices, too. */ |
404 | /* which makes programs even slower. might work on other unices, too. */ |
386 | #if EV_USE_CLOCK_SYSCALL |
405 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
414 | |
433 | |
415 | #if !EV_USE_NANOSLEEP |
434 | #if !EV_USE_NANOSLEEP |
416 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
435 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
417 | # if !defined _WIN32 && !defined __hpux |
436 | # if !defined _WIN32 && !defined __hpux |
418 | # include <sys/select.h> |
437 | # include <sys/select.h> |
|
|
438 | # endif |
|
|
439 | #endif |
|
|
440 | |
|
|
441 | #if EV_USE_LINUXAIO |
|
|
442 | # include <sys/syscall.h> |
|
|
443 | # if !SYS_io_getevents |
|
|
444 | # undef EV_USE_LINUXAIO |
|
|
445 | # define EV_USE_LINUXAIO 0 |
419 | # endif |
446 | # endif |
420 | #endif |
447 | #endif |
421 | |
448 | |
422 | #if EV_USE_INOTIFY |
449 | #if EV_USE_INOTIFY |
423 | # include <sys/statfs.h> |
450 | # include <sys/statfs.h> |
… | |
… | |
607 | #define ECB_CLANG_EXTENSION(x) 0 |
634 | #define ECB_CLANG_EXTENSION(x) 0 |
608 | #endif |
635 | #endif |
609 | |
636 | |
610 | #define ECB_CPP (__cplusplus+0) |
637 | #define ECB_CPP (__cplusplus+0) |
611 | #define ECB_CPP11 (__cplusplus >= 201103L) |
638 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
639 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
640 | #define ECB_CPP17 (__cplusplus >= 201703L) |
612 | |
641 | |
613 | #if ECB_CPP |
642 | #if ECB_CPP |
614 | #define ECB_C 0 |
643 | #define ECB_C 0 |
615 | #define ECB_STDC_VERSION 0 |
644 | #define ECB_STDC_VERSION 0 |
616 | #else |
645 | #else |
… | |
… | |
618 | #define ECB_STDC_VERSION __STDC_VERSION__ |
647 | #define ECB_STDC_VERSION __STDC_VERSION__ |
619 | #endif |
648 | #endif |
620 | |
649 | |
621 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
650 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
622 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
651 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
652 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
623 | |
653 | |
624 | #if ECB_CPP |
654 | #if ECB_CPP |
625 | #define ECB_EXTERN_C extern "C" |
655 | #define ECB_EXTERN_C extern "C" |
626 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
656 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
627 | #define ECB_EXTERN_C_END } |
657 | #define ECB_EXTERN_C_END } |
… | |
… | |
656 | #ifndef ECB_MEMORY_FENCE |
686 | #ifndef ECB_MEMORY_FENCE |
657 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
687 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
658 | #if __i386 || __i386__ |
688 | #if __i386 || __i386__ |
659 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
689 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
660 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
690 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
661 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
691 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
662 | #elif ECB_GCC_AMD64 |
692 | #elif ECB_GCC_AMD64 |
663 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
693 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
664 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
694 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
695 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
666 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
696 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
667 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
697 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
668 | #elif defined __ARM_ARCH_2__ \ |
698 | #elif defined __ARM_ARCH_2__ \ |
669 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
699 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
670 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
700 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
1538 | # define ABSPRI(w) (((W)w), 0) |
1568 | # define ABSPRI(w) (((W)w), 0) |
1539 | #else |
1569 | #else |
1540 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1570 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1541 | #endif |
1571 | #endif |
1542 | |
1572 | |
1543 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1573 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1544 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1545 | |
1574 | |
1546 | typedef ev_watcher *W; |
1575 | typedef ev_watcher *W; |
1547 | typedef ev_watcher_list *WL; |
1576 | typedef ev_watcher_list *WL; |
1548 | typedef ev_watcher_time *WT; |
1577 | typedef ev_watcher_time *WT; |
1549 | |
1578 | |
… | |
… | |
1675 | { |
1704 | { |
1676 | write (STDERR_FILENO, msg, strlen (msg)); |
1705 | write (STDERR_FILENO, msg, strlen (msg)); |
1677 | } |
1706 | } |
1678 | #endif |
1707 | #endif |
1679 | |
1708 | |
1680 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1709 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1681 | |
1710 | |
1682 | ecb_cold |
1711 | ecb_cold |
1683 | void |
1712 | void |
1684 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1713 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1685 | { |
1714 | { |
1686 | syserr_cb = cb; |
1715 | syserr_cb = cb; |
1687 | } |
1716 | } |
1688 | |
1717 | |
1689 | noinline ecb_cold |
1718 | noinline ecb_cold |
… | |
… | |
1708 | abort (); |
1737 | abort (); |
1709 | } |
1738 | } |
1710 | } |
1739 | } |
1711 | |
1740 | |
1712 | static void * |
1741 | static void * |
1713 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1742 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1714 | { |
1743 | { |
1715 | /* some systems, notably openbsd and darwin, fail to properly |
1744 | /* some systems, notably openbsd and darwin, fail to properly |
1716 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1745 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1717 | * the single unix specification, so work around them here. |
1746 | * the single unix specification, so work around them here. |
1718 | * recently, also (at least) fedora and debian started breaking it, |
1747 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1724 | |
1753 | |
1725 | free (ptr); |
1754 | free (ptr); |
1726 | return 0; |
1755 | return 0; |
1727 | } |
1756 | } |
1728 | |
1757 | |
1729 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1758 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1730 | |
1759 | |
1731 | ecb_cold |
1760 | ecb_cold |
1732 | void |
1761 | void |
1733 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1762 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1734 | { |
1763 | { |
1735 | alloc = cb; |
1764 | alloc = cb; |
1736 | } |
1765 | } |
1737 | |
1766 | |
1738 | inline_speed void * |
1767 | inline_speed void * |
… | |
… | |
1765 | typedef struct |
1794 | typedef struct |
1766 | { |
1795 | { |
1767 | WL head; |
1796 | WL head; |
1768 | unsigned char events; /* the events watched for */ |
1797 | unsigned char events; /* the events watched for */ |
1769 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1798 | 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 */ |
1799 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1771 | unsigned char unused; |
1800 | unsigned char unused; |
1772 | #if EV_USE_EPOLL |
1801 | #if EV_USE_EPOLL |
1773 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1802 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1774 | #endif |
1803 | #endif |
1775 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1804 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1855 | |
1884 | |
1856 | /*****************************************************************************/ |
1885 | /*****************************************************************************/ |
1857 | |
1886 | |
1858 | #ifndef EV_HAVE_EV_TIME |
1887 | #ifndef EV_HAVE_EV_TIME |
1859 | ev_tstamp |
1888 | ev_tstamp |
1860 | ev_time (void) EV_THROW |
1889 | ev_time (void) EV_NOEXCEPT |
1861 | { |
1890 | { |
1862 | #if EV_USE_REALTIME |
1891 | #if EV_USE_REALTIME |
1863 | if (expect_true (have_realtime)) |
1892 | if (expect_true (have_realtime)) |
1864 | { |
1893 | { |
1865 | struct timespec ts; |
1894 | struct timespec ts; |
… | |
… | |
1889 | return ev_time (); |
1918 | return ev_time (); |
1890 | } |
1919 | } |
1891 | |
1920 | |
1892 | #if EV_MULTIPLICITY |
1921 | #if EV_MULTIPLICITY |
1893 | ev_tstamp |
1922 | ev_tstamp |
1894 | ev_now (EV_P) EV_THROW |
1923 | ev_now (EV_P) EV_NOEXCEPT |
1895 | { |
1924 | { |
1896 | return ev_rt_now; |
1925 | return ev_rt_now; |
1897 | } |
1926 | } |
1898 | #endif |
1927 | #endif |
1899 | |
1928 | |
1900 | void |
1929 | void |
1901 | ev_sleep (ev_tstamp delay) EV_THROW |
1930 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1902 | { |
1931 | { |
1903 | if (delay > 0.) |
1932 | if (delay > 0.) |
1904 | { |
1933 | { |
1905 | #if EV_USE_NANOSLEEP |
1934 | #if EV_USE_NANOSLEEP |
1906 | struct timespec ts; |
1935 | struct timespec ts; |
… | |
… | |
1956 | { |
1985 | { |
1957 | *cur = array_nextsize (elem, *cur, cnt); |
1986 | *cur = array_nextsize (elem, *cur, cnt); |
1958 | return ev_realloc (base, elem * *cur); |
1987 | return ev_realloc (base, elem * *cur); |
1959 | } |
1988 | } |
1960 | |
1989 | |
|
|
1990 | #define array_needsize_noinit(base,count) |
|
|
1991 | |
1961 | #define array_init_zero(base,count) \ |
1992 | #define array_needsize_zerofill(base,count) \ |
1962 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1993 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1963 | |
1994 | |
1964 | #define array_needsize(type,base,cur,cnt,init) \ |
1995 | #define array_needsize(type,base,cur,cnt,init) \ |
1965 | if (expect_false ((cnt) > (cur))) \ |
1996 | if (expect_false ((cnt) > (cur))) \ |
1966 | { \ |
1997 | { \ |
… | |
… | |
1992 | { |
2023 | { |
1993 | } |
2024 | } |
1994 | |
2025 | |
1995 | noinline |
2026 | noinline |
1996 | void |
2027 | void |
1997 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2028 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1998 | { |
2029 | { |
1999 | W w_ = (W)w; |
2030 | W w_ = (W)w; |
2000 | int pri = ABSPRI (w_); |
2031 | int pri = ABSPRI (w_); |
2001 | |
2032 | |
2002 | if (expect_false (w_->pending)) |
2033 | if (expect_false (w_->pending)) |
2003 | pendings [pri][w_->pending - 1].events |= revents; |
2034 | pendings [pri][w_->pending - 1].events |= revents; |
2004 | else |
2035 | else |
2005 | { |
2036 | { |
2006 | w_->pending = ++pendingcnt [pri]; |
2037 | w_->pending = ++pendingcnt [pri]; |
2007 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2038 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2008 | pendings [pri][w_->pending - 1].w = w_; |
2039 | pendings [pri][w_->pending - 1].w = w_; |
2009 | pendings [pri][w_->pending - 1].events = revents; |
2040 | pendings [pri][w_->pending - 1].events = revents; |
2010 | } |
2041 | } |
2011 | |
2042 | |
2012 | pendingpri = NUMPRI - 1; |
2043 | pendingpri = NUMPRI - 1; |
2013 | } |
2044 | } |
2014 | |
2045 | |
2015 | inline_speed void |
2046 | inline_speed void |
2016 | feed_reverse (EV_P_ W w) |
2047 | feed_reverse (EV_P_ W w) |
2017 | { |
2048 | { |
2018 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2049 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2019 | rfeeds [rfeedcnt++] = w; |
2050 | rfeeds [rfeedcnt++] = w; |
2020 | } |
2051 | } |
2021 | |
2052 | |
2022 | inline_size void |
2053 | inline_size void |
2023 | feed_reverse_done (EV_P_ int revents) |
2054 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2063 | if (expect_true (!anfd->reify)) |
2094 | if (expect_true (!anfd->reify)) |
2064 | fd_event_nocheck (EV_A_ fd, revents); |
2095 | fd_event_nocheck (EV_A_ fd, revents); |
2065 | } |
2096 | } |
2066 | |
2097 | |
2067 | void |
2098 | void |
2068 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2099 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2069 | { |
2100 | { |
2070 | if (fd >= 0 && fd < anfdmax) |
2101 | if (fd >= 0 && fd < anfdmax) |
2071 | fd_event_nocheck (EV_A_ fd, revents); |
2102 | fd_event_nocheck (EV_A_ fd, revents); |
2072 | } |
2103 | } |
2073 | |
2104 | |
… | |
… | |
2141 | anfds [fd].reify |= flags; |
2172 | anfds [fd].reify |= flags; |
2142 | |
2173 | |
2143 | if (expect_true (!reify)) |
2174 | if (expect_true (!reify)) |
2144 | { |
2175 | { |
2145 | ++fdchangecnt; |
2176 | ++fdchangecnt; |
2146 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2177 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2147 | fdchanges [fdchangecnt - 1] = fd; |
2178 | fdchanges [fdchangecnt - 1] = fd; |
2148 | } |
2179 | } |
2149 | } |
2180 | } |
2150 | |
2181 | |
2151 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2182 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
… | |
… | |
2473 | #endif |
2504 | #endif |
2474 | { |
2505 | { |
2475 | #ifdef _WIN32 |
2506 | #ifdef _WIN32 |
2476 | WSABUF buf; |
2507 | WSABUF buf; |
2477 | DWORD sent; |
2508 | DWORD sent; |
2478 | buf.buf = &buf; |
2509 | buf.buf = (char *)&buf; |
2479 | buf.len = 1; |
2510 | buf.len = 1; |
2480 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2511 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2481 | #else |
2512 | #else |
2482 | write (evpipe [1], &(evpipe [1]), 1); |
2513 | write (evpipe [1], &(evpipe [1]), 1); |
2483 | #endif |
2514 | #endif |
… | |
… | |
2555 | } |
2586 | } |
2556 | |
2587 | |
2557 | /*****************************************************************************/ |
2588 | /*****************************************************************************/ |
2558 | |
2589 | |
2559 | void |
2590 | void |
2560 | ev_feed_signal (int signum) EV_THROW |
2591 | ev_feed_signal (int signum) EV_NOEXCEPT |
2561 | { |
2592 | { |
2562 | #if EV_MULTIPLICITY |
2593 | #if EV_MULTIPLICITY |
2563 | EV_P; |
2594 | EV_P; |
2564 | ECB_MEMORY_FENCE_ACQUIRE; |
2595 | ECB_MEMORY_FENCE_ACQUIRE; |
2565 | EV_A = signals [signum - 1].loop; |
2596 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2582 | ev_feed_signal (signum); |
2613 | ev_feed_signal (signum); |
2583 | } |
2614 | } |
2584 | |
2615 | |
2585 | noinline |
2616 | noinline |
2586 | void |
2617 | void |
2587 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2618 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2588 | { |
2619 | { |
2589 | WL w; |
2620 | WL w; |
2590 | |
2621 | |
2591 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2622 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2592 | return; |
2623 | return; |
… | |
… | |
2698 | # include "ev_port.c" |
2729 | # include "ev_port.c" |
2699 | #endif |
2730 | #endif |
2700 | #if EV_USE_KQUEUE |
2731 | #if EV_USE_KQUEUE |
2701 | # include "ev_kqueue.c" |
2732 | # include "ev_kqueue.c" |
2702 | #endif |
2733 | #endif |
|
|
2734 | #if EV_USE_LINUXAIO |
|
|
2735 | # include "ev_linuxaio.c" |
|
|
2736 | #endif |
2703 | #if EV_USE_EPOLL |
2737 | #if EV_USE_EPOLL |
2704 | # include "ev_epoll.c" |
2738 | # include "ev_epoll.c" |
2705 | #endif |
2739 | #endif |
2706 | #if EV_USE_POLL |
2740 | #if EV_USE_POLL |
2707 | # include "ev_poll.c" |
2741 | # include "ev_poll.c" |
… | |
… | |
2709 | #if EV_USE_SELECT |
2743 | #if EV_USE_SELECT |
2710 | # include "ev_select.c" |
2744 | # include "ev_select.c" |
2711 | #endif |
2745 | #endif |
2712 | |
2746 | |
2713 | ecb_cold int |
2747 | ecb_cold int |
2714 | ev_version_major (void) EV_THROW |
2748 | ev_version_major (void) EV_NOEXCEPT |
2715 | { |
2749 | { |
2716 | return EV_VERSION_MAJOR; |
2750 | return EV_VERSION_MAJOR; |
2717 | } |
2751 | } |
2718 | |
2752 | |
2719 | ecb_cold int |
2753 | ecb_cold int |
2720 | ev_version_minor (void) EV_THROW |
2754 | ev_version_minor (void) EV_NOEXCEPT |
2721 | { |
2755 | { |
2722 | return EV_VERSION_MINOR; |
2756 | return EV_VERSION_MINOR; |
2723 | } |
2757 | } |
2724 | |
2758 | |
2725 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2759 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2734 | #endif |
2768 | #endif |
2735 | } |
2769 | } |
2736 | |
2770 | |
2737 | ecb_cold |
2771 | ecb_cold |
2738 | unsigned int |
2772 | unsigned int |
2739 | ev_supported_backends (void) EV_THROW |
2773 | ev_supported_backends (void) EV_NOEXCEPT |
2740 | { |
2774 | { |
2741 | unsigned int flags = 0; |
2775 | unsigned int flags = 0; |
2742 | |
2776 | |
2743 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2777 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2744 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2778 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2745 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2779 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2780 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2746 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2781 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2747 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2782 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2748 | |
2783 | |
2749 | return flags; |
2784 | return flags; |
2750 | } |
2785 | } |
2751 | |
2786 | |
2752 | ecb_cold |
2787 | ecb_cold |
2753 | unsigned int |
2788 | unsigned int |
2754 | ev_recommended_backends (void) EV_THROW |
2789 | ev_recommended_backends (void) EV_NOEXCEPT |
2755 | { |
2790 | { |
2756 | unsigned int flags = ev_supported_backends (); |
2791 | unsigned int flags = ev_supported_backends (); |
2757 | |
2792 | |
2758 | #ifndef __NetBSD__ |
2793 | #ifndef __NetBSD__ |
2759 | /* kqueue is borked on everything but netbsd apparently */ |
2794 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2767 | #endif |
2802 | #endif |
2768 | #ifdef __FreeBSD__ |
2803 | #ifdef __FreeBSD__ |
2769 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2804 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2770 | #endif |
2805 | #endif |
2771 | |
2806 | |
|
|
2807 | /* TODO: linuxaio is very experimental */ |
|
|
2808 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2809 | |
2772 | return flags; |
2810 | return flags; |
2773 | } |
2811 | } |
2774 | |
2812 | |
2775 | ecb_cold |
2813 | ecb_cold |
2776 | unsigned int |
2814 | unsigned int |
2777 | ev_embeddable_backends (void) EV_THROW |
2815 | ev_embeddable_backends (void) EV_NOEXCEPT |
2778 | { |
2816 | { |
2779 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2817 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2780 | |
2818 | |
2781 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2819 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2782 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2820 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2784 | |
2822 | |
2785 | return flags; |
2823 | return flags; |
2786 | } |
2824 | } |
2787 | |
2825 | |
2788 | unsigned int |
2826 | unsigned int |
2789 | ev_backend (EV_P) EV_THROW |
2827 | ev_backend (EV_P) EV_NOEXCEPT |
2790 | { |
2828 | { |
2791 | return backend; |
2829 | return backend; |
2792 | } |
2830 | } |
2793 | |
2831 | |
2794 | #if EV_FEATURE_API |
2832 | #if EV_FEATURE_API |
2795 | unsigned int |
2833 | unsigned int |
2796 | ev_iteration (EV_P) EV_THROW |
2834 | ev_iteration (EV_P) EV_NOEXCEPT |
2797 | { |
2835 | { |
2798 | return loop_count; |
2836 | return loop_count; |
2799 | } |
2837 | } |
2800 | |
2838 | |
2801 | unsigned int |
2839 | unsigned int |
2802 | ev_depth (EV_P) EV_THROW |
2840 | ev_depth (EV_P) EV_NOEXCEPT |
2803 | { |
2841 | { |
2804 | return loop_depth; |
2842 | return loop_depth; |
2805 | } |
2843 | } |
2806 | |
2844 | |
2807 | void |
2845 | void |
2808 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2846 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2809 | { |
2847 | { |
2810 | io_blocktime = interval; |
2848 | io_blocktime = interval; |
2811 | } |
2849 | } |
2812 | |
2850 | |
2813 | void |
2851 | void |
2814 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2852 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2815 | { |
2853 | { |
2816 | timeout_blocktime = interval; |
2854 | timeout_blocktime = interval; |
2817 | } |
2855 | } |
2818 | |
2856 | |
2819 | void |
2857 | void |
2820 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2858 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2821 | { |
2859 | { |
2822 | userdata = data; |
2860 | userdata = data; |
2823 | } |
2861 | } |
2824 | |
2862 | |
2825 | void * |
2863 | void * |
2826 | ev_userdata (EV_P) EV_THROW |
2864 | ev_userdata (EV_P) EV_NOEXCEPT |
2827 | { |
2865 | { |
2828 | return userdata; |
2866 | return userdata; |
2829 | } |
2867 | } |
2830 | |
2868 | |
2831 | void |
2869 | void |
2832 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
2870 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2833 | { |
2871 | { |
2834 | invoke_cb = invoke_pending_cb; |
2872 | invoke_cb = invoke_pending_cb; |
2835 | } |
2873 | } |
2836 | |
2874 | |
2837 | void |
2875 | void |
2838 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2876 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2839 | { |
2877 | { |
2840 | release_cb = release; |
2878 | release_cb = release; |
2841 | acquire_cb = acquire; |
2879 | acquire_cb = acquire; |
2842 | } |
2880 | } |
2843 | #endif |
2881 | #endif |
2844 | |
2882 | |
2845 | /* initialise a loop structure, must be zero-initialised */ |
2883 | /* initialise a loop structure, must be zero-initialised */ |
2846 | noinline ecb_cold |
2884 | noinline ecb_cold |
2847 | static void |
2885 | static void |
2848 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2886 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2849 | { |
2887 | { |
2850 | if (!backend) |
2888 | if (!backend) |
2851 | { |
2889 | { |
2852 | origflags = flags; |
2890 | origflags = flags; |
2853 | |
2891 | |
… | |
… | |
2911 | |
2949 | |
2912 | if (!(flags & EVBACKEND_MASK)) |
2950 | if (!(flags & EVBACKEND_MASK)) |
2913 | flags |= ev_recommended_backends (); |
2951 | flags |= ev_recommended_backends (); |
2914 | |
2952 | |
2915 | #if EV_USE_IOCP |
2953 | #if EV_USE_IOCP |
2916 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2954 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2917 | #endif |
2955 | #endif |
2918 | #if EV_USE_PORT |
2956 | #if EV_USE_PORT |
2919 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2957 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2920 | #endif |
2958 | #endif |
2921 | #if EV_USE_KQUEUE |
2959 | #if EV_USE_KQUEUE |
2922 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
2960 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
|
|
2961 | #endif |
|
|
2962 | #if EV_USE_LINUXAIO |
|
|
2963 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2923 | #endif |
2964 | #endif |
2924 | #if EV_USE_EPOLL |
2965 | #if EV_USE_EPOLL |
2925 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2966 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2926 | #endif |
2967 | #endif |
2927 | #if EV_USE_POLL |
2968 | #if EV_USE_POLL |
2928 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2969 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2929 | #endif |
2970 | #endif |
2930 | #if EV_USE_SELECT |
2971 | #if EV_USE_SELECT |
2931 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2972 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2932 | #endif |
2973 | #endif |
2933 | |
2974 | |
2934 | ev_prepare_init (&pending_w, pendingcb); |
2975 | ev_prepare_init (&pending_w, pendingcb); |
2935 | |
2976 | |
2936 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2977 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2991 | |
3032 | |
2992 | if (backend_fd >= 0) |
3033 | if (backend_fd >= 0) |
2993 | close (backend_fd); |
3034 | close (backend_fd); |
2994 | |
3035 | |
2995 | #if EV_USE_IOCP |
3036 | #if EV_USE_IOCP |
2996 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3037 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2997 | #endif |
3038 | #endif |
2998 | #if EV_USE_PORT |
3039 | #if EV_USE_PORT |
2999 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3040 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3000 | #endif |
3041 | #endif |
3001 | #if EV_USE_KQUEUE |
3042 | #if EV_USE_KQUEUE |
3002 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
3043 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3044 | #endif |
|
|
3045 | #if EV_USE_LINUXAIO |
|
|
3046 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3003 | #endif |
3047 | #endif |
3004 | #if EV_USE_EPOLL |
3048 | #if EV_USE_EPOLL |
3005 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3049 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3006 | #endif |
3050 | #endif |
3007 | #if EV_USE_POLL |
3051 | #if EV_USE_POLL |
3008 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3052 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3009 | #endif |
3053 | #endif |
3010 | #if EV_USE_SELECT |
3054 | #if EV_USE_SELECT |
3011 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3055 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3012 | #endif |
3056 | #endif |
3013 | |
3057 | |
3014 | for (i = NUMPRI; i--; ) |
3058 | for (i = NUMPRI; i--; ) |
3015 | { |
3059 | { |
3016 | array_free (pending, [i]); |
3060 | array_free (pending, [i]); |
… | |
… | |
3058 | |
3102 | |
3059 | inline_size void |
3103 | inline_size void |
3060 | loop_fork (EV_P) |
3104 | loop_fork (EV_P) |
3061 | { |
3105 | { |
3062 | #if EV_USE_PORT |
3106 | #if EV_USE_PORT |
3063 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3107 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3064 | #endif |
3108 | #endif |
3065 | #if EV_USE_KQUEUE |
3109 | #if EV_USE_KQUEUE |
3066 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
3110 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3111 | #endif |
|
|
3112 | #if EV_USE_LINUXAIO |
|
|
3113 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3067 | #endif |
3114 | #endif |
3068 | #if EV_USE_EPOLL |
3115 | #if EV_USE_EPOLL |
3069 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3116 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3070 | #endif |
3117 | #endif |
3071 | #if EV_USE_INOTIFY |
3118 | #if EV_USE_INOTIFY |
3072 | infy_fork (EV_A); |
3119 | infy_fork (EV_A); |
3073 | #endif |
3120 | #endif |
3074 | |
3121 | |
… | |
… | |
3094 | |
3141 | |
3095 | #if EV_MULTIPLICITY |
3142 | #if EV_MULTIPLICITY |
3096 | |
3143 | |
3097 | ecb_cold |
3144 | ecb_cold |
3098 | struct ev_loop * |
3145 | struct ev_loop * |
3099 | ev_loop_new (unsigned int flags) EV_THROW |
3146 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3100 | { |
3147 | { |
3101 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3148 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3102 | |
3149 | |
3103 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3150 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3104 | loop_init (EV_A_ flags); |
3151 | loop_init (EV_A_ flags); |
… | |
… | |
3151 | } |
3198 | } |
3152 | #endif |
3199 | #endif |
3153 | |
3200 | |
3154 | #if EV_FEATURE_API |
3201 | #if EV_FEATURE_API |
3155 | void ecb_cold |
3202 | void ecb_cold |
3156 | ev_verify (EV_P) EV_THROW |
3203 | ev_verify (EV_P) EV_NOEXCEPT |
3157 | { |
3204 | { |
3158 | #if EV_VERIFY |
3205 | #if EV_VERIFY |
3159 | int i; |
3206 | int i; |
3160 | WL w, w2; |
3207 | WL w, w2; |
3161 | |
3208 | |
… | |
… | |
3242 | ecb_cold |
3289 | ecb_cold |
3243 | struct ev_loop * |
3290 | struct ev_loop * |
3244 | #else |
3291 | #else |
3245 | int |
3292 | int |
3246 | #endif |
3293 | #endif |
3247 | ev_default_loop (unsigned int flags) EV_THROW |
3294 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3248 | { |
3295 | { |
3249 | if (!ev_default_loop_ptr) |
3296 | if (!ev_default_loop_ptr) |
3250 | { |
3297 | { |
3251 | #if EV_MULTIPLICITY |
3298 | #if EV_MULTIPLICITY |
3252 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3299 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3271 | |
3318 | |
3272 | return ev_default_loop_ptr; |
3319 | return ev_default_loop_ptr; |
3273 | } |
3320 | } |
3274 | |
3321 | |
3275 | void |
3322 | void |
3276 | ev_loop_fork (EV_P) EV_THROW |
3323 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3277 | { |
3324 | { |
3278 | postfork = 1; |
3325 | postfork = 1; |
3279 | } |
3326 | } |
3280 | |
3327 | |
3281 | /*****************************************************************************/ |
3328 | /*****************************************************************************/ |
… | |
… | |
3285 | { |
3332 | { |
3286 | EV_CB_INVOKE ((W)w, revents); |
3333 | EV_CB_INVOKE ((W)w, revents); |
3287 | } |
3334 | } |
3288 | |
3335 | |
3289 | unsigned int |
3336 | unsigned int |
3290 | ev_pending_count (EV_P) EV_THROW |
3337 | ev_pending_count (EV_P) EV_NOEXCEPT |
3291 | { |
3338 | { |
3292 | int pri; |
3339 | int pri; |
3293 | unsigned int count = 0; |
3340 | unsigned int count = 0; |
3294 | |
3341 | |
3295 | for (pri = NUMPRI; pri--; ) |
3342 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3302 | void |
3349 | void |
3303 | ev_invoke_pending (EV_P) |
3350 | ev_invoke_pending (EV_P) |
3304 | { |
3351 | { |
3305 | pendingpri = NUMPRI; |
3352 | pendingpri = NUMPRI; |
3306 | |
3353 | |
3307 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3354 | do |
3308 | { |
3355 | { |
3309 | --pendingpri; |
3356 | --pendingpri; |
3310 | |
3357 | |
|
|
3358 | /* pendingpri possibly gets modified in the inner loop */ |
3311 | while (pendingcnt [pendingpri]) |
3359 | while (pendingcnt [pendingpri]) |
3312 | { |
3360 | { |
3313 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3361 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3314 | |
3362 | |
3315 | p->w->pending = 0; |
3363 | p->w->pending = 0; |
3316 | EV_CB_INVOKE (p->w, p->events); |
3364 | EV_CB_INVOKE (p->w, p->events); |
3317 | EV_FREQUENT_CHECK; |
3365 | EV_FREQUENT_CHECK; |
3318 | } |
3366 | } |
3319 | } |
3367 | } |
|
|
3368 | while (pendingpri); |
3320 | } |
3369 | } |
3321 | |
3370 | |
3322 | #if EV_IDLE_ENABLE |
3371 | #if EV_IDLE_ENABLE |
3323 | /* make idle watchers pending. this handles the "call-idle */ |
3372 | /* make idle watchers pending. this handles the "call-idle */ |
3324 | /* only when higher priorities are idle" logic */ |
3373 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3733 | |
3782 | |
3734 | return activecnt; |
3783 | return activecnt; |
3735 | } |
3784 | } |
3736 | |
3785 | |
3737 | void |
3786 | void |
3738 | ev_break (EV_P_ int how) EV_THROW |
3787 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3739 | { |
3788 | { |
3740 | loop_done = how; |
3789 | loop_done = how; |
3741 | } |
3790 | } |
3742 | |
3791 | |
3743 | void |
3792 | void |
3744 | ev_ref (EV_P) EV_THROW |
3793 | ev_ref (EV_P) EV_NOEXCEPT |
3745 | { |
3794 | { |
3746 | ++activecnt; |
3795 | ++activecnt; |
3747 | } |
3796 | } |
3748 | |
3797 | |
3749 | void |
3798 | void |
3750 | ev_unref (EV_P) EV_THROW |
3799 | ev_unref (EV_P) EV_NOEXCEPT |
3751 | { |
3800 | { |
3752 | --activecnt; |
3801 | --activecnt; |
3753 | } |
3802 | } |
3754 | |
3803 | |
3755 | void |
3804 | void |
3756 | ev_now_update (EV_P) EV_THROW |
3805 | ev_now_update (EV_P) EV_NOEXCEPT |
3757 | { |
3806 | { |
3758 | time_update (EV_A_ 1e100); |
3807 | time_update (EV_A_ 1e100); |
3759 | } |
3808 | } |
3760 | |
3809 | |
3761 | void |
3810 | void |
3762 | ev_suspend (EV_P) EV_THROW |
3811 | ev_suspend (EV_P) EV_NOEXCEPT |
3763 | { |
3812 | { |
3764 | ev_now_update (EV_A); |
3813 | ev_now_update (EV_A); |
3765 | } |
3814 | } |
3766 | |
3815 | |
3767 | void |
3816 | void |
3768 | ev_resume (EV_P) EV_THROW |
3817 | ev_resume (EV_P) EV_NOEXCEPT |
3769 | { |
3818 | { |
3770 | ev_tstamp mn_prev = mn_now; |
3819 | ev_tstamp mn_prev = mn_now; |
3771 | |
3820 | |
3772 | ev_now_update (EV_A); |
3821 | ev_now_update (EV_A); |
3773 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3822 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3812 | w->pending = 0; |
3861 | w->pending = 0; |
3813 | } |
3862 | } |
3814 | } |
3863 | } |
3815 | |
3864 | |
3816 | int |
3865 | int |
3817 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3866 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3818 | { |
3867 | { |
3819 | W w_ = (W)w; |
3868 | W w_ = (W)w; |
3820 | int pending = w_->pending; |
3869 | int pending = w_->pending; |
3821 | |
3870 | |
3822 | if (expect_true (pending)) |
3871 | if (expect_true (pending)) |
… | |
… | |
3856 | |
3905 | |
3857 | /*****************************************************************************/ |
3906 | /*****************************************************************************/ |
3858 | |
3907 | |
3859 | noinline |
3908 | noinline |
3860 | void |
3909 | void |
3861 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3910 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3862 | { |
3911 | { |
3863 | int fd = w->fd; |
3912 | int fd = w->fd; |
3864 | |
3913 | |
3865 | if (expect_false (ev_is_active (w))) |
3914 | if (expect_false (ev_is_active (w))) |
3866 | return; |
3915 | return; |
… | |
… | |
3869 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3918 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3870 | |
3919 | |
3871 | EV_FREQUENT_CHECK; |
3920 | EV_FREQUENT_CHECK; |
3872 | |
3921 | |
3873 | ev_start (EV_A_ (W)w, 1); |
3922 | ev_start (EV_A_ (W)w, 1); |
3874 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3923 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3875 | wlist_add (&anfds[fd].head, (WL)w); |
3924 | wlist_add (&anfds[fd].head, (WL)w); |
3876 | |
3925 | |
3877 | /* common bug, apparently */ |
3926 | /* common bug, apparently */ |
3878 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3927 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3879 | |
3928 | |
… | |
… | |
3883 | EV_FREQUENT_CHECK; |
3932 | EV_FREQUENT_CHECK; |
3884 | } |
3933 | } |
3885 | |
3934 | |
3886 | noinline |
3935 | noinline |
3887 | void |
3936 | void |
3888 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3937 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3889 | { |
3938 | { |
3890 | clear_pending (EV_A_ (W)w); |
3939 | clear_pending (EV_A_ (W)w); |
3891 | if (expect_false (!ev_is_active (w))) |
3940 | if (expect_false (!ev_is_active (w))) |
3892 | return; |
3941 | return; |
3893 | |
3942 | |
… | |
… | |
3903 | EV_FREQUENT_CHECK; |
3952 | EV_FREQUENT_CHECK; |
3904 | } |
3953 | } |
3905 | |
3954 | |
3906 | noinline |
3955 | noinline |
3907 | void |
3956 | void |
3908 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3957 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3909 | { |
3958 | { |
3910 | if (expect_false (ev_is_active (w))) |
3959 | if (expect_false (ev_is_active (w))) |
3911 | return; |
3960 | return; |
3912 | |
3961 | |
3913 | ev_at (w) += mn_now; |
3962 | ev_at (w) += mn_now; |
… | |
… | |
3916 | |
3965 | |
3917 | EV_FREQUENT_CHECK; |
3966 | EV_FREQUENT_CHECK; |
3918 | |
3967 | |
3919 | ++timercnt; |
3968 | ++timercnt; |
3920 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3969 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3921 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3970 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3922 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3971 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3923 | ANHE_at_cache (timers [ev_active (w)]); |
3972 | ANHE_at_cache (timers [ev_active (w)]); |
3924 | upheap (timers, ev_active (w)); |
3973 | upheap (timers, ev_active (w)); |
3925 | |
3974 | |
3926 | EV_FREQUENT_CHECK; |
3975 | EV_FREQUENT_CHECK; |
… | |
… | |
3928 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3977 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3929 | } |
3978 | } |
3930 | |
3979 | |
3931 | noinline |
3980 | noinline |
3932 | void |
3981 | void |
3933 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3982 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3934 | { |
3983 | { |
3935 | clear_pending (EV_A_ (W)w); |
3984 | clear_pending (EV_A_ (W)w); |
3936 | if (expect_false (!ev_is_active (w))) |
3985 | if (expect_false (!ev_is_active (w))) |
3937 | return; |
3986 | return; |
3938 | |
3987 | |
… | |
… | |
3959 | EV_FREQUENT_CHECK; |
4008 | EV_FREQUENT_CHECK; |
3960 | } |
4009 | } |
3961 | |
4010 | |
3962 | noinline |
4011 | noinline |
3963 | void |
4012 | void |
3964 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4013 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3965 | { |
4014 | { |
3966 | EV_FREQUENT_CHECK; |
4015 | EV_FREQUENT_CHECK; |
3967 | |
4016 | |
3968 | clear_pending (EV_A_ (W)w); |
4017 | clear_pending (EV_A_ (W)w); |
3969 | |
4018 | |
… | |
… | |
3986 | |
4035 | |
3987 | EV_FREQUENT_CHECK; |
4036 | EV_FREQUENT_CHECK; |
3988 | } |
4037 | } |
3989 | |
4038 | |
3990 | ev_tstamp |
4039 | ev_tstamp |
3991 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4040 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3992 | { |
4041 | { |
3993 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4042 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3994 | } |
4043 | } |
3995 | |
4044 | |
3996 | #if EV_PERIODIC_ENABLE |
4045 | #if EV_PERIODIC_ENABLE |
3997 | noinline |
4046 | noinline |
3998 | void |
4047 | void |
3999 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4048 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4000 | { |
4049 | { |
4001 | if (expect_false (ev_is_active (w))) |
4050 | if (expect_false (ev_is_active (w))) |
4002 | return; |
4051 | return; |
4003 | |
4052 | |
4004 | if (w->reschedule_cb) |
4053 | if (w->reschedule_cb) |
… | |
… | |
4013 | |
4062 | |
4014 | EV_FREQUENT_CHECK; |
4063 | EV_FREQUENT_CHECK; |
4015 | |
4064 | |
4016 | ++periodiccnt; |
4065 | ++periodiccnt; |
4017 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4066 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4018 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4067 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4019 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4068 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4020 | ANHE_at_cache (periodics [ev_active (w)]); |
4069 | ANHE_at_cache (periodics [ev_active (w)]); |
4021 | upheap (periodics, ev_active (w)); |
4070 | upheap (periodics, ev_active (w)); |
4022 | |
4071 | |
4023 | EV_FREQUENT_CHECK; |
4072 | EV_FREQUENT_CHECK; |
… | |
… | |
4025 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4074 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4026 | } |
4075 | } |
4027 | |
4076 | |
4028 | noinline |
4077 | noinline |
4029 | void |
4078 | void |
4030 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4079 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4031 | { |
4080 | { |
4032 | clear_pending (EV_A_ (W)w); |
4081 | clear_pending (EV_A_ (W)w); |
4033 | if (expect_false (!ev_is_active (w))) |
4082 | if (expect_false (!ev_is_active (w))) |
4034 | return; |
4083 | return; |
4035 | |
4084 | |
… | |
… | |
4054 | EV_FREQUENT_CHECK; |
4103 | EV_FREQUENT_CHECK; |
4055 | } |
4104 | } |
4056 | |
4105 | |
4057 | noinline |
4106 | noinline |
4058 | void |
4107 | void |
4059 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4108 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4060 | { |
4109 | { |
4061 | /* TODO: use adjustheap and recalculation */ |
4110 | /* TODO: use adjustheap and recalculation */ |
4062 | ev_periodic_stop (EV_A_ w); |
4111 | ev_periodic_stop (EV_A_ w); |
4063 | ev_periodic_start (EV_A_ w); |
4112 | ev_periodic_start (EV_A_ w); |
4064 | } |
4113 | } |
… | |
… | |
4070 | |
4119 | |
4071 | #if EV_SIGNAL_ENABLE |
4120 | #if EV_SIGNAL_ENABLE |
4072 | |
4121 | |
4073 | noinline |
4122 | noinline |
4074 | void |
4123 | void |
4075 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4124 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4076 | { |
4125 | { |
4077 | if (expect_false (ev_is_active (w))) |
4126 | if (expect_false (ev_is_active (w))) |
4078 | return; |
4127 | return; |
4079 | |
4128 | |
4080 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4129 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4153 | EV_FREQUENT_CHECK; |
4202 | EV_FREQUENT_CHECK; |
4154 | } |
4203 | } |
4155 | |
4204 | |
4156 | noinline |
4205 | noinline |
4157 | void |
4206 | void |
4158 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4207 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4159 | { |
4208 | { |
4160 | clear_pending (EV_A_ (W)w); |
4209 | clear_pending (EV_A_ (W)w); |
4161 | if (expect_false (!ev_is_active (w))) |
4210 | if (expect_false (!ev_is_active (w))) |
4162 | return; |
4211 | return; |
4163 | |
4212 | |
… | |
… | |
4194 | #endif |
4243 | #endif |
4195 | |
4244 | |
4196 | #if EV_CHILD_ENABLE |
4245 | #if EV_CHILD_ENABLE |
4197 | |
4246 | |
4198 | void |
4247 | void |
4199 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4248 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4200 | { |
4249 | { |
4201 | #if EV_MULTIPLICITY |
4250 | #if EV_MULTIPLICITY |
4202 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4251 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4203 | #endif |
4252 | #endif |
4204 | if (expect_false (ev_is_active (w))) |
4253 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4211 | |
4260 | |
4212 | EV_FREQUENT_CHECK; |
4261 | EV_FREQUENT_CHECK; |
4213 | } |
4262 | } |
4214 | |
4263 | |
4215 | void |
4264 | void |
4216 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4265 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4217 | { |
4266 | { |
4218 | clear_pending (EV_A_ (W)w); |
4267 | clear_pending (EV_A_ (W)w); |
4219 | if (expect_false (!ev_is_active (w))) |
4268 | if (expect_false (!ev_is_active (w))) |
4220 | return; |
4269 | return; |
4221 | |
4270 | |
… | |
… | |
4486 | #else |
4535 | #else |
4487 | # define EV_LSTAT(p,b) lstat (p, b) |
4536 | # define EV_LSTAT(p,b) lstat (p, b) |
4488 | #endif |
4537 | #endif |
4489 | |
4538 | |
4490 | void |
4539 | void |
4491 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4540 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4492 | { |
4541 | { |
4493 | if (lstat (w->path, &w->attr) < 0) |
4542 | if (lstat (w->path, &w->attr) < 0) |
4494 | w->attr.st_nlink = 0; |
4543 | w->attr.st_nlink = 0; |
4495 | else if (!w->attr.st_nlink) |
4544 | else if (!w->attr.st_nlink) |
4496 | w->attr.st_nlink = 1; |
4545 | w->attr.st_nlink = 1; |
… | |
… | |
4536 | ev_feed_event (EV_A_ w, EV_STAT); |
4585 | ev_feed_event (EV_A_ w, EV_STAT); |
4537 | } |
4586 | } |
4538 | } |
4587 | } |
4539 | |
4588 | |
4540 | void |
4589 | void |
4541 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4590 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4542 | { |
4591 | { |
4543 | if (expect_false (ev_is_active (w))) |
4592 | if (expect_false (ev_is_active (w))) |
4544 | return; |
4593 | return; |
4545 | |
4594 | |
4546 | ev_stat_stat (EV_A_ w); |
4595 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4567 | |
4616 | |
4568 | EV_FREQUENT_CHECK; |
4617 | EV_FREQUENT_CHECK; |
4569 | } |
4618 | } |
4570 | |
4619 | |
4571 | void |
4620 | void |
4572 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4621 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4573 | { |
4622 | { |
4574 | clear_pending (EV_A_ (W)w); |
4623 | clear_pending (EV_A_ (W)w); |
4575 | if (expect_false (!ev_is_active (w))) |
4624 | if (expect_false (!ev_is_active (w))) |
4576 | return; |
4625 | return; |
4577 | |
4626 | |
… | |
… | |
4593 | } |
4642 | } |
4594 | #endif |
4643 | #endif |
4595 | |
4644 | |
4596 | #if EV_IDLE_ENABLE |
4645 | #if EV_IDLE_ENABLE |
4597 | void |
4646 | void |
4598 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4647 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4599 | { |
4648 | { |
4600 | if (expect_false (ev_is_active (w))) |
4649 | if (expect_false (ev_is_active (w))) |
4601 | return; |
4650 | return; |
4602 | |
4651 | |
4603 | pri_adjust (EV_A_ (W)w); |
4652 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4608 | int active = ++idlecnt [ABSPRI (w)]; |
4657 | int active = ++idlecnt [ABSPRI (w)]; |
4609 | |
4658 | |
4610 | ++idleall; |
4659 | ++idleall; |
4611 | ev_start (EV_A_ (W)w, active); |
4660 | ev_start (EV_A_ (W)w, active); |
4612 | |
4661 | |
4613 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4662 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4614 | idles [ABSPRI (w)][active - 1] = w; |
4663 | idles [ABSPRI (w)][active - 1] = w; |
4615 | } |
4664 | } |
4616 | |
4665 | |
4617 | EV_FREQUENT_CHECK; |
4666 | EV_FREQUENT_CHECK; |
4618 | } |
4667 | } |
4619 | |
4668 | |
4620 | void |
4669 | void |
4621 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4670 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4622 | { |
4671 | { |
4623 | clear_pending (EV_A_ (W)w); |
4672 | clear_pending (EV_A_ (W)w); |
4624 | if (expect_false (!ev_is_active (w))) |
4673 | if (expect_false (!ev_is_active (w))) |
4625 | return; |
4674 | return; |
4626 | |
4675 | |
… | |
… | |
4640 | } |
4689 | } |
4641 | #endif |
4690 | #endif |
4642 | |
4691 | |
4643 | #if EV_PREPARE_ENABLE |
4692 | #if EV_PREPARE_ENABLE |
4644 | void |
4693 | void |
4645 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4694 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4646 | { |
4695 | { |
4647 | if (expect_false (ev_is_active (w))) |
4696 | if (expect_false (ev_is_active (w))) |
4648 | return; |
4697 | return; |
4649 | |
4698 | |
4650 | EV_FREQUENT_CHECK; |
4699 | EV_FREQUENT_CHECK; |
4651 | |
4700 | |
4652 | ev_start (EV_A_ (W)w, ++preparecnt); |
4701 | ev_start (EV_A_ (W)w, ++preparecnt); |
4653 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4702 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4654 | prepares [preparecnt - 1] = w; |
4703 | prepares [preparecnt - 1] = w; |
4655 | |
4704 | |
4656 | EV_FREQUENT_CHECK; |
4705 | EV_FREQUENT_CHECK; |
4657 | } |
4706 | } |
4658 | |
4707 | |
4659 | void |
4708 | void |
4660 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4709 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4661 | { |
4710 | { |
4662 | clear_pending (EV_A_ (W)w); |
4711 | clear_pending (EV_A_ (W)w); |
4663 | if (expect_false (!ev_is_active (w))) |
4712 | if (expect_false (!ev_is_active (w))) |
4664 | return; |
4713 | return; |
4665 | |
4714 | |
… | |
… | |
4678 | } |
4727 | } |
4679 | #endif |
4728 | #endif |
4680 | |
4729 | |
4681 | #if EV_CHECK_ENABLE |
4730 | #if EV_CHECK_ENABLE |
4682 | void |
4731 | void |
4683 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4732 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4684 | { |
4733 | { |
4685 | if (expect_false (ev_is_active (w))) |
4734 | if (expect_false (ev_is_active (w))) |
4686 | return; |
4735 | return; |
4687 | |
4736 | |
4688 | EV_FREQUENT_CHECK; |
4737 | EV_FREQUENT_CHECK; |
4689 | |
4738 | |
4690 | ev_start (EV_A_ (W)w, ++checkcnt); |
4739 | ev_start (EV_A_ (W)w, ++checkcnt); |
4691 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4740 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4692 | checks [checkcnt - 1] = w; |
4741 | checks [checkcnt - 1] = w; |
4693 | |
4742 | |
4694 | EV_FREQUENT_CHECK; |
4743 | EV_FREQUENT_CHECK; |
4695 | } |
4744 | } |
4696 | |
4745 | |
4697 | void |
4746 | void |
4698 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4747 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4699 | { |
4748 | { |
4700 | clear_pending (EV_A_ (W)w); |
4749 | clear_pending (EV_A_ (W)w); |
4701 | if (expect_false (!ev_is_active (w))) |
4750 | if (expect_false (!ev_is_active (w))) |
4702 | return; |
4751 | return; |
4703 | |
4752 | |
… | |
… | |
4717 | #endif |
4766 | #endif |
4718 | |
4767 | |
4719 | #if EV_EMBED_ENABLE |
4768 | #if EV_EMBED_ENABLE |
4720 | noinline |
4769 | noinline |
4721 | void |
4770 | void |
4722 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4771 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4723 | { |
4772 | { |
4724 | ev_run (w->other, EVRUN_NOWAIT); |
4773 | ev_run (w->other, EVRUN_NOWAIT); |
4725 | } |
4774 | } |
4726 | |
4775 | |
4727 | static void |
4776 | static void |
… | |
… | |
4775 | ev_idle_stop (EV_A_ idle); |
4824 | ev_idle_stop (EV_A_ idle); |
4776 | } |
4825 | } |
4777 | #endif |
4826 | #endif |
4778 | |
4827 | |
4779 | void |
4828 | void |
4780 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4829 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4781 | { |
4830 | { |
4782 | if (expect_false (ev_is_active (w))) |
4831 | if (expect_false (ev_is_active (w))) |
4783 | return; |
4832 | return; |
4784 | |
4833 | |
4785 | { |
4834 | { |
… | |
… | |
4806 | |
4855 | |
4807 | EV_FREQUENT_CHECK; |
4856 | EV_FREQUENT_CHECK; |
4808 | } |
4857 | } |
4809 | |
4858 | |
4810 | void |
4859 | void |
4811 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4860 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4812 | { |
4861 | { |
4813 | clear_pending (EV_A_ (W)w); |
4862 | clear_pending (EV_A_ (W)w); |
4814 | if (expect_false (!ev_is_active (w))) |
4863 | if (expect_false (!ev_is_active (w))) |
4815 | return; |
4864 | return; |
4816 | |
4865 | |
… | |
… | |
4826 | } |
4875 | } |
4827 | #endif |
4876 | #endif |
4828 | |
4877 | |
4829 | #if EV_FORK_ENABLE |
4878 | #if EV_FORK_ENABLE |
4830 | void |
4879 | void |
4831 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4880 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4832 | { |
4881 | { |
4833 | if (expect_false (ev_is_active (w))) |
4882 | if (expect_false (ev_is_active (w))) |
4834 | return; |
4883 | return; |
4835 | |
4884 | |
4836 | EV_FREQUENT_CHECK; |
4885 | EV_FREQUENT_CHECK; |
4837 | |
4886 | |
4838 | ev_start (EV_A_ (W)w, ++forkcnt); |
4887 | ev_start (EV_A_ (W)w, ++forkcnt); |
4839 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4888 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4840 | forks [forkcnt - 1] = w; |
4889 | forks [forkcnt - 1] = w; |
4841 | |
4890 | |
4842 | EV_FREQUENT_CHECK; |
4891 | EV_FREQUENT_CHECK; |
4843 | } |
4892 | } |
4844 | |
4893 | |
4845 | void |
4894 | void |
4846 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4895 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4847 | { |
4896 | { |
4848 | clear_pending (EV_A_ (W)w); |
4897 | clear_pending (EV_A_ (W)w); |
4849 | if (expect_false (!ev_is_active (w))) |
4898 | if (expect_false (!ev_is_active (w))) |
4850 | return; |
4899 | return; |
4851 | |
4900 | |
… | |
… | |
4864 | } |
4913 | } |
4865 | #endif |
4914 | #endif |
4866 | |
4915 | |
4867 | #if EV_CLEANUP_ENABLE |
4916 | #if EV_CLEANUP_ENABLE |
4868 | void |
4917 | void |
4869 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4918 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4870 | { |
4919 | { |
4871 | if (expect_false (ev_is_active (w))) |
4920 | if (expect_false (ev_is_active (w))) |
4872 | return; |
4921 | return; |
4873 | |
4922 | |
4874 | EV_FREQUENT_CHECK; |
4923 | EV_FREQUENT_CHECK; |
4875 | |
4924 | |
4876 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4925 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4877 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4926 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4878 | cleanups [cleanupcnt - 1] = w; |
4927 | cleanups [cleanupcnt - 1] = w; |
4879 | |
4928 | |
4880 | /* cleanup watchers should never keep a refcount on the loop */ |
4929 | /* cleanup watchers should never keep a refcount on the loop */ |
4881 | ev_unref (EV_A); |
4930 | ev_unref (EV_A); |
4882 | EV_FREQUENT_CHECK; |
4931 | EV_FREQUENT_CHECK; |
4883 | } |
4932 | } |
4884 | |
4933 | |
4885 | void |
4934 | void |
4886 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4935 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4887 | { |
4936 | { |
4888 | clear_pending (EV_A_ (W)w); |
4937 | clear_pending (EV_A_ (W)w); |
4889 | if (expect_false (!ev_is_active (w))) |
4938 | if (expect_false (!ev_is_active (w))) |
4890 | return; |
4939 | return; |
4891 | |
4940 | |
… | |
… | |
4905 | } |
4954 | } |
4906 | #endif |
4955 | #endif |
4907 | |
4956 | |
4908 | #if EV_ASYNC_ENABLE |
4957 | #if EV_ASYNC_ENABLE |
4909 | void |
4958 | void |
4910 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4959 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4911 | { |
4960 | { |
4912 | if (expect_false (ev_is_active (w))) |
4961 | if (expect_false (ev_is_active (w))) |
4913 | return; |
4962 | return; |
4914 | |
4963 | |
4915 | w->sent = 0; |
4964 | w->sent = 0; |
… | |
… | |
4917 | evpipe_init (EV_A); |
4966 | evpipe_init (EV_A); |
4918 | |
4967 | |
4919 | EV_FREQUENT_CHECK; |
4968 | EV_FREQUENT_CHECK; |
4920 | |
4969 | |
4921 | ev_start (EV_A_ (W)w, ++asynccnt); |
4970 | ev_start (EV_A_ (W)w, ++asynccnt); |
4922 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4971 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4923 | asyncs [asynccnt - 1] = w; |
4972 | asyncs [asynccnt - 1] = w; |
4924 | |
4973 | |
4925 | EV_FREQUENT_CHECK; |
4974 | EV_FREQUENT_CHECK; |
4926 | } |
4975 | } |
4927 | |
4976 | |
4928 | void |
4977 | void |
4929 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4978 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4930 | { |
4979 | { |
4931 | clear_pending (EV_A_ (W)w); |
4980 | clear_pending (EV_A_ (W)w); |
4932 | if (expect_false (!ev_is_active (w))) |
4981 | if (expect_false (!ev_is_active (w))) |
4933 | return; |
4982 | return; |
4934 | |
4983 | |
… | |
… | |
4945 | |
4994 | |
4946 | EV_FREQUENT_CHECK; |
4995 | EV_FREQUENT_CHECK; |
4947 | } |
4996 | } |
4948 | |
4997 | |
4949 | void |
4998 | void |
4950 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4999 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4951 | { |
5000 | { |
4952 | w->sent = 1; |
5001 | w->sent = 1; |
4953 | evpipe_write (EV_A_ &async_pending); |
5002 | evpipe_write (EV_A_ &async_pending); |
4954 | } |
5003 | } |
4955 | #endif |
5004 | #endif |
… | |
… | |
4992 | |
5041 | |
4993 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5042 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4994 | } |
5043 | } |
4995 | |
5044 | |
4996 | void |
5045 | void |
4997 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5046 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
4998 | { |
5047 | { |
4999 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5048 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5000 | |
|
|
5001 | if (expect_false (!once)) |
|
|
5002 | { |
|
|
5003 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5004 | return; |
|
|
5005 | } |
|
|
5006 | |
5049 | |
5007 | once->cb = cb; |
5050 | once->cb = cb; |
5008 | once->arg = arg; |
5051 | once->arg = arg; |
5009 | |
5052 | |
5010 | ev_init (&once->io, once_cb_io); |
5053 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5025 | /*****************************************************************************/ |
5068 | /*****************************************************************************/ |
5026 | |
5069 | |
5027 | #if EV_WALK_ENABLE |
5070 | #if EV_WALK_ENABLE |
5028 | ecb_cold |
5071 | ecb_cold |
5029 | void |
5072 | void |
5030 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5073 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
5031 | { |
5074 | { |
5032 | int i, j; |
5075 | int i, j; |
5033 | ev_watcher_list *wl, *wn; |
5076 | ev_watcher_list *wl, *wn; |
5034 | |
5077 | |
5035 | if (types & (EV_IO | EV_EMBED)) |
5078 | if (types & (EV_IO | EV_EMBED)) |