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 |
… | |
… | |
315 | |
324 | |
316 | #ifndef EV_USE_PORT |
325 | #ifndef EV_USE_PORT |
317 | # define EV_USE_PORT 0 |
326 | # define EV_USE_PORT 0 |
318 | #endif |
327 | #endif |
319 | |
328 | |
|
|
329 | #ifndef EV_USE_LINUXAIO |
|
|
330 | # define EV_USE_LINUXAIO 0 |
|
|
331 | #endif |
|
|
332 | |
320 | #ifndef EV_USE_INOTIFY |
333 | #ifndef EV_USE_INOTIFY |
321 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
334 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
322 | # define EV_USE_INOTIFY EV_FEATURE_OS |
335 | # define EV_USE_INOTIFY EV_FEATURE_OS |
323 | # else |
336 | # else |
324 | # define EV_USE_INOTIFY 0 |
337 | # define EV_USE_INOTIFY 0 |
… | |
… | |
379 | /* aix's poll.h seems to cause lots of trouble */ |
392 | /* aix's poll.h seems to cause lots of trouble */ |
380 | #ifdef _AIX |
393 | #ifdef _AIX |
381 | /* AIX has a completely broken poll.h header */ |
394 | /* AIX has a completely broken poll.h header */ |
382 | # undef EV_USE_POLL |
395 | # undef EV_USE_POLL |
383 | # 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 */ |
384 | #endif |
401 | #endif |
385 | |
402 | |
386 | /* 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, */ |
387 | /* which makes programs even slower. might work on other unices, too. */ |
404 | /* which makes programs even slower. might work on other unices, too. */ |
388 | #if EV_USE_CLOCK_SYSCALL |
405 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
416 | |
433 | |
417 | #if !EV_USE_NANOSLEEP |
434 | #if !EV_USE_NANOSLEEP |
418 | /* 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 */ |
419 | # if !defined _WIN32 && !defined __hpux |
436 | # if !defined _WIN32 && !defined __hpux |
420 | # 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 |
421 | # endif |
446 | # endif |
422 | #endif |
447 | #endif |
423 | |
448 | |
424 | #if EV_USE_INOTIFY |
449 | #if EV_USE_INOTIFY |
425 | # include <sys/statfs.h> |
450 | # include <sys/statfs.h> |
… | |
… | |
609 | #define ECB_CLANG_EXTENSION(x) 0 |
634 | #define ECB_CLANG_EXTENSION(x) 0 |
610 | #endif |
635 | #endif |
611 | |
636 | |
612 | #define ECB_CPP (__cplusplus+0) |
637 | #define ECB_CPP (__cplusplus+0) |
613 | #define ECB_CPP11 (__cplusplus >= 201103L) |
638 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
639 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
640 | #define ECB_CPP17 (__cplusplus >= 201703L) |
614 | |
641 | |
615 | #if ECB_CPP |
642 | #if ECB_CPP |
616 | #define ECB_C 0 |
643 | #define ECB_C 0 |
617 | #define ECB_STDC_VERSION 0 |
644 | #define ECB_STDC_VERSION 0 |
618 | #else |
645 | #else |
… | |
… | |
620 | #define ECB_STDC_VERSION __STDC_VERSION__ |
647 | #define ECB_STDC_VERSION __STDC_VERSION__ |
621 | #endif |
648 | #endif |
622 | |
649 | |
623 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
650 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
624 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
651 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
652 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
625 | |
653 | |
626 | #if ECB_CPP |
654 | #if ECB_CPP |
627 | #define ECB_EXTERN_C extern "C" |
655 | #define ECB_EXTERN_C extern "C" |
628 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
656 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
629 | #define ECB_EXTERN_C_END } |
657 | #define ECB_EXTERN_C_END } |
… | |
… | |
658 | #ifndef ECB_MEMORY_FENCE |
686 | #ifndef ECB_MEMORY_FENCE |
659 | #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 |
660 | #if __i386 || __i386__ |
688 | #if __i386 || __i386__ |
661 | #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") |
662 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
690 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
663 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
691 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
664 | #elif ECB_GCC_AMD64 |
692 | #elif ECB_GCC_AMD64 |
665 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
693 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
666 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
694 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
667 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
695 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
668 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
696 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
669 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
697 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
670 | #elif defined __ARM_ARCH_2__ \ |
698 | #elif defined __ARM_ARCH_2__ \ |
671 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
699 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
672 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
700 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
1540 | # define ABSPRI(w) (((W)w), 0) |
1568 | # define ABSPRI(w) (((W)w), 0) |
1541 | #else |
1569 | #else |
1542 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1570 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1543 | #endif |
1571 | #endif |
1544 | |
1572 | |
1545 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1573 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1546 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1547 | |
1574 | |
1548 | typedef ev_watcher *W; |
1575 | typedef ev_watcher *W; |
1549 | typedef ev_watcher_list *WL; |
1576 | typedef ev_watcher_list *WL; |
1550 | typedef ev_watcher_time *WT; |
1577 | typedef ev_watcher_time *WT; |
1551 | |
1578 | |
… | |
… | |
1677 | { |
1704 | { |
1678 | write (STDERR_FILENO, msg, strlen (msg)); |
1705 | write (STDERR_FILENO, msg, strlen (msg)); |
1679 | } |
1706 | } |
1680 | #endif |
1707 | #endif |
1681 | |
1708 | |
1682 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1709 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1683 | |
1710 | |
1684 | ecb_cold |
1711 | ecb_cold |
1685 | void |
1712 | void |
1686 | 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 |
1687 | { |
1714 | { |
1688 | syserr_cb = cb; |
1715 | syserr_cb = cb; |
1689 | } |
1716 | } |
1690 | |
1717 | |
1691 | noinline ecb_cold |
1718 | noinline ecb_cold |
… | |
… | |
1710 | abort (); |
1737 | abort (); |
1711 | } |
1738 | } |
1712 | } |
1739 | } |
1713 | |
1740 | |
1714 | static void * |
1741 | static void * |
1715 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1742 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1716 | { |
1743 | { |
1717 | /* some systems, notably openbsd and darwin, fail to properly |
1744 | /* some systems, notably openbsd and darwin, fail to properly |
1718 | * 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 |
1719 | * the single unix specification, so work around them here. |
1746 | * the single unix specification, so work around them here. |
1720 | * recently, also (at least) fedora and debian started breaking it, |
1747 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1726 | |
1753 | |
1727 | free (ptr); |
1754 | free (ptr); |
1728 | return 0; |
1755 | return 0; |
1729 | } |
1756 | } |
1730 | |
1757 | |
1731 | 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; |
1732 | |
1759 | |
1733 | ecb_cold |
1760 | ecb_cold |
1734 | void |
1761 | void |
1735 | 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 |
1736 | { |
1763 | { |
1737 | alloc = cb; |
1764 | alloc = cb; |
1738 | } |
1765 | } |
1739 | |
1766 | |
1740 | inline_speed void * |
1767 | inline_speed void * |
… | |
… | |
1767 | typedef struct |
1794 | typedef struct |
1768 | { |
1795 | { |
1769 | WL head; |
1796 | WL head; |
1770 | unsigned char events; /* the events watched for */ |
1797 | unsigned char events; /* the events watched for */ |
1771 | 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) */ |
1772 | 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 */ |
1773 | unsigned char unused; |
1800 | unsigned char unused; |
1774 | #if EV_USE_EPOLL |
1801 | #if EV_USE_EPOLL |
1775 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1802 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1776 | #endif |
1803 | #endif |
1777 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1804 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1857 | |
1884 | |
1858 | /*****************************************************************************/ |
1885 | /*****************************************************************************/ |
1859 | |
1886 | |
1860 | #ifndef EV_HAVE_EV_TIME |
1887 | #ifndef EV_HAVE_EV_TIME |
1861 | ev_tstamp |
1888 | ev_tstamp |
1862 | ev_time (void) EV_THROW |
1889 | ev_time (void) EV_NOEXCEPT |
1863 | { |
1890 | { |
1864 | #if EV_USE_REALTIME |
1891 | #if EV_USE_REALTIME |
1865 | if (expect_true (have_realtime)) |
1892 | if (expect_true (have_realtime)) |
1866 | { |
1893 | { |
1867 | struct timespec ts; |
1894 | struct timespec ts; |
… | |
… | |
1891 | return ev_time (); |
1918 | return ev_time (); |
1892 | } |
1919 | } |
1893 | |
1920 | |
1894 | #if EV_MULTIPLICITY |
1921 | #if EV_MULTIPLICITY |
1895 | ev_tstamp |
1922 | ev_tstamp |
1896 | ev_now (EV_P) EV_THROW |
1923 | ev_now (EV_P) EV_NOEXCEPT |
1897 | { |
1924 | { |
1898 | return ev_rt_now; |
1925 | return ev_rt_now; |
1899 | } |
1926 | } |
1900 | #endif |
1927 | #endif |
1901 | |
1928 | |
1902 | void |
1929 | void |
1903 | ev_sleep (ev_tstamp delay) EV_THROW |
1930 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1904 | { |
1931 | { |
1905 | if (delay > 0.) |
1932 | if (delay > 0.) |
1906 | { |
1933 | { |
1907 | #if EV_USE_NANOSLEEP |
1934 | #if EV_USE_NANOSLEEP |
1908 | struct timespec ts; |
1935 | struct timespec ts; |
… | |
… | |
1958 | { |
1985 | { |
1959 | *cur = array_nextsize (elem, *cur, cnt); |
1986 | *cur = array_nextsize (elem, *cur, cnt); |
1960 | return ev_realloc (base, elem * *cur); |
1987 | return ev_realloc (base, elem * *cur); |
1961 | } |
1988 | } |
1962 | |
1989 | |
|
|
1990 | #define array_needsize_noinit(base,count) |
|
|
1991 | |
1963 | #define array_init_zero(base,count) \ |
1992 | #define array_needsize_zerofill(base,count) \ |
1964 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1993 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1965 | |
1994 | |
1966 | #define array_needsize(type,base,cur,cnt,init) \ |
1995 | #define array_needsize(type,base,cur,cnt,init) \ |
1967 | if (expect_false ((cnt) > (cur))) \ |
1996 | if (expect_false ((cnt) > (cur))) \ |
1968 | { \ |
1997 | { \ |
… | |
… | |
1994 | { |
2023 | { |
1995 | } |
2024 | } |
1996 | |
2025 | |
1997 | noinline |
2026 | noinline |
1998 | void |
2027 | void |
1999 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2028 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2000 | { |
2029 | { |
2001 | W w_ = (W)w; |
2030 | W w_ = (W)w; |
2002 | int pri = ABSPRI (w_); |
2031 | int pri = ABSPRI (w_); |
2003 | |
2032 | |
2004 | if (expect_false (w_->pending)) |
2033 | if (expect_false (w_->pending)) |
2005 | pendings [pri][w_->pending - 1].events |= revents; |
2034 | pendings [pri][w_->pending - 1].events |= revents; |
2006 | else |
2035 | else |
2007 | { |
2036 | { |
2008 | w_->pending = ++pendingcnt [pri]; |
2037 | w_->pending = ++pendingcnt [pri]; |
2009 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2038 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2010 | pendings [pri][w_->pending - 1].w = w_; |
2039 | pendings [pri][w_->pending - 1].w = w_; |
2011 | pendings [pri][w_->pending - 1].events = revents; |
2040 | pendings [pri][w_->pending - 1].events = revents; |
2012 | } |
2041 | } |
2013 | |
2042 | |
2014 | pendingpri = NUMPRI - 1; |
2043 | pendingpri = NUMPRI - 1; |
2015 | } |
2044 | } |
2016 | |
2045 | |
2017 | inline_speed void |
2046 | inline_speed void |
2018 | feed_reverse (EV_P_ W w) |
2047 | feed_reverse (EV_P_ W w) |
2019 | { |
2048 | { |
2020 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2049 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2021 | rfeeds [rfeedcnt++] = w; |
2050 | rfeeds [rfeedcnt++] = w; |
2022 | } |
2051 | } |
2023 | |
2052 | |
2024 | inline_size void |
2053 | inline_size void |
2025 | feed_reverse_done (EV_P_ int revents) |
2054 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2065 | if (expect_true (!anfd->reify)) |
2094 | if (expect_true (!anfd->reify)) |
2066 | fd_event_nocheck (EV_A_ fd, revents); |
2095 | fd_event_nocheck (EV_A_ fd, revents); |
2067 | } |
2096 | } |
2068 | |
2097 | |
2069 | void |
2098 | void |
2070 | 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 |
2071 | { |
2100 | { |
2072 | if (fd >= 0 && fd < anfdmax) |
2101 | if (fd >= 0 && fd < anfdmax) |
2073 | fd_event_nocheck (EV_A_ fd, revents); |
2102 | fd_event_nocheck (EV_A_ fd, revents); |
2074 | } |
2103 | } |
2075 | |
2104 | |
… | |
… | |
2143 | anfds [fd].reify |= flags; |
2172 | anfds [fd].reify |= flags; |
2144 | |
2173 | |
2145 | if (expect_true (!reify)) |
2174 | if (expect_true (!reify)) |
2146 | { |
2175 | { |
2147 | ++fdchangecnt; |
2176 | ++fdchangecnt; |
2148 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2177 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2149 | fdchanges [fdchangecnt - 1] = fd; |
2178 | fdchanges [fdchangecnt - 1] = fd; |
2150 | } |
2179 | } |
2151 | } |
2180 | } |
2152 | |
2181 | |
2153 | /* 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 */ |
… | |
… | |
2475 | #endif |
2504 | #endif |
2476 | { |
2505 | { |
2477 | #ifdef _WIN32 |
2506 | #ifdef _WIN32 |
2478 | WSABUF buf; |
2507 | WSABUF buf; |
2479 | DWORD sent; |
2508 | DWORD sent; |
2480 | buf.buf = &buf; |
2509 | buf.buf = (char *)&buf; |
2481 | buf.len = 1; |
2510 | buf.len = 1; |
2482 | 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); |
2483 | #else |
2512 | #else |
2484 | write (evpipe [1], &(evpipe [1]), 1); |
2513 | write (evpipe [1], &(evpipe [1]), 1); |
2485 | #endif |
2514 | #endif |
… | |
… | |
2557 | } |
2586 | } |
2558 | |
2587 | |
2559 | /*****************************************************************************/ |
2588 | /*****************************************************************************/ |
2560 | |
2589 | |
2561 | void |
2590 | void |
2562 | ev_feed_signal (int signum) EV_THROW |
2591 | ev_feed_signal (int signum) EV_NOEXCEPT |
2563 | { |
2592 | { |
2564 | #if EV_MULTIPLICITY |
2593 | #if EV_MULTIPLICITY |
2565 | EV_P; |
2594 | EV_P; |
2566 | ECB_MEMORY_FENCE_ACQUIRE; |
2595 | ECB_MEMORY_FENCE_ACQUIRE; |
2567 | EV_A = signals [signum - 1].loop; |
2596 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2584 | ev_feed_signal (signum); |
2613 | ev_feed_signal (signum); |
2585 | } |
2614 | } |
2586 | |
2615 | |
2587 | noinline |
2616 | noinline |
2588 | void |
2617 | void |
2589 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2618 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2590 | { |
2619 | { |
2591 | WL w; |
2620 | WL w; |
2592 | |
2621 | |
2593 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2622 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2594 | return; |
2623 | return; |
… | |
… | |
2700 | # include "ev_port.c" |
2729 | # include "ev_port.c" |
2701 | #endif |
2730 | #endif |
2702 | #if EV_USE_KQUEUE |
2731 | #if EV_USE_KQUEUE |
2703 | # include "ev_kqueue.c" |
2732 | # include "ev_kqueue.c" |
2704 | #endif |
2733 | #endif |
|
|
2734 | #if EV_USE_LINUXAIO |
|
|
2735 | # include "ev_linuxaio.c" |
|
|
2736 | #endif |
2705 | #if EV_USE_EPOLL |
2737 | #if EV_USE_EPOLL |
2706 | # include "ev_epoll.c" |
2738 | # include "ev_epoll.c" |
2707 | #endif |
2739 | #endif |
2708 | #if EV_USE_POLL |
2740 | #if EV_USE_POLL |
2709 | # include "ev_poll.c" |
2741 | # include "ev_poll.c" |
… | |
… | |
2711 | #if EV_USE_SELECT |
2743 | #if EV_USE_SELECT |
2712 | # include "ev_select.c" |
2744 | # include "ev_select.c" |
2713 | #endif |
2745 | #endif |
2714 | |
2746 | |
2715 | ecb_cold int |
2747 | ecb_cold int |
2716 | ev_version_major (void) EV_THROW |
2748 | ev_version_major (void) EV_NOEXCEPT |
2717 | { |
2749 | { |
2718 | return EV_VERSION_MAJOR; |
2750 | return EV_VERSION_MAJOR; |
2719 | } |
2751 | } |
2720 | |
2752 | |
2721 | ecb_cold int |
2753 | ecb_cold int |
2722 | ev_version_minor (void) EV_THROW |
2754 | ev_version_minor (void) EV_NOEXCEPT |
2723 | { |
2755 | { |
2724 | return EV_VERSION_MINOR; |
2756 | return EV_VERSION_MINOR; |
2725 | } |
2757 | } |
2726 | |
2758 | |
2727 | /* 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 */ |
… | |
… | |
2736 | #endif |
2768 | #endif |
2737 | } |
2769 | } |
2738 | |
2770 | |
2739 | ecb_cold |
2771 | ecb_cold |
2740 | unsigned int |
2772 | unsigned int |
2741 | ev_supported_backends (void) EV_THROW |
2773 | ev_supported_backends (void) EV_NOEXCEPT |
2742 | { |
2774 | { |
2743 | unsigned int flags = 0; |
2775 | unsigned int flags = 0; |
2744 | |
2776 | |
2745 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2777 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2746 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2778 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2747 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2779 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2780 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2748 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2781 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2749 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2782 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2750 | |
2783 | |
2751 | return flags; |
2784 | return flags; |
2752 | } |
2785 | } |
2753 | |
2786 | |
2754 | ecb_cold |
2787 | ecb_cold |
2755 | unsigned int |
2788 | unsigned int |
2756 | ev_recommended_backends (void) EV_THROW |
2789 | ev_recommended_backends (void) EV_NOEXCEPT |
2757 | { |
2790 | { |
2758 | unsigned int flags = ev_supported_backends (); |
2791 | unsigned int flags = ev_supported_backends (); |
2759 | |
2792 | |
2760 | #ifndef __NetBSD__ |
2793 | #ifndef __NetBSD__ |
2761 | /* kqueue is borked on everything but netbsd apparently */ |
2794 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2769 | #endif |
2802 | #endif |
2770 | #ifdef __FreeBSD__ |
2803 | #ifdef __FreeBSD__ |
2771 | 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) */ |
2772 | #endif |
2805 | #endif |
2773 | |
2806 | |
|
|
2807 | /* TODO: linuxaio is very experimental */ |
|
|
2808 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2809 | |
2774 | return flags; |
2810 | return flags; |
2775 | } |
2811 | } |
2776 | |
2812 | |
2777 | ecb_cold |
2813 | ecb_cold |
2778 | unsigned int |
2814 | unsigned int |
2779 | ev_embeddable_backends (void) EV_THROW |
2815 | ev_embeddable_backends (void) EV_NOEXCEPT |
2780 | { |
2816 | { |
2781 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2817 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2782 | |
2818 | |
2783 | /* 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 */ |
2784 | 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 */ |
… | |
… | |
2786 | |
2822 | |
2787 | return flags; |
2823 | return flags; |
2788 | } |
2824 | } |
2789 | |
2825 | |
2790 | unsigned int |
2826 | unsigned int |
2791 | ev_backend (EV_P) EV_THROW |
2827 | ev_backend (EV_P) EV_NOEXCEPT |
2792 | { |
2828 | { |
2793 | return backend; |
2829 | return backend; |
2794 | } |
2830 | } |
2795 | |
2831 | |
2796 | #if EV_FEATURE_API |
2832 | #if EV_FEATURE_API |
2797 | unsigned int |
2833 | unsigned int |
2798 | ev_iteration (EV_P) EV_THROW |
2834 | ev_iteration (EV_P) EV_NOEXCEPT |
2799 | { |
2835 | { |
2800 | return loop_count; |
2836 | return loop_count; |
2801 | } |
2837 | } |
2802 | |
2838 | |
2803 | unsigned int |
2839 | unsigned int |
2804 | ev_depth (EV_P) EV_THROW |
2840 | ev_depth (EV_P) EV_NOEXCEPT |
2805 | { |
2841 | { |
2806 | return loop_depth; |
2842 | return loop_depth; |
2807 | } |
2843 | } |
2808 | |
2844 | |
2809 | void |
2845 | void |
2810 | 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 |
2811 | { |
2847 | { |
2812 | io_blocktime = interval; |
2848 | io_blocktime = interval; |
2813 | } |
2849 | } |
2814 | |
2850 | |
2815 | void |
2851 | void |
2816 | 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 |
2817 | { |
2853 | { |
2818 | timeout_blocktime = interval; |
2854 | timeout_blocktime = interval; |
2819 | } |
2855 | } |
2820 | |
2856 | |
2821 | void |
2857 | void |
2822 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2858 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2823 | { |
2859 | { |
2824 | userdata = data; |
2860 | userdata = data; |
2825 | } |
2861 | } |
2826 | |
2862 | |
2827 | void * |
2863 | void * |
2828 | ev_userdata (EV_P) EV_THROW |
2864 | ev_userdata (EV_P) EV_NOEXCEPT |
2829 | { |
2865 | { |
2830 | return userdata; |
2866 | return userdata; |
2831 | } |
2867 | } |
2832 | |
2868 | |
2833 | void |
2869 | void |
2834 | 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 |
2835 | { |
2871 | { |
2836 | invoke_cb = invoke_pending_cb; |
2872 | invoke_cb = invoke_pending_cb; |
2837 | } |
2873 | } |
2838 | |
2874 | |
2839 | void |
2875 | void |
2840 | 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 |
2841 | { |
2877 | { |
2842 | release_cb = release; |
2878 | release_cb = release; |
2843 | acquire_cb = acquire; |
2879 | acquire_cb = acquire; |
2844 | } |
2880 | } |
2845 | #endif |
2881 | #endif |
2846 | |
2882 | |
2847 | /* initialise a loop structure, must be zero-initialised */ |
2883 | /* initialise a loop structure, must be zero-initialised */ |
2848 | noinline ecb_cold |
2884 | noinline ecb_cold |
2849 | static void |
2885 | static void |
2850 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2886 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2851 | { |
2887 | { |
2852 | if (!backend) |
2888 | if (!backend) |
2853 | { |
2889 | { |
2854 | origflags = flags; |
2890 | origflags = flags; |
2855 | |
2891 | |
… | |
… | |
2913 | |
2949 | |
2914 | if (!(flags & EVBACKEND_MASK)) |
2950 | if (!(flags & EVBACKEND_MASK)) |
2915 | flags |= ev_recommended_backends (); |
2951 | flags |= ev_recommended_backends (); |
2916 | |
2952 | |
2917 | #if EV_USE_IOCP |
2953 | #if EV_USE_IOCP |
2918 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2954 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2919 | #endif |
2955 | #endif |
2920 | #if EV_USE_PORT |
2956 | #if EV_USE_PORT |
2921 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2957 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2922 | #endif |
2958 | #endif |
2923 | #if EV_USE_KQUEUE |
2959 | #if EV_USE_KQUEUE |
2924 | 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); |
2925 | #endif |
2964 | #endif |
2926 | #if EV_USE_EPOLL |
2965 | #if EV_USE_EPOLL |
2927 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2966 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2928 | #endif |
2967 | #endif |
2929 | #if EV_USE_POLL |
2968 | #if EV_USE_POLL |
2930 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2969 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2931 | #endif |
2970 | #endif |
2932 | #if EV_USE_SELECT |
2971 | #if EV_USE_SELECT |
2933 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2972 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2934 | #endif |
2973 | #endif |
2935 | |
2974 | |
2936 | ev_prepare_init (&pending_w, pendingcb); |
2975 | ev_prepare_init (&pending_w, pendingcb); |
2937 | |
2976 | |
2938 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2977 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2993 | |
3032 | |
2994 | if (backend_fd >= 0) |
3033 | if (backend_fd >= 0) |
2995 | close (backend_fd); |
3034 | close (backend_fd); |
2996 | |
3035 | |
2997 | #if EV_USE_IOCP |
3036 | #if EV_USE_IOCP |
2998 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3037 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2999 | #endif |
3038 | #endif |
3000 | #if EV_USE_PORT |
3039 | #if EV_USE_PORT |
3001 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3040 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3002 | #endif |
3041 | #endif |
3003 | #if EV_USE_KQUEUE |
3042 | #if EV_USE_KQUEUE |
3004 | 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); |
3005 | #endif |
3047 | #endif |
3006 | #if EV_USE_EPOLL |
3048 | #if EV_USE_EPOLL |
3007 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3049 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3008 | #endif |
3050 | #endif |
3009 | #if EV_USE_POLL |
3051 | #if EV_USE_POLL |
3010 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3052 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3011 | #endif |
3053 | #endif |
3012 | #if EV_USE_SELECT |
3054 | #if EV_USE_SELECT |
3013 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3055 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3014 | #endif |
3056 | #endif |
3015 | |
3057 | |
3016 | for (i = NUMPRI; i--; ) |
3058 | for (i = NUMPRI; i--; ) |
3017 | { |
3059 | { |
3018 | array_free (pending, [i]); |
3060 | array_free (pending, [i]); |
… | |
… | |
3060 | |
3102 | |
3061 | inline_size void |
3103 | inline_size void |
3062 | loop_fork (EV_P) |
3104 | loop_fork (EV_P) |
3063 | { |
3105 | { |
3064 | #if EV_USE_PORT |
3106 | #if EV_USE_PORT |
3065 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3107 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3066 | #endif |
3108 | #endif |
3067 | #if EV_USE_KQUEUE |
3109 | #if EV_USE_KQUEUE |
3068 | 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); |
3069 | #endif |
3114 | #endif |
3070 | #if EV_USE_EPOLL |
3115 | #if EV_USE_EPOLL |
3071 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3116 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3072 | #endif |
3117 | #endif |
3073 | #if EV_USE_INOTIFY |
3118 | #if EV_USE_INOTIFY |
3074 | infy_fork (EV_A); |
3119 | infy_fork (EV_A); |
3075 | #endif |
3120 | #endif |
3076 | |
3121 | |
… | |
… | |
3096 | |
3141 | |
3097 | #if EV_MULTIPLICITY |
3142 | #if EV_MULTIPLICITY |
3098 | |
3143 | |
3099 | ecb_cold |
3144 | ecb_cold |
3100 | struct ev_loop * |
3145 | struct ev_loop * |
3101 | ev_loop_new (unsigned int flags) EV_THROW |
3146 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3102 | { |
3147 | { |
3103 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3148 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3104 | |
3149 | |
3105 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3150 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3106 | loop_init (EV_A_ flags); |
3151 | loop_init (EV_A_ flags); |
… | |
… | |
3153 | } |
3198 | } |
3154 | #endif |
3199 | #endif |
3155 | |
3200 | |
3156 | #if EV_FEATURE_API |
3201 | #if EV_FEATURE_API |
3157 | void ecb_cold |
3202 | void ecb_cold |
3158 | ev_verify (EV_P) EV_THROW |
3203 | ev_verify (EV_P) EV_NOEXCEPT |
3159 | { |
3204 | { |
3160 | #if EV_VERIFY |
3205 | #if EV_VERIFY |
3161 | int i; |
3206 | int i; |
3162 | WL w, w2; |
3207 | WL w, w2; |
3163 | |
3208 | |
… | |
… | |
3244 | ecb_cold |
3289 | ecb_cold |
3245 | struct ev_loop * |
3290 | struct ev_loop * |
3246 | #else |
3291 | #else |
3247 | int |
3292 | int |
3248 | #endif |
3293 | #endif |
3249 | ev_default_loop (unsigned int flags) EV_THROW |
3294 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3250 | { |
3295 | { |
3251 | if (!ev_default_loop_ptr) |
3296 | if (!ev_default_loop_ptr) |
3252 | { |
3297 | { |
3253 | #if EV_MULTIPLICITY |
3298 | #if EV_MULTIPLICITY |
3254 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3299 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3273 | |
3318 | |
3274 | return ev_default_loop_ptr; |
3319 | return ev_default_loop_ptr; |
3275 | } |
3320 | } |
3276 | |
3321 | |
3277 | void |
3322 | void |
3278 | ev_loop_fork (EV_P) EV_THROW |
3323 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3279 | { |
3324 | { |
3280 | postfork = 1; |
3325 | postfork = 1; |
3281 | } |
3326 | } |
3282 | |
3327 | |
3283 | /*****************************************************************************/ |
3328 | /*****************************************************************************/ |
… | |
… | |
3287 | { |
3332 | { |
3288 | EV_CB_INVOKE ((W)w, revents); |
3333 | EV_CB_INVOKE ((W)w, revents); |
3289 | } |
3334 | } |
3290 | |
3335 | |
3291 | unsigned int |
3336 | unsigned int |
3292 | ev_pending_count (EV_P) EV_THROW |
3337 | ev_pending_count (EV_P) EV_NOEXCEPT |
3293 | { |
3338 | { |
3294 | int pri; |
3339 | int pri; |
3295 | unsigned int count = 0; |
3340 | unsigned int count = 0; |
3296 | |
3341 | |
3297 | for (pri = NUMPRI; pri--; ) |
3342 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3737 | |
3782 | |
3738 | return activecnt; |
3783 | return activecnt; |
3739 | } |
3784 | } |
3740 | |
3785 | |
3741 | void |
3786 | void |
3742 | ev_break (EV_P_ int how) EV_THROW |
3787 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3743 | { |
3788 | { |
3744 | loop_done = how; |
3789 | loop_done = how; |
3745 | } |
3790 | } |
3746 | |
3791 | |
3747 | void |
3792 | void |
3748 | ev_ref (EV_P) EV_THROW |
3793 | ev_ref (EV_P) EV_NOEXCEPT |
3749 | { |
3794 | { |
3750 | ++activecnt; |
3795 | ++activecnt; |
3751 | } |
3796 | } |
3752 | |
3797 | |
3753 | void |
3798 | void |
3754 | ev_unref (EV_P) EV_THROW |
3799 | ev_unref (EV_P) EV_NOEXCEPT |
3755 | { |
3800 | { |
3756 | --activecnt; |
3801 | --activecnt; |
3757 | } |
3802 | } |
3758 | |
3803 | |
3759 | void |
3804 | void |
3760 | ev_now_update (EV_P) EV_THROW |
3805 | ev_now_update (EV_P) EV_NOEXCEPT |
3761 | { |
3806 | { |
3762 | time_update (EV_A_ 1e100); |
3807 | time_update (EV_A_ 1e100); |
3763 | } |
3808 | } |
3764 | |
3809 | |
3765 | void |
3810 | void |
3766 | ev_suspend (EV_P) EV_THROW |
3811 | ev_suspend (EV_P) EV_NOEXCEPT |
3767 | { |
3812 | { |
3768 | ev_now_update (EV_A); |
3813 | ev_now_update (EV_A); |
3769 | } |
3814 | } |
3770 | |
3815 | |
3771 | void |
3816 | void |
3772 | ev_resume (EV_P) EV_THROW |
3817 | ev_resume (EV_P) EV_NOEXCEPT |
3773 | { |
3818 | { |
3774 | ev_tstamp mn_prev = mn_now; |
3819 | ev_tstamp mn_prev = mn_now; |
3775 | |
3820 | |
3776 | ev_now_update (EV_A); |
3821 | ev_now_update (EV_A); |
3777 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3822 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3816 | w->pending = 0; |
3861 | w->pending = 0; |
3817 | } |
3862 | } |
3818 | } |
3863 | } |
3819 | |
3864 | |
3820 | int |
3865 | int |
3821 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3866 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3822 | { |
3867 | { |
3823 | W w_ = (W)w; |
3868 | W w_ = (W)w; |
3824 | int pending = w_->pending; |
3869 | int pending = w_->pending; |
3825 | |
3870 | |
3826 | if (expect_true (pending)) |
3871 | if (expect_true (pending)) |
… | |
… | |
3860 | |
3905 | |
3861 | /*****************************************************************************/ |
3906 | /*****************************************************************************/ |
3862 | |
3907 | |
3863 | noinline |
3908 | noinline |
3864 | void |
3909 | void |
3865 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3910 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3866 | { |
3911 | { |
3867 | int fd = w->fd; |
3912 | int fd = w->fd; |
3868 | |
3913 | |
3869 | if (expect_false (ev_is_active (w))) |
3914 | if (expect_false (ev_is_active (w))) |
3870 | return; |
3915 | return; |
… | |
… | |
3873 | 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)))); |
3874 | |
3919 | |
3875 | EV_FREQUENT_CHECK; |
3920 | EV_FREQUENT_CHECK; |
3876 | |
3921 | |
3877 | ev_start (EV_A_ (W)w, 1); |
3922 | ev_start (EV_A_ (W)w, 1); |
3878 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3923 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3879 | wlist_add (&anfds[fd].head, (WL)w); |
3924 | wlist_add (&anfds[fd].head, (WL)w); |
3880 | |
3925 | |
3881 | /* common bug, apparently */ |
3926 | /* common bug, apparently */ |
3882 | 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)); |
3883 | |
3928 | |
… | |
… | |
3887 | EV_FREQUENT_CHECK; |
3932 | EV_FREQUENT_CHECK; |
3888 | } |
3933 | } |
3889 | |
3934 | |
3890 | noinline |
3935 | noinline |
3891 | void |
3936 | void |
3892 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3937 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3893 | { |
3938 | { |
3894 | clear_pending (EV_A_ (W)w); |
3939 | clear_pending (EV_A_ (W)w); |
3895 | if (expect_false (!ev_is_active (w))) |
3940 | if (expect_false (!ev_is_active (w))) |
3896 | return; |
3941 | return; |
3897 | |
3942 | |
… | |
… | |
3907 | EV_FREQUENT_CHECK; |
3952 | EV_FREQUENT_CHECK; |
3908 | } |
3953 | } |
3909 | |
3954 | |
3910 | noinline |
3955 | noinline |
3911 | void |
3956 | void |
3912 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3957 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3913 | { |
3958 | { |
3914 | if (expect_false (ev_is_active (w))) |
3959 | if (expect_false (ev_is_active (w))) |
3915 | return; |
3960 | return; |
3916 | |
3961 | |
3917 | ev_at (w) += mn_now; |
3962 | ev_at (w) += mn_now; |
… | |
… | |
3920 | |
3965 | |
3921 | EV_FREQUENT_CHECK; |
3966 | EV_FREQUENT_CHECK; |
3922 | |
3967 | |
3923 | ++timercnt; |
3968 | ++timercnt; |
3924 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3969 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3925 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3970 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3926 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3971 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3927 | ANHE_at_cache (timers [ev_active (w)]); |
3972 | ANHE_at_cache (timers [ev_active (w)]); |
3928 | upheap (timers, ev_active (w)); |
3973 | upheap (timers, ev_active (w)); |
3929 | |
3974 | |
3930 | EV_FREQUENT_CHECK; |
3975 | EV_FREQUENT_CHECK; |
… | |
… | |
3932 | /*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));*/ |
3933 | } |
3978 | } |
3934 | |
3979 | |
3935 | noinline |
3980 | noinline |
3936 | void |
3981 | void |
3937 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3982 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3938 | { |
3983 | { |
3939 | clear_pending (EV_A_ (W)w); |
3984 | clear_pending (EV_A_ (W)w); |
3940 | if (expect_false (!ev_is_active (w))) |
3985 | if (expect_false (!ev_is_active (w))) |
3941 | return; |
3986 | return; |
3942 | |
3987 | |
… | |
… | |
3963 | EV_FREQUENT_CHECK; |
4008 | EV_FREQUENT_CHECK; |
3964 | } |
4009 | } |
3965 | |
4010 | |
3966 | noinline |
4011 | noinline |
3967 | void |
4012 | void |
3968 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4013 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3969 | { |
4014 | { |
3970 | EV_FREQUENT_CHECK; |
4015 | EV_FREQUENT_CHECK; |
3971 | |
4016 | |
3972 | clear_pending (EV_A_ (W)w); |
4017 | clear_pending (EV_A_ (W)w); |
3973 | |
4018 | |
… | |
… | |
3990 | |
4035 | |
3991 | EV_FREQUENT_CHECK; |
4036 | EV_FREQUENT_CHECK; |
3992 | } |
4037 | } |
3993 | |
4038 | |
3994 | ev_tstamp |
4039 | ev_tstamp |
3995 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4040 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3996 | { |
4041 | { |
3997 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4042 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3998 | } |
4043 | } |
3999 | |
4044 | |
4000 | #if EV_PERIODIC_ENABLE |
4045 | #if EV_PERIODIC_ENABLE |
4001 | noinline |
4046 | noinline |
4002 | void |
4047 | void |
4003 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4048 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4004 | { |
4049 | { |
4005 | if (expect_false (ev_is_active (w))) |
4050 | if (expect_false (ev_is_active (w))) |
4006 | return; |
4051 | return; |
4007 | |
4052 | |
4008 | if (w->reschedule_cb) |
4053 | if (w->reschedule_cb) |
… | |
… | |
4017 | |
4062 | |
4018 | EV_FREQUENT_CHECK; |
4063 | EV_FREQUENT_CHECK; |
4019 | |
4064 | |
4020 | ++periodiccnt; |
4065 | ++periodiccnt; |
4021 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4066 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4022 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4067 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4023 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4068 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4024 | ANHE_at_cache (periodics [ev_active (w)]); |
4069 | ANHE_at_cache (periodics [ev_active (w)]); |
4025 | upheap (periodics, ev_active (w)); |
4070 | upheap (periodics, ev_active (w)); |
4026 | |
4071 | |
4027 | EV_FREQUENT_CHECK; |
4072 | EV_FREQUENT_CHECK; |
… | |
… | |
4029 | /*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));*/ |
4030 | } |
4075 | } |
4031 | |
4076 | |
4032 | noinline |
4077 | noinline |
4033 | void |
4078 | void |
4034 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4079 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4035 | { |
4080 | { |
4036 | clear_pending (EV_A_ (W)w); |
4081 | clear_pending (EV_A_ (W)w); |
4037 | if (expect_false (!ev_is_active (w))) |
4082 | if (expect_false (!ev_is_active (w))) |
4038 | return; |
4083 | return; |
4039 | |
4084 | |
… | |
… | |
4058 | EV_FREQUENT_CHECK; |
4103 | EV_FREQUENT_CHECK; |
4059 | } |
4104 | } |
4060 | |
4105 | |
4061 | noinline |
4106 | noinline |
4062 | void |
4107 | void |
4063 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4108 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4064 | { |
4109 | { |
4065 | /* TODO: use adjustheap and recalculation */ |
4110 | /* TODO: use adjustheap and recalculation */ |
4066 | ev_periodic_stop (EV_A_ w); |
4111 | ev_periodic_stop (EV_A_ w); |
4067 | ev_periodic_start (EV_A_ w); |
4112 | ev_periodic_start (EV_A_ w); |
4068 | } |
4113 | } |
… | |
… | |
4074 | |
4119 | |
4075 | #if EV_SIGNAL_ENABLE |
4120 | #if EV_SIGNAL_ENABLE |
4076 | |
4121 | |
4077 | noinline |
4122 | noinline |
4078 | void |
4123 | void |
4079 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4124 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4080 | { |
4125 | { |
4081 | if (expect_false (ev_is_active (w))) |
4126 | if (expect_false (ev_is_active (w))) |
4082 | return; |
4127 | return; |
4083 | |
4128 | |
4084 | 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)); |
… | |
… | |
4157 | EV_FREQUENT_CHECK; |
4202 | EV_FREQUENT_CHECK; |
4158 | } |
4203 | } |
4159 | |
4204 | |
4160 | noinline |
4205 | noinline |
4161 | void |
4206 | void |
4162 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4207 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4163 | { |
4208 | { |
4164 | clear_pending (EV_A_ (W)w); |
4209 | clear_pending (EV_A_ (W)w); |
4165 | if (expect_false (!ev_is_active (w))) |
4210 | if (expect_false (!ev_is_active (w))) |
4166 | return; |
4211 | return; |
4167 | |
4212 | |
… | |
… | |
4198 | #endif |
4243 | #endif |
4199 | |
4244 | |
4200 | #if EV_CHILD_ENABLE |
4245 | #if EV_CHILD_ENABLE |
4201 | |
4246 | |
4202 | void |
4247 | void |
4203 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4248 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4204 | { |
4249 | { |
4205 | #if EV_MULTIPLICITY |
4250 | #if EV_MULTIPLICITY |
4206 | 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)); |
4207 | #endif |
4252 | #endif |
4208 | if (expect_false (ev_is_active (w))) |
4253 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4215 | |
4260 | |
4216 | EV_FREQUENT_CHECK; |
4261 | EV_FREQUENT_CHECK; |
4217 | } |
4262 | } |
4218 | |
4263 | |
4219 | void |
4264 | void |
4220 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4265 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4221 | { |
4266 | { |
4222 | clear_pending (EV_A_ (W)w); |
4267 | clear_pending (EV_A_ (W)w); |
4223 | if (expect_false (!ev_is_active (w))) |
4268 | if (expect_false (!ev_is_active (w))) |
4224 | return; |
4269 | return; |
4225 | |
4270 | |
… | |
… | |
4490 | #else |
4535 | #else |
4491 | # define EV_LSTAT(p,b) lstat (p, b) |
4536 | # define EV_LSTAT(p,b) lstat (p, b) |
4492 | #endif |
4537 | #endif |
4493 | |
4538 | |
4494 | void |
4539 | void |
4495 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4540 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4496 | { |
4541 | { |
4497 | if (lstat (w->path, &w->attr) < 0) |
4542 | if (lstat (w->path, &w->attr) < 0) |
4498 | w->attr.st_nlink = 0; |
4543 | w->attr.st_nlink = 0; |
4499 | else if (!w->attr.st_nlink) |
4544 | else if (!w->attr.st_nlink) |
4500 | w->attr.st_nlink = 1; |
4545 | w->attr.st_nlink = 1; |
… | |
… | |
4540 | ev_feed_event (EV_A_ w, EV_STAT); |
4585 | ev_feed_event (EV_A_ w, EV_STAT); |
4541 | } |
4586 | } |
4542 | } |
4587 | } |
4543 | |
4588 | |
4544 | void |
4589 | void |
4545 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4590 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4546 | { |
4591 | { |
4547 | if (expect_false (ev_is_active (w))) |
4592 | if (expect_false (ev_is_active (w))) |
4548 | return; |
4593 | return; |
4549 | |
4594 | |
4550 | ev_stat_stat (EV_A_ w); |
4595 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4571 | |
4616 | |
4572 | EV_FREQUENT_CHECK; |
4617 | EV_FREQUENT_CHECK; |
4573 | } |
4618 | } |
4574 | |
4619 | |
4575 | void |
4620 | void |
4576 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4621 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4577 | { |
4622 | { |
4578 | clear_pending (EV_A_ (W)w); |
4623 | clear_pending (EV_A_ (W)w); |
4579 | if (expect_false (!ev_is_active (w))) |
4624 | if (expect_false (!ev_is_active (w))) |
4580 | return; |
4625 | return; |
4581 | |
4626 | |
… | |
… | |
4597 | } |
4642 | } |
4598 | #endif |
4643 | #endif |
4599 | |
4644 | |
4600 | #if EV_IDLE_ENABLE |
4645 | #if EV_IDLE_ENABLE |
4601 | void |
4646 | void |
4602 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4647 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4603 | { |
4648 | { |
4604 | if (expect_false (ev_is_active (w))) |
4649 | if (expect_false (ev_is_active (w))) |
4605 | return; |
4650 | return; |
4606 | |
4651 | |
4607 | pri_adjust (EV_A_ (W)w); |
4652 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4612 | int active = ++idlecnt [ABSPRI (w)]; |
4657 | int active = ++idlecnt [ABSPRI (w)]; |
4613 | |
4658 | |
4614 | ++idleall; |
4659 | ++idleall; |
4615 | ev_start (EV_A_ (W)w, active); |
4660 | ev_start (EV_A_ (W)w, active); |
4616 | |
4661 | |
4617 | 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); |
4618 | idles [ABSPRI (w)][active - 1] = w; |
4663 | idles [ABSPRI (w)][active - 1] = w; |
4619 | } |
4664 | } |
4620 | |
4665 | |
4621 | EV_FREQUENT_CHECK; |
4666 | EV_FREQUENT_CHECK; |
4622 | } |
4667 | } |
4623 | |
4668 | |
4624 | void |
4669 | void |
4625 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4670 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4626 | { |
4671 | { |
4627 | clear_pending (EV_A_ (W)w); |
4672 | clear_pending (EV_A_ (W)w); |
4628 | if (expect_false (!ev_is_active (w))) |
4673 | if (expect_false (!ev_is_active (w))) |
4629 | return; |
4674 | return; |
4630 | |
4675 | |
… | |
… | |
4644 | } |
4689 | } |
4645 | #endif |
4690 | #endif |
4646 | |
4691 | |
4647 | #if EV_PREPARE_ENABLE |
4692 | #if EV_PREPARE_ENABLE |
4648 | void |
4693 | void |
4649 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4694 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4650 | { |
4695 | { |
4651 | if (expect_false (ev_is_active (w))) |
4696 | if (expect_false (ev_is_active (w))) |
4652 | return; |
4697 | return; |
4653 | |
4698 | |
4654 | EV_FREQUENT_CHECK; |
4699 | EV_FREQUENT_CHECK; |
4655 | |
4700 | |
4656 | ev_start (EV_A_ (W)w, ++preparecnt); |
4701 | ev_start (EV_A_ (W)w, ++preparecnt); |
4657 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4702 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4658 | prepares [preparecnt - 1] = w; |
4703 | prepares [preparecnt - 1] = w; |
4659 | |
4704 | |
4660 | EV_FREQUENT_CHECK; |
4705 | EV_FREQUENT_CHECK; |
4661 | } |
4706 | } |
4662 | |
4707 | |
4663 | void |
4708 | void |
4664 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4709 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4665 | { |
4710 | { |
4666 | clear_pending (EV_A_ (W)w); |
4711 | clear_pending (EV_A_ (W)w); |
4667 | if (expect_false (!ev_is_active (w))) |
4712 | if (expect_false (!ev_is_active (w))) |
4668 | return; |
4713 | return; |
4669 | |
4714 | |
… | |
… | |
4682 | } |
4727 | } |
4683 | #endif |
4728 | #endif |
4684 | |
4729 | |
4685 | #if EV_CHECK_ENABLE |
4730 | #if EV_CHECK_ENABLE |
4686 | void |
4731 | void |
4687 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4732 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4688 | { |
4733 | { |
4689 | if (expect_false (ev_is_active (w))) |
4734 | if (expect_false (ev_is_active (w))) |
4690 | return; |
4735 | return; |
4691 | |
4736 | |
4692 | EV_FREQUENT_CHECK; |
4737 | EV_FREQUENT_CHECK; |
4693 | |
4738 | |
4694 | ev_start (EV_A_ (W)w, ++checkcnt); |
4739 | ev_start (EV_A_ (W)w, ++checkcnt); |
4695 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4740 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4696 | checks [checkcnt - 1] = w; |
4741 | checks [checkcnt - 1] = w; |
4697 | |
4742 | |
4698 | EV_FREQUENT_CHECK; |
4743 | EV_FREQUENT_CHECK; |
4699 | } |
4744 | } |
4700 | |
4745 | |
4701 | void |
4746 | void |
4702 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4747 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4703 | { |
4748 | { |
4704 | clear_pending (EV_A_ (W)w); |
4749 | clear_pending (EV_A_ (W)w); |
4705 | if (expect_false (!ev_is_active (w))) |
4750 | if (expect_false (!ev_is_active (w))) |
4706 | return; |
4751 | return; |
4707 | |
4752 | |
… | |
… | |
4721 | #endif |
4766 | #endif |
4722 | |
4767 | |
4723 | #if EV_EMBED_ENABLE |
4768 | #if EV_EMBED_ENABLE |
4724 | noinline |
4769 | noinline |
4725 | void |
4770 | void |
4726 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4771 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4727 | { |
4772 | { |
4728 | ev_run (w->other, EVRUN_NOWAIT); |
4773 | ev_run (w->other, EVRUN_NOWAIT); |
4729 | } |
4774 | } |
4730 | |
4775 | |
4731 | static void |
4776 | static void |
… | |
… | |
4779 | ev_idle_stop (EV_A_ idle); |
4824 | ev_idle_stop (EV_A_ idle); |
4780 | } |
4825 | } |
4781 | #endif |
4826 | #endif |
4782 | |
4827 | |
4783 | void |
4828 | void |
4784 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4829 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4785 | { |
4830 | { |
4786 | if (expect_false (ev_is_active (w))) |
4831 | if (expect_false (ev_is_active (w))) |
4787 | return; |
4832 | return; |
4788 | |
4833 | |
4789 | { |
4834 | { |
… | |
… | |
4810 | |
4855 | |
4811 | EV_FREQUENT_CHECK; |
4856 | EV_FREQUENT_CHECK; |
4812 | } |
4857 | } |
4813 | |
4858 | |
4814 | void |
4859 | void |
4815 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4860 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4816 | { |
4861 | { |
4817 | clear_pending (EV_A_ (W)w); |
4862 | clear_pending (EV_A_ (W)w); |
4818 | if (expect_false (!ev_is_active (w))) |
4863 | if (expect_false (!ev_is_active (w))) |
4819 | return; |
4864 | return; |
4820 | |
4865 | |
… | |
… | |
4830 | } |
4875 | } |
4831 | #endif |
4876 | #endif |
4832 | |
4877 | |
4833 | #if EV_FORK_ENABLE |
4878 | #if EV_FORK_ENABLE |
4834 | void |
4879 | void |
4835 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4880 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4836 | { |
4881 | { |
4837 | if (expect_false (ev_is_active (w))) |
4882 | if (expect_false (ev_is_active (w))) |
4838 | return; |
4883 | return; |
4839 | |
4884 | |
4840 | EV_FREQUENT_CHECK; |
4885 | EV_FREQUENT_CHECK; |
4841 | |
4886 | |
4842 | ev_start (EV_A_ (W)w, ++forkcnt); |
4887 | ev_start (EV_A_ (W)w, ++forkcnt); |
4843 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4888 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4844 | forks [forkcnt - 1] = w; |
4889 | forks [forkcnt - 1] = w; |
4845 | |
4890 | |
4846 | EV_FREQUENT_CHECK; |
4891 | EV_FREQUENT_CHECK; |
4847 | } |
4892 | } |
4848 | |
4893 | |
4849 | void |
4894 | void |
4850 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4895 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4851 | { |
4896 | { |
4852 | clear_pending (EV_A_ (W)w); |
4897 | clear_pending (EV_A_ (W)w); |
4853 | if (expect_false (!ev_is_active (w))) |
4898 | if (expect_false (!ev_is_active (w))) |
4854 | return; |
4899 | return; |
4855 | |
4900 | |
… | |
… | |
4868 | } |
4913 | } |
4869 | #endif |
4914 | #endif |
4870 | |
4915 | |
4871 | #if EV_CLEANUP_ENABLE |
4916 | #if EV_CLEANUP_ENABLE |
4872 | void |
4917 | void |
4873 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4918 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4874 | { |
4919 | { |
4875 | if (expect_false (ev_is_active (w))) |
4920 | if (expect_false (ev_is_active (w))) |
4876 | return; |
4921 | return; |
4877 | |
4922 | |
4878 | EV_FREQUENT_CHECK; |
4923 | EV_FREQUENT_CHECK; |
4879 | |
4924 | |
4880 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4925 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4881 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4926 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4882 | cleanups [cleanupcnt - 1] = w; |
4927 | cleanups [cleanupcnt - 1] = w; |
4883 | |
4928 | |
4884 | /* cleanup watchers should never keep a refcount on the loop */ |
4929 | /* cleanup watchers should never keep a refcount on the loop */ |
4885 | ev_unref (EV_A); |
4930 | ev_unref (EV_A); |
4886 | EV_FREQUENT_CHECK; |
4931 | EV_FREQUENT_CHECK; |
4887 | } |
4932 | } |
4888 | |
4933 | |
4889 | void |
4934 | void |
4890 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4935 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4891 | { |
4936 | { |
4892 | clear_pending (EV_A_ (W)w); |
4937 | clear_pending (EV_A_ (W)w); |
4893 | if (expect_false (!ev_is_active (w))) |
4938 | if (expect_false (!ev_is_active (w))) |
4894 | return; |
4939 | return; |
4895 | |
4940 | |
… | |
… | |
4909 | } |
4954 | } |
4910 | #endif |
4955 | #endif |
4911 | |
4956 | |
4912 | #if EV_ASYNC_ENABLE |
4957 | #if EV_ASYNC_ENABLE |
4913 | void |
4958 | void |
4914 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4959 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4915 | { |
4960 | { |
4916 | if (expect_false (ev_is_active (w))) |
4961 | if (expect_false (ev_is_active (w))) |
4917 | return; |
4962 | return; |
4918 | |
4963 | |
4919 | w->sent = 0; |
4964 | w->sent = 0; |
… | |
… | |
4921 | evpipe_init (EV_A); |
4966 | evpipe_init (EV_A); |
4922 | |
4967 | |
4923 | EV_FREQUENT_CHECK; |
4968 | EV_FREQUENT_CHECK; |
4924 | |
4969 | |
4925 | ev_start (EV_A_ (W)w, ++asynccnt); |
4970 | ev_start (EV_A_ (W)w, ++asynccnt); |
4926 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4971 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4927 | asyncs [asynccnt - 1] = w; |
4972 | asyncs [asynccnt - 1] = w; |
4928 | |
4973 | |
4929 | EV_FREQUENT_CHECK; |
4974 | EV_FREQUENT_CHECK; |
4930 | } |
4975 | } |
4931 | |
4976 | |
4932 | void |
4977 | void |
4933 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4978 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4934 | { |
4979 | { |
4935 | clear_pending (EV_A_ (W)w); |
4980 | clear_pending (EV_A_ (W)w); |
4936 | if (expect_false (!ev_is_active (w))) |
4981 | if (expect_false (!ev_is_active (w))) |
4937 | return; |
4982 | return; |
4938 | |
4983 | |
… | |
… | |
4949 | |
4994 | |
4950 | EV_FREQUENT_CHECK; |
4995 | EV_FREQUENT_CHECK; |
4951 | } |
4996 | } |
4952 | |
4997 | |
4953 | void |
4998 | void |
4954 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4999 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4955 | { |
5000 | { |
4956 | w->sent = 1; |
5001 | w->sent = 1; |
4957 | evpipe_write (EV_A_ &async_pending); |
5002 | evpipe_write (EV_A_ &async_pending); |
4958 | } |
5003 | } |
4959 | #endif |
5004 | #endif |
… | |
… | |
4996 | |
5041 | |
4997 | 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)); |
4998 | } |
5043 | } |
4999 | |
5044 | |
5000 | void |
5045 | void |
5001 | 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 |
5002 | { |
5047 | { |
5003 | 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)); |
5004 | |
|
|
5005 | if (expect_false (!once)) |
|
|
5006 | { |
|
|
5007 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5008 | return; |
|
|
5009 | } |
|
|
5010 | |
5049 | |
5011 | once->cb = cb; |
5050 | once->cb = cb; |
5012 | once->arg = arg; |
5051 | once->arg = arg; |
5013 | |
5052 | |
5014 | ev_init (&once->io, once_cb_io); |
5053 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5029 | /*****************************************************************************/ |
5068 | /*****************************************************************************/ |
5030 | |
5069 | |
5031 | #if EV_WALK_ENABLE |
5070 | #if EV_WALK_ENABLE |
5032 | ecb_cold |
5071 | ecb_cold |
5033 | void |
5072 | void |
5034 | 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 |
5035 | { |
5074 | { |
5036 | int i, j; |
5075 | int i, j; |
5037 | ev_watcher_list *wl, *wn; |
5076 | ev_watcher_list *wl, *wn; |
5038 | |
5077 | |
5039 | if (types & (EV_IO | EV_EMBED)) |
5078 | if (types & (EV_IO | EV_EMBED)) |