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 |
… | |
… | |
363 | |
378 | |
364 | #ifndef EV_HEAP_CACHE_AT |
379 | #ifndef EV_HEAP_CACHE_AT |
365 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
380 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
366 | #endif |
381 | #endif |
367 | |
382 | |
368 | #ifdef ANDROID |
383 | #ifdef __ANDROID__ |
369 | /* supposedly, android doesn't typedef fd_mask */ |
384 | /* supposedly, android doesn't typedef fd_mask */ |
370 | # undef EV_USE_SELECT |
385 | # undef EV_USE_SELECT |
371 | # define EV_USE_SELECT 0 |
386 | # define EV_USE_SELECT 0 |
372 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
387 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
373 | # undef EV_USE_CLOCK_SYSCALL |
388 | # undef EV_USE_CLOCK_SYSCALL |
… | |
… | |
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; |
1907 | |
1936 | |
1908 | EV_TS_SET (ts, delay); |
1937 | EV_TS_SET (ts, delay); |
1909 | nanosleep (&ts, 0); |
1938 | nanosleep (&ts, 0); |
1910 | #elif defined _WIN32 |
1939 | #elif defined _WIN32 |
|
|
1940 | /* maybe this should round up, as ms is very low resolution */ |
|
|
1941 | /* compared to select (µs) or nanosleep (ns) */ |
1911 | Sleep ((unsigned long)(delay * 1e3)); |
1942 | Sleep ((unsigned long)(delay * 1e3)); |
1912 | #else |
1943 | #else |
1913 | struct timeval tv; |
1944 | struct timeval tv; |
1914 | |
1945 | |
1915 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1946 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1954 | { |
1985 | { |
1955 | *cur = array_nextsize (elem, *cur, cnt); |
1986 | *cur = array_nextsize (elem, *cur, cnt); |
1956 | return ev_realloc (base, elem * *cur); |
1987 | return ev_realloc (base, elem * *cur); |
1957 | } |
1988 | } |
1958 | |
1989 | |
|
|
1990 | #define array_needsize_noinit(base,count) |
|
|
1991 | |
1959 | #define array_init_zero(base,count) \ |
1992 | #define array_needsize_zerofill(base,count) \ |
1960 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1993 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1961 | |
1994 | |
1962 | #define array_needsize(type,base,cur,cnt,init) \ |
1995 | #define array_needsize(type,base,cur,cnt,init) \ |
1963 | if (expect_false ((cnt) > (cur))) \ |
1996 | if (expect_false ((cnt) > (cur))) \ |
1964 | { \ |
1997 | { \ |
… | |
… | |
1990 | { |
2023 | { |
1991 | } |
2024 | } |
1992 | |
2025 | |
1993 | noinline |
2026 | noinline |
1994 | void |
2027 | void |
1995 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2028 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1996 | { |
2029 | { |
1997 | W w_ = (W)w; |
2030 | W w_ = (W)w; |
1998 | int pri = ABSPRI (w_); |
2031 | int pri = ABSPRI (w_); |
1999 | |
2032 | |
2000 | if (expect_false (w_->pending)) |
2033 | if (expect_false (w_->pending)) |
2001 | pendings [pri][w_->pending - 1].events |= revents; |
2034 | pendings [pri][w_->pending - 1].events |= revents; |
2002 | else |
2035 | else |
2003 | { |
2036 | { |
2004 | w_->pending = ++pendingcnt [pri]; |
2037 | w_->pending = ++pendingcnt [pri]; |
2005 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2038 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2006 | pendings [pri][w_->pending - 1].w = w_; |
2039 | pendings [pri][w_->pending - 1].w = w_; |
2007 | pendings [pri][w_->pending - 1].events = revents; |
2040 | pendings [pri][w_->pending - 1].events = revents; |
2008 | } |
2041 | } |
2009 | |
2042 | |
2010 | pendingpri = NUMPRI - 1; |
2043 | pendingpri = NUMPRI - 1; |
2011 | } |
2044 | } |
2012 | |
2045 | |
2013 | inline_speed void |
2046 | inline_speed void |
2014 | feed_reverse (EV_P_ W w) |
2047 | feed_reverse (EV_P_ W w) |
2015 | { |
2048 | { |
2016 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2049 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2017 | rfeeds [rfeedcnt++] = w; |
2050 | rfeeds [rfeedcnt++] = w; |
2018 | } |
2051 | } |
2019 | |
2052 | |
2020 | inline_size void |
2053 | inline_size void |
2021 | feed_reverse_done (EV_P_ int revents) |
2054 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2061 | if (expect_true (!anfd->reify)) |
2094 | if (expect_true (!anfd->reify)) |
2062 | fd_event_nocheck (EV_A_ fd, revents); |
2095 | fd_event_nocheck (EV_A_ fd, revents); |
2063 | } |
2096 | } |
2064 | |
2097 | |
2065 | void |
2098 | void |
2066 | 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 |
2067 | { |
2100 | { |
2068 | if (fd >= 0 && fd < anfdmax) |
2101 | if (fd >= 0 && fd < anfdmax) |
2069 | fd_event_nocheck (EV_A_ fd, revents); |
2102 | fd_event_nocheck (EV_A_ fd, revents); |
2070 | } |
2103 | } |
2071 | |
2104 | |
… | |
… | |
2139 | anfds [fd].reify |= flags; |
2172 | anfds [fd].reify |= flags; |
2140 | |
2173 | |
2141 | if (expect_true (!reify)) |
2174 | if (expect_true (!reify)) |
2142 | { |
2175 | { |
2143 | ++fdchangecnt; |
2176 | ++fdchangecnt; |
2144 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2177 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2145 | fdchanges [fdchangecnt - 1] = fd; |
2178 | fdchanges [fdchangecnt - 1] = fd; |
2146 | } |
2179 | } |
2147 | } |
2180 | } |
2148 | |
2181 | |
2149 | /* 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 */ |
… | |
… | |
2471 | #endif |
2504 | #endif |
2472 | { |
2505 | { |
2473 | #ifdef _WIN32 |
2506 | #ifdef _WIN32 |
2474 | WSABUF buf; |
2507 | WSABUF buf; |
2475 | DWORD sent; |
2508 | DWORD sent; |
2476 | buf.buf = &buf; |
2509 | buf.buf = (char *)&buf; |
2477 | buf.len = 1; |
2510 | buf.len = 1; |
2478 | 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); |
2479 | #else |
2512 | #else |
2480 | write (evpipe [1], &(evpipe [1]), 1); |
2513 | write (evpipe [1], &(evpipe [1]), 1); |
2481 | #endif |
2514 | #endif |
… | |
… | |
2553 | } |
2586 | } |
2554 | |
2587 | |
2555 | /*****************************************************************************/ |
2588 | /*****************************************************************************/ |
2556 | |
2589 | |
2557 | void |
2590 | void |
2558 | ev_feed_signal (int signum) EV_THROW |
2591 | ev_feed_signal (int signum) EV_NOEXCEPT |
2559 | { |
2592 | { |
2560 | #if EV_MULTIPLICITY |
2593 | #if EV_MULTIPLICITY |
2561 | EV_P; |
2594 | EV_P; |
2562 | ECB_MEMORY_FENCE_ACQUIRE; |
2595 | ECB_MEMORY_FENCE_ACQUIRE; |
2563 | EV_A = signals [signum - 1].loop; |
2596 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2580 | ev_feed_signal (signum); |
2613 | ev_feed_signal (signum); |
2581 | } |
2614 | } |
2582 | |
2615 | |
2583 | noinline |
2616 | noinline |
2584 | void |
2617 | void |
2585 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2618 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2586 | { |
2619 | { |
2587 | WL w; |
2620 | WL w; |
2588 | |
2621 | |
2589 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2622 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2590 | return; |
2623 | return; |
… | |
… | |
2696 | # include "ev_port.c" |
2729 | # include "ev_port.c" |
2697 | #endif |
2730 | #endif |
2698 | #if EV_USE_KQUEUE |
2731 | #if EV_USE_KQUEUE |
2699 | # include "ev_kqueue.c" |
2732 | # include "ev_kqueue.c" |
2700 | #endif |
2733 | #endif |
|
|
2734 | #if EV_USE_LINUXAIO |
|
|
2735 | # include "ev_linuxaio.c" |
|
|
2736 | #endif |
2701 | #if EV_USE_EPOLL |
2737 | #if EV_USE_EPOLL |
2702 | # include "ev_epoll.c" |
2738 | # include "ev_epoll.c" |
2703 | #endif |
2739 | #endif |
2704 | #if EV_USE_POLL |
2740 | #if EV_USE_POLL |
2705 | # include "ev_poll.c" |
2741 | # include "ev_poll.c" |
… | |
… | |
2707 | #if EV_USE_SELECT |
2743 | #if EV_USE_SELECT |
2708 | # include "ev_select.c" |
2744 | # include "ev_select.c" |
2709 | #endif |
2745 | #endif |
2710 | |
2746 | |
2711 | ecb_cold int |
2747 | ecb_cold int |
2712 | ev_version_major (void) EV_THROW |
2748 | ev_version_major (void) EV_NOEXCEPT |
2713 | { |
2749 | { |
2714 | return EV_VERSION_MAJOR; |
2750 | return EV_VERSION_MAJOR; |
2715 | } |
2751 | } |
2716 | |
2752 | |
2717 | ecb_cold int |
2753 | ecb_cold int |
2718 | ev_version_minor (void) EV_THROW |
2754 | ev_version_minor (void) EV_NOEXCEPT |
2719 | { |
2755 | { |
2720 | return EV_VERSION_MINOR; |
2756 | return EV_VERSION_MINOR; |
2721 | } |
2757 | } |
2722 | |
2758 | |
2723 | /* 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 */ |
… | |
… | |
2732 | #endif |
2768 | #endif |
2733 | } |
2769 | } |
2734 | |
2770 | |
2735 | ecb_cold |
2771 | ecb_cold |
2736 | unsigned int |
2772 | unsigned int |
2737 | ev_supported_backends (void) EV_THROW |
2773 | ev_supported_backends (void) EV_NOEXCEPT |
2738 | { |
2774 | { |
2739 | unsigned int flags = 0; |
2775 | unsigned int flags = 0; |
2740 | |
2776 | |
2741 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2777 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2742 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2778 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2743 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2779 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2780 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2744 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2781 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2745 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2782 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2746 | |
2783 | |
2747 | return flags; |
2784 | return flags; |
2748 | } |
2785 | } |
2749 | |
2786 | |
2750 | ecb_cold |
2787 | ecb_cold |
2751 | unsigned int |
2788 | unsigned int |
2752 | ev_recommended_backends (void) EV_THROW |
2789 | ev_recommended_backends (void) EV_NOEXCEPT |
2753 | { |
2790 | { |
2754 | unsigned int flags = ev_supported_backends (); |
2791 | unsigned int flags = ev_supported_backends (); |
2755 | |
2792 | |
2756 | #ifndef __NetBSD__ |
2793 | #ifndef __NetBSD__ |
2757 | /* kqueue is borked on everything but netbsd apparently */ |
2794 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2765 | #endif |
2802 | #endif |
2766 | #ifdef __FreeBSD__ |
2803 | #ifdef __FreeBSD__ |
2767 | 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) */ |
2768 | #endif |
2805 | #endif |
2769 | |
2806 | |
|
|
2807 | /* TODO: linuxaio is very experimental */ |
|
|
2808 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2809 | |
2770 | return flags; |
2810 | return flags; |
2771 | } |
2811 | } |
2772 | |
2812 | |
2773 | ecb_cold |
2813 | ecb_cold |
2774 | unsigned int |
2814 | unsigned int |
2775 | ev_embeddable_backends (void) EV_THROW |
2815 | ev_embeddable_backends (void) EV_NOEXCEPT |
2776 | { |
2816 | { |
2777 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2817 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2778 | |
2818 | |
2779 | /* 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 */ |
2780 | 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 */ |
… | |
… | |
2782 | |
2822 | |
2783 | return flags; |
2823 | return flags; |
2784 | } |
2824 | } |
2785 | |
2825 | |
2786 | unsigned int |
2826 | unsigned int |
2787 | ev_backend (EV_P) EV_THROW |
2827 | ev_backend (EV_P) EV_NOEXCEPT |
2788 | { |
2828 | { |
2789 | return backend; |
2829 | return backend; |
2790 | } |
2830 | } |
2791 | |
2831 | |
2792 | #if EV_FEATURE_API |
2832 | #if EV_FEATURE_API |
2793 | unsigned int |
2833 | unsigned int |
2794 | ev_iteration (EV_P) EV_THROW |
2834 | ev_iteration (EV_P) EV_NOEXCEPT |
2795 | { |
2835 | { |
2796 | return loop_count; |
2836 | return loop_count; |
2797 | } |
2837 | } |
2798 | |
2838 | |
2799 | unsigned int |
2839 | unsigned int |
2800 | ev_depth (EV_P) EV_THROW |
2840 | ev_depth (EV_P) EV_NOEXCEPT |
2801 | { |
2841 | { |
2802 | return loop_depth; |
2842 | return loop_depth; |
2803 | } |
2843 | } |
2804 | |
2844 | |
2805 | void |
2845 | void |
2806 | 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 |
2807 | { |
2847 | { |
2808 | io_blocktime = interval; |
2848 | io_blocktime = interval; |
2809 | } |
2849 | } |
2810 | |
2850 | |
2811 | void |
2851 | void |
2812 | 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 |
2813 | { |
2853 | { |
2814 | timeout_blocktime = interval; |
2854 | timeout_blocktime = interval; |
2815 | } |
2855 | } |
2816 | |
2856 | |
2817 | void |
2857 | void |
2818 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2858 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2819 | { |
2859 | { |
2820 | userdata = data; |
2860 | userdata = data; |
2821 | } |
2861 | } |
2822 | |
2862 | |
2823 | void * |
2863 | void * |
2824 | ev_userdata (EV_P) EV_THROW |
2864 | ev_userdata (EV_P) EV_NOEXCEPT |
2825 | { |
2865 | { |
2826 | return userdata; |
2866 | return userdata; |
2827 | } |
2867 | } |
2828 | |
2868 | |
2829 | void |
2869 | void |
2830 | 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 |
2831 | { |
2871 | { |
2832 | invoke_cb = invoke_pending_cb; |
2872 | invoke_cb = invoke_pending_cb; |
2833 | } |
2873 | } |
2834 | |
2874 | |
2835 | void |
2875 | void |
2836 | 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 |
2837 | { |
2877 | { |
2838 | release_cb = release; |
2878 | release_cb = release; |
2839 | acquire_cb = acquire; |
2879 | acquire_cb = acquire; |
2840 | } |
2880 | } |
2841 | #endif |
2881 | #endif |
2842 | |
2882 | |
2843 | /* initialise a loop structure, must be zero-initialised */ |
2883 | /* initialise a loop structure, must be zero-initialised */ |
2844 | noinline ecb_cold |
2884 | noinline ecb_cold |
2845 | static void |
2885 | static void |
2846 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2886 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2847 | { |
2887 | { |
2848 | if (!backend) |
2888 | if (!backend) |
2849 | { |
2889 | { |
2850 | origflags = flags; |
2890 | origflags = flags; |
2851 | |
2891 | |
… | |
… | |
2909 | |
2949 | |
2910 | if (!(flags & EVBACKEND_MASK)) |
2950 | if (!(flags & EVBACKEND_MASK)) |
2911 | flags |= ev_recommended_backends (); |
2951 | flags |= ev_recommended_backends (); |
2912 | |
2952 | |
2913 | #if EV_USE_IOCP |
2953 | #if EV_USE_IOCP |
2914 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2954 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2915 | #endif |
2955 | #endif |
2916 | #if EV_USE_PORT |
2956 | #if EV_USE_PORT |
2917 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2957 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2918 | #endif |
2958 | #endif |
2919 | #if EV_USE_KQUEUE |
2959 | #if EV_USE_KQUEUE |
2920 | 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); |
2921 | #endif |
2964 | #endif |
2922 | #if EV_USE_EPOLL |
2965 | #if EV_USE_EPOLL |
2923 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2966 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2924 | #endif |
2967 | #endif |
2925 | #if EV_USE_POLL |
2968 | #if EV_USE_POLL |
2926 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2969 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2927 | #endif |
2970 | #endif |
2928 | #if EV_USE_SELECT |
2971 | #if EV_USE_SELECT |
2929 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2972 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2930 | #endif |
2973 | #endif |
2931 | |
2974 | |
2932 | ev_prepare_init (&pending_w, pendingcb); |
2975 | ev_prepare_init (&pending_w, pendingcb); |
2933 | |
2976 | |
2934 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2977 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2989 | |
3032 | |
2990 | if (backend_fd >= 0) |
3033 | if (backend_fd >= 0) |
2991 | close (backend_fd); |
3034 | close (backend_fd); |
2992 | |
3035 | |
2993 | #if EV_USE_IOCP |
3036 | #if EV_USE_IOCP |
2994 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3037 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2995 | #endif |
3038 | #endif |
2996 | #if EV_USE_PORT |
3039 | #if EV_USE_PORT |
2997 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3040 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
2998 | #endif |
3041 | #endif |
2999 | #if EV_USE_KQUEUE |
3042 | #if EV_USE_KQUEUE |
3000 | 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); |
3001 | #endif |
3047 | #endif |
3002 | #if EV_USE_EPOLL |
3048 | #if EV_USE_EPOLL |
3003 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3049 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3004 | #endif |
3050 | #endif |
3005 | #if EV_USE_POLL |
3051 | #if EV_USE_POLL |
3006 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3052 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3007 | #endif |
3053 | #endif |
3008 | #if EV_USE_SELECT |
3054 | #if EV_USE_SELECT |
3009 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3055 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3010 | #endif |
3056 | #endif |
3011 | |
3057 | |
3012 | for (i = NUMPRI; i--; ) |
3058 | for (i = NUMPRI; i--; ) |
3013 | { |
3059 | { |
3014 | array_free (pending, [i]); |
3060 | array_free (pending, [i]); |
… | |
… | |
3056 | |
3102 | |
3057 | inline_size void |
3103 | inline_size void |
3058 | loop_fork (EV_P) |
3104 | loop_fork (EV_P) |
3059 | { |
3105 | { |
3060 | #if EV_USE_PORT |
3106 | #if EV_USE_PORT |
3061 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3107 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3062 | #endif |
3108 | #endif |
3063 | #if EV_USE_KQUEUE |
3109 | #if EV_USE_KQUEUE |
3064 | 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); |
3065 | #endif |
3114 | #endif |
3066 | #if EV_USE_EPOLL |
3115 | #if EV_USE_EPOLL |
3067 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3116 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3068 | #endif |
3117 | #endif |
3069 | #if EV_USE_INOTIFY |
3118 | #if EV_USE_INOTIFY |
3070 | infy_fork (EV_A); |
3119 | infy_fork (EV_A); |
3071 | #endif |
3120 | #endif |
3072 | |
3121 | |
… | |
… | |
3092 | |
3141 | |
3093 | #if EV_MULTIPLICITY |
3142 | #if EV_MULTIPLICITY |
3094 | |
3143 | |
3095 | ecb_cold |
3144 | ecb_cold |
3096 | struct ev_loop * |
3145 | struct ev_loop * |
3097 | ev_loop_new (unsigned int flags) EV_THROW |
3146 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3098 | { |
3147 | { |
3099 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3148 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3100 | |
3149 | |
3101 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3150 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3102 | loop_init (EV_A_ flags); |
3151 | loop_init (EV_A_ flags); |
… | |
… | |
3149 | } |
3198 | } |
3150 | #endif |
3199 | #endif |
3151 | |
3200 | |
3152 | #if EV_FEATURE_API |
3201 | #if EV_FEATURE_API |
3153 | void ecb_cold |
3202 | void ecb_cold |
3154 | ev_verify (EV_P) EV_THROW |
3203 | ev_verify (EV_P) EV_NOEXCEPT |
3155 | { |
3204 | { |
3156 | #if EV_VERIFY |
3205 | #if EV_VERIFY |
3157 | int i; |
3206 | int i; |
3158 | WL w, w2; |
3207 | WL w, w2; |
3159 | |
3208 | |
… | |
… | |
3240 | ecb_cold |
3289 | ecb_cold |
3241 | struct ev_loop * |
3290 | struct ev_loop * |
3242 | #else |
3291 | #else |
3243 | int |
3292 | int |
3244 | #endif |
3293 | #endif |
3245 | ev_default_loop (unsigned int flags) EV_THROW |
3294 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3246 | { |
3295 | { |
3247 | if (!ev_default_loop_ptr) |
3296 | if (!ev_default_loop_ptr) |
3248 | { |
3297 | { |
3249 | #if EV_MULTIPLICITY |
3298 | #if EV_MULTIPLICITY |
3250 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3299 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3269 | |
3318 | |
3270 | return ev_default_loop_ptr; |
3319 | return ev_default_loop_ptr; |
3271 | } |
3320 | } |
3272 | |
3321 | |
3273 | void |
3322 | void |
3274 | ev_loop_fork (EV_P) EV_THROW |
3323 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3275 | { |
3324 | { |
3276 | postfork = 1; |
3325 | postfork = 1; |
3277 | } |
3326 | } |
3278 | |
3327 | |
3279 | /*****************************************************************************/ |
3328 | /*****************************************************************************/ |
… | |
… | |
3283 | { |
3332 | { |
3284 | EV_CB_INVOKE ((W)w, revents); |
3333 | EV_CB_INVOKE ((W)w, revents); |
3285 | } |
3334 | } |
3286 | |
3335 | |
3287 | unsigned int |
3336 | unsigned int |
3288 | ev_pending_count (EV_P) EV_THROW |
3337 | ev_pending_count (EV_P) EV_NOEXCEPT |
3289 | { |
3338 | { |
3290 | int pri; |
3339 | int pri; |
3291 | unsigned int count = 0; |
3340 | unsigned int count = 0; |
3292 | |
3341 | |
3293 | for (pri = NUMPRI; pri--; ) |
3342 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3300 | void |
3349 | void |
3301 | ev_invoke_pending (EV_P) |
3350 | ev_invoke_pending (EV_P) |
3302 | { |
3351 | { |
3303 | pendingpri = NUMPRI; |
3352 | pendingpri = NUMPRI; |
3304 | |
3353 | |
3305 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3354 | do |
3306 | { |
3355 | { |
3307 | --pendingpri; |
3356 | --pendingpri; |
3308 | |
3357 | |
|
|
3358 | /* pendingpri possibly gets modified in the inner loop */ |
3309 | while (pendingcnt [pendingpri]) |
3359 | while (pendingcnt [pendingpri]) |
3310 | { |
3360 | { |
3311 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3361 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3312 | |
3362 | |
3313 | p->w->pending = 0; |
3363 | p->w->pending = 0; |
3314 | EV_CB_INVOKE (p->w, p->events); |
3364 | EV_CB_INVOKE (p->w, p->events); |
3315 | EV_FREQUENT_CHECK; |
3365 | EV_FREQUENT_CHECK; |
3316 | } |
3366 | } |
3317 | } |
3367 | } |
|
|
3368 | while (pendingpri); |
3318 | } |
3369 | } |
3319 | |
3370 | |
3320 | #if EV_IDLE_ENABLE |
3371 | #if EV_IDLE_ENABLE |
3321 | /* make idle watchers pending. this handles the "call-idle */ |
3372 | /* make idle watchers pending. this handles the "call-idle */ |
3322 | /* only when higher priorities are idle" logic */ |
3373 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3731 | |
3782 | |
3732 | return activecnt; |
3783 | return activecnt; |
3733 | } |
3784 | } |
3734 | |
3785 | |
3735 | void |
3786 | void |
3736 | ev_break (EV_P_ int how) EV_THROW |
3787 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3737 | { |
3788 | { |
3738 | loop_done = how; |
3789 | loop_done = how; |
3739 | } |
3790 | } |
3740 | |
3791 | |
3741 | void |
3792 | void |
3742 | ev_ref (EV_P) EV_THROW |
3793 | ev_ref (EV_P) EV_NOEXCEPT |
3743 | { |
3794 | { |
3744 | ++activecnt; |
3795 | ++activecnt; |
3745 | } |
3796 | } |
3746 | |
3797 | |
3747 | void |
3798 | void |
3748 | ev_unref (EV_P) EV_THROW |
3799 | ev_unref (EV_P) EV_NOEXCEPT |
3749 | { |
3800 | { |
3750 | --activecnt; |
3801 | --activecnt; |
3751 | } |
3802 | } |
3752 | |
3803 | |
3753 | void |
3804 | void |
3754 | ev_now_update (EV_P) EV_THROW |
3805 | ev_now_update (EV_P) EV_NOEXCEPT |
3755 | { |
3806 | { |
3756 | time_update (EV_A_ 1e100); |
3807 | time_update (EV_A_ 1e100); |
3757 | } |
3808 | } |
3758 | |
3809 | |
3759 | void |
3810 | void |
3760 | ev_suspend (EV_P) EV_THROW |
3811 | ev_suspend (EV_P) EV_NOEXCEPT |
3761 | { |
3812 | { |
3762 | ev_now_update (EV_A); |
3813 | ev_now_update (EV_A); |
3763 | } |
3814 | } |
3764 | |
3815 | |
3765 | void |
3816 | void |
3766 | ev_resume (EV_P) EV_THROW |
3817 | ev_resume (EV_P) EV_NOEXCEPT |
3767 | { |
3818 | { |
3768 | ev_tstamp mn_prev = mn_now; |
3819 | ev_tstamp mn_prev = mn_now; |
3769 | |
3820 | |
3770 | ev_now_update (EV_A); |
3821 | ev_now_update (EV_A); |
3771 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3822 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3810 | w->pending = 0; |
3861 | w->pending = 0; |
3811 | } |
3862 | } |
3812 | } |
3863 | } |
3813 | |
3864 | |
3814 | int |
3865 | int |
3815 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3866 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3816 | { |
3867 | { |
3817 | W w_ = (W)w; |
3868 | W w_ = (W)w; |
3818 | int pending = w_->pending; |
3869 | int pending = w_->pending; |
3819 | |
3870 | |
3820 | if (expect_true (pending)) |
3871 | if (expect_true (pending)) |
… | |
… | |
3854 | |
3905 | |
3855 | /*****************************************************************************/ |
3906 | /*****************************************************************************/ |
3856 | |
3907 | |
3857 | noinline |
3908 | noinline |
3858 | void |
3909 | void |
3859 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3910 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3860 | { |
3911 | { |
3861 | int fd = w->fd; |
3912 | int fd = w->fd; |
3862 | |
3913 | |
3863 | if (expect_false (ev_is_active (w))) |
3914 | if (expect_false (ev_is_active (w))) |
3864 | return; |
3915 | return; |
… | |
… | |
3867 | 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)))); |
3868 | |
3919 | |
3869 | EV_FREQUENT_CHECK; |
3920 | EV_FREQUENT_CHECK; |
3870 | |
3921 | |
3871 | ev_start (EV_A_ (W)w, 1); |
3922 | ev_start (EV_A_ (W)w, 1); |
3872 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3923 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3873 | wlist_add (&anfds[fd].head, (WL)w); |
3924 | wlist_add (&anfds[fd].head, (WL)w); |
3874 | |
3925 | |
3875 | /* common bug, apparently */ |
3926 | /* common bug, apparently */ |
3876 | 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)); |
3877 | |
3928 | |
… | |
… | |
3881 | EV_FREQUENT_CHECK; |
3932 | EV_FREQUENT_CHECK; |
3882 | } |
3933 | } |
3883 | |
3934 | |
3884 | noinline |
3935 | noinline |
3885 | void |
3936 | void |
3886 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3937 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3887 | { |
3938 | { |
3888 | clear_pending (EV_A_ (W)w); |
3939 | clear_pending (EV_A_ (W)w); |
3889 | if (expect_false (!ev_is_active (w))) |
3940 | if (expect_false (!ev_is_active (w))) |
3890 | return; |
3941 | return; |
3891 | |
3942 | |
… | |
… | |
3901 | EV_FREQUENT_CHECK; |
3952 | EV_FREQUENT_CHECK; |
3902 | } |
3953 | } |
3903 | |
3954 | |
3904 | noinline |
3955 | noinline |
3905 | void |
3956 | void |
3906 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3957 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3907 | { |
3958 | { |
3908 | if (expect_false (ev_is_active (w))) |
3959 | if (expect_false (ev_is_active (w))) |
3909 | return; |
3960 | return; |
3910 | |
3961 | |
3911 | ev_at (w) += mn_now; |
3962 | ev_at (w) += mn_now; |
… | |
… | |
3914 | |
3965 | |
3915 | EV_FREQUENT_CHECK; |
3966 | EV_FREQUENT_CHECK; |
3916 | |
3967 | |
3917 | ++timercnt; |
3968 | ++timercnt; |
3918 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3969 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3919 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3970 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3920 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3971 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3921 | ANHE_at_cache (timers [ev_active (w)]); |
3972 | ANHE_at_cache (timers [ev_active (w)]); |
3922 | upheap (timers, ev_active (w)); |
3973 | upheap (timers, ev_active (w)); |
3923 | |
3974 | |
3924 | EV_FREQUENT_CHECK; |
3975 | EV_FREQUENT_CHECK; |
… | |
… | |
3926 | /*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));*/ |
3927 | } |
3978 | } |
3928 | |
3979 | |
3929 | noinline |
3980 | noinline |
3930 | void |
3981 | void |
3931 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3982 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3932 | { |
3983 | { |
3933 | clear_pending (EV_A_ (W)w); |
3984 | clear_pending (EV_A_ (W)w); |
3934 | if (expect_false (!ev_is_active (w))) |
3985 | if (expect_false (!ev_is_active (w))) |
3935 | return; |
3986 | return; |
3936 | |
3987 | |
… | |
… | |
3957 | EV_FREQUENT_CHECK; |
4008 | EV_FREQUENT_CHECK; |
3958 | } |
4009 | } |
3959 | |
4010 | |
3960 | noinline |
4011 | noinline |
3961 | void |
4012 | void |
3962 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4013 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3963 | { |
4014 | { |
3964 | EV_FREQUENT_CHECK; |
4015 | EV_FREQUENT_CHECK; |
3965 | |
4016 | |
3966 | clear_pending (EV_A_ (W)w); |
4017 | clear_pending (EV_A_ (W)w); |
3967 | |
4018 | |
… | |
… | |
3984 | |
4035 | |
3985 | EV_FREQUENT_CHECK; |
4036 | EV_FREQUENT_CHECK; |
3986 | } |
4037 | } |
3987 | |
4038 | |
3988 | ev_tstamp |
4039 | ev_tstamp |
3989 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4040 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3990 | { |
4041 | { |
3991 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4042 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3992 | } |
4043 | } |
3993 | |
4044 | |
3994 | #if EV_PERIODIC_ENABLE |
4045 | #if EV_PERIODIC_ENABLE |
3995 | noinline |
4046 | noinline |
3996 | void |
4047 | void |
3997 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4048 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3998 | { |
4049 | { |
3999 | if (expect_false (ev_is_active (w))) |
4050 | if (expect_false (ev_is_active (w))) |
4000 | return; |
4051 | return; |
4001 | |
4052 | |
4002 | if (w->reschedule_cb) |
4053 | if (w->reschedule_cb) |
… | |
… | |
4011 | |
4062 | |
4012 | EV_FREQUENT_CHECK; |
4063 | EV_FREQUENT_CHECK; |
4013 | |
4064 | |
4014 | ++periodiccnt; |
4065 | ++periodiccnt; |
4015 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4066 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4016 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4067 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4017 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4068 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4018 | ANHE_at_cache (periodics [ev_active (w)]); |
4069 | ANHE_at_cache (periodics [ev_active (w)]); |
4019 | upheap (periodics, ev_active (w)); |
4070 | upheap (periodics, ev_active (w)); |
4020 | |
4071 | |
4021 | EV_FREQUENT_CHECK; |
4072 | EV_FREQUENT_CHECK; |
… | |
… | |
4023 | /*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));*/ |
4024 | } |
4075 | } |
4025 | |
4076 | |
4026 | noinline |
4077 | noinline |
4027 | void |
4078 | void |
4028 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4079 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4029 | { |
4080 | { |
4030 | clear_pending (EV_A_ (W)w); |
4081 | clear_pending (EV_A_ (W)w); |
4031 | if (expect_false (!ev_is_active (w))) |
4082 | if (expect_false (!ev_is_active (w))) |
4032 | return; |
4083 | return; |
4033 | |
4084 | |
… | |
… | |
4052 | EV_FREQUENT_CHECK; |
4103 | EV_FREQUENT_CHECK; |
4053 | } |
4104 | } |
4054 | |
4105 | |
4055 | noinline |
4106 | noinline |
4056 | void |
4107 | void |
4057 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4108 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4058 | { |
4109 | { |
4059 | /* TODO: use adjustheap and recalculation */ |
4110 | /* TODO: use adjustheap and recalculation */ |
4060 | ev_periodic_stop (EV_A_ w); |
4111 | ev_periodic_stop (EV_A_ w); |
4061 | ev_periodic_start (EV_A_ w); |
4112 | ev_periodic_start (EV_A_ w); |
4062 | } |
4113 | } |
… | |
… | |
4068 | |
4119 | |
4069 | #if EV_SIGNAL_ENABLE |
4120 | #if EV_SIGNAL_ENABLE |
4070 | |
4121 | |
4071 | noinline |
4122 | noinline |
4072 | void |
4123 | void |
4073 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4124 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4074 | { |
4125 | { |
4075 | if (expect_false (ev_is_active (w))) |
4126 | if (expect_false (ev_is_active (w))) |
4076 | return; |
4127 | return; |
4077 | |
4128 | |
4078 | 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)); |
… | |
… | |
4151 | EV_FREQUENT_CHECK; |
4202 | EV_FREQUENT_CHECK; |
4152 | } |
4203 | } |
4153 | |
4204 | |
4154 | noinline |
4205 | noinline |
4155 | void |
4206 | void |
4156 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4207 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4157 | { |
4208 | { |
4158 | clear_pending (EV_A_ (W)w); |
4209 | clear_pending (EV_A_ (W)w); |
4159 | if (expect_false (!ev_is_active (w))) |
4210 | if (expect_false (!ev_is_active (w))) |
4160 | return; |
4211 | return; |
4161 | |
4212 | |
… | |
… | |
4192 | #endif |
4243 | #endif |
4193 | |
4244 | |
4194 | #if EV_CHILD_ENABLE |
4245 | #if EV_CHILD_ENABLE |
4195 | |
4246 | |
4196 | void |
4247 | void |
4197 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4248 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4198 | { |
4249 | { |
4199 | #if EV_MULTIPLICITY |
4250 | #if EV_MULTIPLICITY |
4200 | 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)); |
4201 | #endif |
4252 | #endif |
4202 | if (expect_false (ev_is_active (w))) |
4253 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4209 | |
4260 | |
4210 | EV_FREQUENT_CHECK; |
4261 | EV_FREQUENT_CHECK; |
4211 | } |
4262 | } |
4212 | |
4263 | |
4213 | void |
4264 | void |
4214 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4265 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4215 | { |
4266 | { |
4216 | clear_pending (EV_A_ (W)w); |
4267 | clear_pending (EV_A_ (W)w); |
4217 | if (expect_false (!ev_is_active (w))) |
4268 | if (expect_false (!ev_is_active (w))) |
4218 | return; |
4269 | return; |
4219 | |
4270 | |
… | |
… | |
4484 | #else |
4535 | #else |
4485 | # define EV_LSTAT(p,b) lstat (p, b) |
4536 | # define EV_LSTAT(p,b) lstat (p, b) |
4486 | #endif |
4537 | #endif |
4487 | |
4538 | |
4488 | void |
4539 | void |
4489 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4540 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4490 | { |
4541 | { |
4491 | if (lstat (w->path, &w->attr) < 0) |
4542 | if (lstat (w->path, &w->attr) < 0) |
4492 | w->attr.st_nlink = 0; |
4543 | w->attr.st_nlink = 0; |
4493 | else if (!w->attr.st_nlink) |
4544 | else if (!w->attr.st_nlink) |
4494 | w->attr.st_nlink = 1; |
4545 | w->attr.st_nlink = 1; |
… | |
… | |
4534 | ev_feed_event (EV_A_ w, EV_STAT); |
4585 | ev_feed_event (EV_A_ w, EV_STAT); |
4535 | } |
4586 | } |
4536 | } |
4587 | } |
4537 | |
4588 | |
4538 | void |
4589 | void |
4539 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4590 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4540 | { |
4591 | { |
4541 | if (expect_false (ev_is_active (w))) |
4592 | if (expect_false (ev_is_active (w))) |
4542 | return; |
4593 | return; |
4543 | |
4594 | |
4544 | ev_stat_stat (EV_A_ w); |
4595 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4565 | |
4616 | |
4566 | EV_FREQUENT_CHECK; |
4617 | EV_FREQUENT_CHECK; |
4567 | } |
4618 | } |
4568 | |
4619 | |
4569 | void |
4620 | void |
4570 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4621 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4571 | { |
4622 | { |
4572 | clear_pending (EV_A_ (W)w); |
4623 | clear_pending (EV_A_ (W)w); |
4573 | if (expect_false (!ev_is_active (w))) |
4624 | if (expect_false (!ev_is_active (w))) |
4574 | return; |
4625 | return; |
4575 | |
4626 | |
… | |
… | |
4591 | } |
4642 | } |
4592 | #endif |
4643 | #endif |
4593 | |
4644 | |
4594 | #if EV_IDLE_ENABLE |
4645 | #if EV_IDLE_ENABLE |
4595 | void |
4646 | void |
4596 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4647 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4597 | { |
4648 | { |
4598 | if (expect_false (ev_is_active (w))) |
4649 | if (expect_false (ev_is_active (w))) |
4599 | return; |
4650 | return; |
4600 | |
4651 | |
4601 | pri_adjust (EV_A_ (W)w); |
4652 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4606 | int active = ++idlecnt [ABSPRI (w)]; |
4657 | int active = ++idlecnt [ABSPRI (w)]; |
4607 | |
4658 | |
4608 | ++idleall; |
4659 | ++idleall; |
4609 | ev_start (EV_A_ (W)w, active); |
4660 | ev_start (EV_A_ (W)w, active); |
4610 | |
4661 | |
4611 | 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); |
4612 | idles [ABSPRI (w)][active - 1] = w; |
4663 | idles [ABSPRI (w)][active - 1] = w; |
4613 | } |
4664 | } |
4614 | |
4665 | |
4615 | EV_FREQUENT_CHECK; |
4666 | EV_FREQUENT_CHECK; |
4616 | } |
4667 | } |
4617 | |
4668 | |
4618 | void |
4669 | void |
4619 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4670 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4620 | { |
4671 | { |
4621 | clear_pending (EV_A_ (W)w); |
4672 | clear_pending (EV_A_ (W)w); |
4622 | if (expect_false (!ev_is_active (w))) |
4673 | if (expect_false (!ev_is_active (w))) |
4623 | return; |
4674 | return; |
4624 | |
4675 | |
… | |
… | |
4638 | } |
4689 | } |
4639 | #endif |
4690 | #endif |
4640 | |
4691 | |
4641 | #if EV_PREPARE_ENABLE |
4692 | #if EV_PREPARE_ENABLE |
4642 | void |
4693 | void |
4643 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4694 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4644 | { |
4695 | { |
4645 | if (expect_false (ev_is_active (w))) |
4696 | if (expect_false (ev_is_active (w))) |
4646 | return; |
4697 | return; |
4647 | |
4698 | |
4648 | EV_FREQUENT_CHECK; |
4699 | EV_FREQUENT_CHECK; |
4649 | |
4700 | |
4650 | ev_start (EV_A_ (W)w, ++preparecnt); |
4701 | ev_start (EV_A_ (W)w, ++preparecnt); |
4651 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4702 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4652 | prepares [preparecnt - 1] = w; |
4703 | prepares [preparecnt - 1] = w; |
4653 | |
4704 | |
4654 | EV_FREQUENT_CHECK; |
4705 | EV_FREQUENT_CHECK; |
4655 | } |
4706 | } |
4656 | |
4707 | |
4657 | void |
4708 | void |
4658 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4709 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4659 | { |
4710 | { |
4660 | clear_pending (EV_A_ (W)w); |
4711 | clear_pending (EV_A_ (W)w); |
4661 | if (expect_false (!ev_is_active (w))) |
4712 | if (expect_false (!ev_is_active (w))) |
4662 | return; |
4713 | return; |
4663 | |
4714 | |
… | |
… | |
4676 | } |
4727 | } |
4677 | #endif |
4728 | #endif |
4678 | |
4729 | |
4679 | #if EV_CHECK_ENABLE |
4730 | #if EV_CHECK_ENABLE |
4680 | void |
4731 | void |
4681 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4732 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4682 | { |
4733 | { |
4683 | if (expect_false (ev_is_active (w))) |
4734 | if (expect_false (ev_is_active (w))) |
4684 | return; |
4735 | return; |
4685 | |
4736 | |
4686 | EV_FREQUENT_CHECK; |
4737 | EV_FREQUENT_CHECK; |
4687 | |
4738 | |
4688 | ev_start (EV_A_ (W)w, ++checkcnt); |
4739 | ev_start (EV_A_ (W)w, ++checkcnt); |
4689 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4740 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4690 | checks [checkcnt - 1] = w; |
4741 | checks [checkcnt - 1] = w; |
4691 | |
4742 | |
4692 | EV_FREQUENT_CHECK; |
4743 | EV_FREQUENT_CHECK; |
4693 | } |
4744 | } |
4694 | |
4745 | |
4695 | void |
4746 | void |
4696 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4747 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4697 | { |
4748 | { |
4698 | clear_pending (EV_A_ (W)w); |
4749 | clear_pending (EV_A_ (W)w); |
4699 | if (expect_false (!ev_is_active (w))) |
4750 | if (expect_false (!ev_is_active (w))) |
4700 | return; |
4751 | return; |
4701 | |
4752 | |
… | |
… | |
4715 | #endif |
4766 | #endif |
4716 | |
4767 | |
4717 | #if EV_EMBED_ENABLE |
4768 | #if EV_EMBED_ENABLE |
4718 | noinline |
4769 | noinline |
4719 | void |
4770 | void |
4720 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4771 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4721 | { |
4772 | { |
4722 | ev_run (w->other, EVRUN_NOWAIT); |
4773 | ev_run (w->other, EVRUN_NOWAIT); |
4723 | } |
4774 | } |
4724 | |
4775 | |
4725 | static void |
4776 | static void |
… | |
… | |
4773 | ev_idle_stop (EV_A_ idle); |
4824 | ev_idle_stop (EV_A_ idle); |
4774 | } |
4825 | } |
4775 | #endif |
4826 | #endif |
4776 | |
4827 | |
4777 | void |
4828 | void |
4778 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4829 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4779 | { |
4830 | { |
4780 | if (expect_false (ev_is_active (w))) |
4831 | if (expect_false (ev_is_active (w))) |
4781 | return; |
4832 | return; |
4782 | |
4833 | |
4783 | { |
4834 | { |
… | |
… | |
4804 | |
4855 | |
4805 | EV_FREQUENT_CHECK; |
4856 | EV_FREQUENT_CHECK; |
4806 | } |
4857 | } |
4807 | |
4858 | |
4808 | void |
4859 | void |
4809 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4860 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4810 | { |
4861 | { |
4811 | clear_pending (EV_A_ (W)w); |
4862 | clear_pending (EV_A_ (W)w); |
4812 | if (expect_false (!ev_is_active (w))) |
4863 | if (expect_false (!ev_is_active (w))) |
4813 | return; |
4864 | return; |
4814 | |
4865 | |
… | |
… | |
4824 | } |
4875 | } |
4825 | #endif |
4876 | #endif |
4826 | |
4877 | |
4827 | #if EV_FORK_ENABLE |
4878 | #if EV_FORK_ENABLE |
4828 | void |
4879 | void |
4829 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4880 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4830 | { |
4881 | { |
4831 | if (expect_false (ev_is_active (w))) |
4882 | if (expect_false (ev_is_active (w))) |
4832 | return; |
4883 | return; |
4833 | |
4884 | |
4834 | EV_FREQUENT_CHECK; |
4885 | EV_FREQUENT_CHECK; |
4835 | |
4886 | |
4836 | ev_start (EV_A_ (W)w, ++forkcnt); |
4887 | ev_start (EV_A_ (W)w, ++forkcnt); |
4837 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4888 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4838 | forks [forkcnt - 1] = w; |
4889 | forks [forkcnt - 1] = w; |
4839 | |
4890 | |
4840 | EV_FREQUENT_CHECK; |
4891 | EV_FREQUENT_CHECK; |
4841 | } |
4892 | } |
4842 | |
4893 | |
4843 | void |
4894 | void |
4844 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4895 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4845 | { |
4896 | { |
4846 | clear_pending (EV_A_ (W)w); |
4897 | clear_pending (EV_A_ (W)w); |
4847 | if (expect_false (!ev_is_active (w))) |
4898 | if (expect_false (!ev_is_active (w))) |
4848 | return; |
4899 | return; |
4849 | |
4900 | |
… | |
… | |
4862 | } |
4913 | } |
4863 | #endif |
4914 | #endif |
4864 | |
4915 | |
4865 | #if EV_CLEANUP_ENABLE |
4916 | #if EV_CLEANUP_ENABLE |
4866 | void |
4917 | void |
4867 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4918 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4868 | { |
4919 | { |
4869 | if (expect_false (ev_is_active (w))) |
4920 | if (expect_false (ev_is_active (w))) |
4870 | return; |
4921 | return; |
4871 | |
4922 | |
4872 | EV_FREQUENT_CHECK; |
4923 | EV_FREQUENT_CHECK; |
4873 | |
4924 | |
4874 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4925 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4875 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4926 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4876 | cleanups [cleanupcnt - 1] = w; |
4927 | cleanups [cleanupcnt - 1] = w; |
4877 | |
4928 | |
4878 | /* cleanup watchers should never keep a refcount on the loop */ |
4929 | /* cleanup watchers should never keep a refcount on the loop */ |
4879 | ev_unref (EV_A); |
4930 | ev_unref (EV_A); |
4880 | EV_FREQUENT_CHECK; |
4931 | EV_FREQUENT_CHECK; |
4881 | } |
4932 | } |
4882 | |
4933 | |
4883 | void |
4934 | void |
4884 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4935 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4885 | { |
4936 | { |
4886 | clear_pending (EV_A_ (W)w); |
4937 | clear_pending (EV_A_ (W)w); |
4887 | if (expect_false (!ev_is_active (w))) |
4938 | if (expect_false (!ev_is_active (w))) |
4888 | return; |
4939 | return; |
4889 | |
4940 | |
… | |
… | |
4903 | } |
4954 | } |
4904 | #endif |
4955 | #endif |
4905 | |
4956 | |
4906 | #if EV_ASYNC_ENABLE |
4957 | #if EV_ASYNC_ENABLE |
4907 | void |
4958 | void |
4908 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4959 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4909 | { |
4960 | { |
4910 | if (expect_false (ev_is_active (w))) |
4961 | if (expect_false (ev_is_active (w))) |
4911 | return; |
4962 | return; |
4912 | |
4963 | |
4913 | w->sent = 0; |
4964 | w->sent = 0; |
… | |
… | |
4915 | evpipe_init (EV_A); |
4966 | evpipe_init (EV_A); |
4916 | |
4967 | |
4917 | EV_FREQUENT_CHECK; |
4968 | EV_FREQUENT_CHECK; |
4918 | |
4969 | |
4919 | ev_start (EV_A_ (W)w, ++asynccnt); |
4970 | ev_start (EV_A_ (W)w, ++asynccnt); |
4920 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4971 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4921 | asyncs [asynccnt - 1] = w; |
4972 | asyncs [asynccnt - 1] = w; |
4922 | |
4973 | |
4923 | EV_FREQUENT_CHECK; |
4974 | EV_FREQUENT_CHECK; |
4924 | } |
4975 | } |
4925 | |
4976 | |
4926 | void |
4977 | void |
4927 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4978 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4928 | { |
4979 | { |
4929 | clear_pending (EV_A_ (W)w); |
4980 | clear_pending (EV_A_ (W)w); |
4930 | if (expect_false (!ev_is_active (w))) |
4981 | if (expect_false (!ev_is_active (w))) |
4931 | return; |
4982 | return; |
4932 | |
4983 | |
… | |
… | |
4943 | |
4994 | |
4944 | EV_FREQUENT_CHECK; |
4995 | EV_FREQUENT_CHECK; |
4945 | } |
4996 | } |
4946 | |
4997 | |
4947 | void |
4998 | void |
4948 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4999 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4949 | { |
5000 | { |
4950 | w->sent = 1; |
5001 | w->sent = 1; |
4951 | evpipe_write (EV_A_ &async_pending); |
5002 | evpipe_write (EV_A_ &async_pending); |
4952 | } |
5003 | } |
4953 | #endif |
5004 | #endif |
… | |
… | |
4990 | |
5041 | |
4991 | 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)); |
4992 | } |
5043 | } |
4993 | |
5044 | |
4994 | void |
5045 | void |
4995 | 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 |
4996 | { |
5047 | { |
4997 | 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)); |
4998 | |
|
|
4999 | if (expect_false (!once)) |
|
|
5000 | { |
|
|
5001 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5002 | return; |
|
|
5003 | } |
|
|
5004 | |
5049 | |
5005 | once->cb = cb; |
5050 | once->cb = cb; |
5006 | once->arg = arg; |
5051 | once->arg = arg; |
5007 | |
5052 | |
5008 | ev_init (&once->io, once_cb_io); |
5053 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5023 | /*****************************************************************************/ |
5068 | /*****************************************************************************/ |
5024 | |
5069 | |
5025 | #if EV_WALK_ENABLE |
5070 | #if EV_WALK_ENABLE |
5026 | ecb_cold |
5071 | ecb_cold |
5027 | void |
5072 | void |
5028 | 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 |
5029 | { |
5074 | { |
5030 | int i, j; |
5075 | int i, j; |
5031 | ev_watcher_list *wl, *wn; |
5076 | ev_watcher_list *wl, *wn; |
5032 | |
5077 | |
5033 | if (types & (EV_IO | EV_EMBED)) |
5078 | if (types & (EV_IO | EV_EMBED)) |