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 | # if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */ |
|
|
331 | # define EV_USE_LINUXAIO 1 |
|
|
332 | # else |
|
|
333 | # define EV_USE_LINUXAIO 0 |
|
|
334 | # endif |
|
|
335 | #endif |
|
|
336 | |
320 | #ifndef EV_USE_INOTIFY |
337 | #ifndef EV_USE_INOTIFY |
321 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
338 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
322 | # define EV_USE_INOTIFY EV_FEATURE_OS |
339 | # define EV_USE_INOTIFY EV_FEATURE_OS |
323 | # else |
340 | # else |
324 | # define EV_USE_INOTIFY 0 |
341 | # define EV_USE_INOTIFY 0 |
… | |
… | |
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 || !EV_USE_EPOLL |
|
|
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 | |
… | |
… | |
1575 | #ifdef _WIN32 |
1602 | #ifdef _WIN32 |
1576 | # include "ev_win32.c" |
1603 | # include "ev_win32.c" |
1577 | #endif |
1604 | #endif |
1578 | |
1605 | |
1579 | /*****************************************************************************/ |
1606 | /*****************************************************************************/ |
|
|
1607 | |
|
|
1608 | #if EV_USE_LINUXAIO |
|
|
1609 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
|
|
1610 | #endif |
1580 | |
1611 | |
1581 | /* define a suitable floor function (only used by periodics atm) */ |
1612 | /* define a suitable floor function (only used by periodics atm) */ |
1582 | |
1613 | |
1583 | #if EV_USE_FLOOR |
1614 | #if EV_USE_FLOOR |
1584 | # include <math.h> |
1615 | # include <math.h> |
… | |
… | |
1677 | { |
1708 | { |
1678 | write (STDERR_FILENO, msg, strlen (msg)); |
1709 | write (STDERR_FILENO, msg, strlen (msg)); |
1679 | } |
1710 | } |
1680 | #endif |
1711 | #endif |
1681 | |
1712 | |
1682 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1713 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1683 | |
1714 | |
1684 | ecb_cold |
1715 | ecb_cold |
1685 | void |
1716 | void |
1686 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1717 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1687 | { |
1718 | { |
1688 | syserr_cb = cb; |
1719 | syserr_cb = cb; |
1689 | } |
1720 | } |
1690 | |
1721 | |
1691 | noinline ecb_cold |
1722 | noinline ecb_cold |
… | |
… | |
1710 | abort (); |
1741 | abort (); |
1711 | } |
1742 | } |
1712 | } |
1743 | } |
1713 | |
1744 | |
1714 | static void * |
1745 | static void * |
1715 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1746 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1716 | { |
1747 | { |
1717 | /* some systems, notably openbsd and darwin, fail to properly |
1748 | /* some systems, notably openbsd and darwin, fail to properly |
1718 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1749 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1719 | * the single unix specification, so work around them here. |
1750 | * the single unix specification, so work around them here. |
1720 | * recently, also (at least) fedora and debian started breaking it, |
1751 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1726 | |
1757 | |
1727 | free (ptr); |
1758 | free (ptr); |
1728 | return 0; |
1759 | return 0; |
1729 | } |
1760 | } |
1730 | |
1761 | |
1731 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1762 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1732 | |
1763 | |
1733 | ecb_cold |
1764 | ecb_cold |
1734 | void |
1765 | void |
1735 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1766 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1736 | { |
1767 | { |
1737 | alloc = cb; |
1768 | alloc = cb; |
1738 | } |
1769 | } |
1739 | |
1770 | |
1740 | inline_speed void * |
1771 | inline_speed void * |
… | |
… | |
1767 | typedef struct |
1798 | typedef struct |
1768 | { |
1799 | { |
1769 | WL head; |
1800 | WL head; |
1770 | unsigned char events; /* the events watched for */ |
1801 | unsigned char events; /* the events watched for */ |
1771 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1802 | 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 */ |
1803 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1773 | unsigned char unused; |
1804 | unsigned char unused; |
1774 | #if EV_USE_EPOLL |
1805 | #if EV_USE_EPOLL |
1775 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1806 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1776 | #endif |
1807 | #endif |
1777 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1808 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1857 | |
1888 | |
1858 | /*****************************************************************************/ |
1889 | /*****************************************************************************/ |
1859 | |
1890 | |
1860 | #ifndef EV_HAVE_EV_TIME |
1891 | #ifndef EV_HAVE_EV_TIME |
1861 | ev_tstamp |
1892 | ev_tstamp |
1862 | ev_time (void) EV_THROW |
1893 | ev_time (void) EV_NOEXCEPT |
1863 | { |
1894 | { |
1864 | #if EV_USE_REALTIME |
1895 | #if EV_USE_REALTIME |
1865 | if (expect_true (have_realtime)) |
1896 | if (expect_true (have_realtime)) |
1866 | { |
1897 | { |
1867 | struct timespec ts; |
1898 | struct timespec ts; |
… | |
… | |
1891 | return ev_time (); |
1922 | return ev_time (); |
1892 | } |
1923 | } |
1893 | |
1924 | |
1894 | #if EV_MULTIPLICITY |
1925 | #if EV_MULTIPLICITY |
1895 | ev_tstamp |
1926 | ev_tstamp |
1896 | ev_now (EV_P) EV_THROW |
1927 | ev_now (EV_P) EV_NOEXCEPT |
1897 | { |
1928 | { |
1898 | return ev_rt_now; |
1929 | return ev_rt_now; |
1899 | } |
1930 | } |
1900 | #endif |
1931 | #endif |
1901 | |
1932 | |
1902 | void |
1933 | void |
1903 | ev_sleep (ev_tstamp delay) EV_THROW |
1934 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1904 | { |
1935 | { |
1905 | if (delay > 0.) |
1936 | if (delay > 0.) |
1906 | { |
1937 | { |
1907 | #if EV_USE_NANOSLEEP |
1938 | #if EV_USE_NANOSLEEP |
1908 | struct timespec ts; |
1939 | struct timespec ts; |
… | |
… | |
1958 | { |
1989 | { |
1959 | *cur = array_nextsize (elem, *cur, cnt); |
1990 | *cur = array_nextsize (elem, *cur, cnt); |
1960 | return ev_realloc (base, elem * *cur); |
1991 | return ev_realloc (base, elem * *cur); |
1961 | } |
1992 | } |
1962 | |
1993 | |
|
|
1994 | #define array_needsize_noinit(base,count) |
|
|
1995 | |
1963 | #define array_init_zero(base,count) \ |
1996 | #define array_needsize_zerofill(base,count) \ |
1964 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1997 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1965 | |
1998 | |
1966 | #define array_needsize(type,base,cur,cnt,init) \ |
1999 | #define array_needsize(type,base,cur,cnt,init) \ |
1967 | if (expect_false ((cnt) > (cur))) \ |
2000 | if (expect_false ((cnt) > (cur))) \ |
1968 | { \ |
2001 | { \ |
… | |
… | |
1994 | { |
2027 | { |
1995 | } |
2028 | } |
1996 | |
2029 | |
1997 | noinline |
2030 | noinline |
1998 | void |
2031 | void |
1999 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2032 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2000 | { |
2033 | { |
2001 | W w_ = (W)w; |
2034 | W w_ = (W)w; |
2002 | int pri = ABSPRI (w_); |
2035 | int pri = ABSPRI (w_); |
2003 | |
2036 | |
2004 | if (expect_false (w_->pending)) |
2037 | if (expect_false (w_->pending)) |
2005 | pendings [pri][w_->pending - 1].events |= revents; |
2038 | pendings [pri][w_->pending - 1].events |= revents; |
2006 | else |
2039 | else |
2007 | { |
2040 | { |
2008 | w_->pending = ++pendingcnt [pri]; |
2041 | w_->pending = ++pendingcnt [pri]; |
2009 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2042 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2010 | pendings [pri][w_->pending - 1].w = w_; |
2043 | pendings [pri][w_->pending - 1].w = w_; |
2011 | pendings [pri][w_->pending - 1].events = revents; |
2044 | pendings [pri][w_->pending - 1].events = revents; |
2012 | } |
2045 | } |
2013 | |
2046 | |
2014 | pendingpri = NUMPRI - 1; |
2047 | pendingpri = NUMPRI - 1; |
2015 | } |
2048 | } |
2016 | |
2049 | |
2017 | inline_speed void |
2050 | inline_speed void |
2018 | feed_reverse (EV_P_ W w) |
2051 | feed_reverse (EV_P_ W w) |
2019 | { |
2052 | { |
2020 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2053 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2021 | rfeeds [rfeedcnt++] = w; |
2054 | rfeeds [rfeedcnt++] = w; |
2022 | } |
2055 | } |
2023 | |
2056 | |
2024 | inline_size void |
2057 | inline_size void |
2025 | feed_reverse_done (EV_P_ int revents) |
2058 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2065 | if (expect_true (!anfd->reify)) |
2098 | if (expect_true (!anfd->reify)) |
2066 | fd_event_nocheck (EV_A_ fd, revents); |
2099 | fd_event_nocheck (EV_A_ fd, revents); |
2067 | } |
2100 | } |
2068 | |
2101 | |
2069 | void |
2102 | void |
2070 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2103 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2071 | { |
2104 | { |
2072 | if (fd >= 0 && fd < anfdmax) |
2105 | if (fd >= 0 && fd < anfdmax) |
2073 | fd_event_nocheck (EV_A_ fd, revents); |
2106 | fd_event_nocheck (EV_A_ fd, revents); |
2074 | } |
2107 | } |
2075 | |
2108 | |
… | |
… | |
2143 | anfds [fd].reify |= flags; |
2176 | anfds [fd].reify |= flags; |
2144 | |
2177 | |
2145 | if (expect_true (!reify)) |
2178 | if (expect_true (!reify)) |
2146 | { |
2179 | { |
2147 | ++fdchangecnt; |
2180 | ++fdchangecnt; |
2148 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2181 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2149 | fdchanges [fdchangecnt - 1] = fd; |
2182 | fdchanges [fdchangecnt - 1] = fd; |
2150 | } |
2183 | } |
2151 | } |
2184 | } |
2152 | |
2185 | |
2153 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2186 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
… | |
… | |
2475 | #endif |
2508 | #endif |
2476 | { |
2509 | { |
2477 | #ifdef _WIN32 |
2510 | #ifdef _WIN32 |
2478 | WSABUF buf; |
2511 | WSABUF buf; |
2479 | DWORD sent; |
2512 | DWORD sent; |
2480 | buf.buf = &buf; |
2513 | buf.buf = (char *)&buf; |
2481 | buf.len = 1; |
2514 | buf.len = 1; |
2482 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2515 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2483 | #else |
2516 | #else |
2484 | write (evpipe [1], &(evpipe [1]), 1); |
2517 | write (evpipe [1], &(evpipe [1]), 1); |
2485 | #endif |
2518 | #endif |
… | |
… | |
2557 | } |
2590 | } |
2558 | |
2591 | |
2559 | /*****************************************************************************/ |
2592 | /*****************************************************************************/ |
2560 | |
2593 | |
2561 | void |
2594 | void |
2562 | ev_feed_signal (int signum) EV_THROW |
2595 | ev_feed_signal (int signum) EV_NOEXCEPT |
2563 | { |
2596 | { |
2564 | #if EV_MULTIPLICITY |
2597 | #if EV_MULTIPLICITY |
2565 | EV_P; |
2598 | EV_P; |
2566 | ECB_MEMORY_FENCE_ACQUIRE; |
2599 | ECB_MEMORY_FENCE_ACQUIRE; |
2567 | EV_A = signals [signum - 1].loop; |
2600 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2584 | ev_feed_signal (signum); |
2617 | ev_feed_signal (signum); |
2585 | } |
2618 | } |
2586 | |
2619 | |
2587 | noinline |
2620 | noinline |
2588 | void |
2621 | void |
2589 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2622 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2590 | { |
2623 | { |
2591 | WL w; |
2624 | WL w; |
2592 | |
2625 | |
2593 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2626 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2594 | return; |
2627 | return; |
… | |
… | |
2703 | # include "ev_kqueue.c" |
2736 | # include "ev_kqueue.c" |
2704 | #endif |
2737 | #endif |
2705 | #if EV_USE_EPOLL |
2738 | #if EV_USE_EPOLL |
2706 | # include "ev_epoll.c" |
2739 | # include "ev_epoll.c" |
2707 | #endif |
2740 | #endif |
|
|
2741 | #if EV_USE_LINUXAIO |
|
|
2742 | # include "ev_linuxaio.c" |
|
|
2743 | #endif |
2708 | #if EV_USE_POLL |
2744 | #if EV_USE_POLL |
2709 | # include "ev_poll.c" |
2745 | # include "ev_poll.c" |
2710 | #endif |
2746 | #endif |
2711 | #if EV_USE_SELECT |
2747 | #if EV_USE_SELECT |
2712 | # include "ev_select.c" |
2748 | # include "ev_select.c" |
2713 | #endif |
2749 | #endif |
2714 | |
2750 | |
2715 | ecb_cold int |
2751 | ecb_cold int |
2716 | ev_version_major (void) EV_THROW |
2752 | ev_version_major (void) EV_NOEXCEPT |
2717 | { |
2753 | { |
2718 | return EV_VERSION_MAJOR; |
2754 | return EV_VERSION_MAJOR; |
2719 | } |
2755 | } |
2720 | |
2756 | |
2721 | ecb_cold int |
2757 | ecb_cold int |
2722 | ev_version_minor (void) EV_THROW |
2758 | ev_version_minor (void) EV_NOEXCEPT |
2723 | { |
2759 | { |
2724 | return EV_VERSION_MINOR; |
2760 | return EV_VERSION_MINOR; |
2725 | } |
2761 | } |
2726 | |
2762 | |
2727 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2763 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2736 | #endif |
2772 | #endif |
2737 | } |
2773 | } |
2738 | |
2774 | |
2739 | ecb_cold |
2775 | ecb_cold |
2740 | unsigned int |
2776 | unsigned int |
2741 | ev_supported_backends (void) EV_THROW |
2777 | ev_supported_backends (void) EV_NOEXCEPT |
2742 | { |
2778 | { |
2743 | unsigned int flags = 0; |
2779 | unsigned int flags = 0; |
2744 | |
2780 | |
2745 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2781 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2746 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2782 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2747 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2783 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2784 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2748 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2785 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2749 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2786 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2750 | |
2787 | |
2751 | return flags; |
2788 | return flags; |
2752 | } |
2789 | } |
2753 | |
2790 | |
2754 | ecb_cold |
2791 | ecb_cold |
2755 | unsigned int |
2792 | unsigned int |
2756 | ev_recommended_backends (void) EV_THROW |
2793 | ev_recommended_backends (void) EV_NOEXCEPT |
2757 | { |
2794 | { |
2758 | unsigned int flags = ev_supported_backends (); |
2795 | unsigned int flags = ev_supported_backends (); |
2759 | |
2796 | |
2760 | #ifndef __NetBSD__ |
2797 | #ifndef __NetBSD__ |
2761 | /* kqueue is borked on everything but netbsd apparently */ |
2798 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2769 | #endif |
2806 | #endif |
2770 | #ifdef __FreeBSD__ |
2807 | #ifdef __FreeBSD__ |
2771 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2808 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2772 | #endif |
2809 | #endif |
2773 | |
2810 | |
|
|
2811 | /* TODO: linuxaio is very experimental */ |
|
|
2812 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2813 | |
2774 | return flags; |
2814 | return flags; |
2775 | } |
2815 | } |
2776 | |
2816 | |
2777 | ecb_cold |
2817 | ecb_cold |
2778 | unsigned int |
2818 | unsigned int |
2779 | ev_embeddable_backends (void) EV_THROW |
2819 | ev_embeddable_backends (void) EV_NOEXCEPT |
2780 | { |
2820 | { |
2781 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2821 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2782 | |
2822 | |
2783 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2823 | /* 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 */ |
2824 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2786 | |
2826 | |
2787 | return flags; |
2827 | return flags; |
2788 | } |
2828 | } |
2789 | |
2829 | |
2790 | unsigned int |
2830 | unsigned int |
2791 | ev_backend (EV_P) EV_THROW |
2831 | ev_backend (EV_P) EV_NOEXCEPT |
2792 | { |
2832 | { |
2793 | return backend; |
2833 | return backend; |
2794 | } |
2834 | } |
2795 | |
2835 | |
2796 | #if EV_FEATURE_API |
2836 | #if EV_FEATURE_API |
2797 | unsigned int |
2837 | unsigned int |
2798 | ev_iteration (EV_P) EV_THROW |
2838 | ev_iteration (EV_P) EV_NOEXCEPT |
2799 | { |
2839 | { |
2800 | return loop_count; |
2840 | return loop_count; |
2801 | } |
2841 | } |
2802 | |
2842 | |
2803 | unsigned int |
2843 | unsigned int |
2804 | ev_depth (EV_P) EV_THROW |
2844 | ev_depth (EV_P) EV_NOEXCEPT |
2805 | { |
2845 | { |
2806 | return loop_depth; |
2846 | return loop_depth; |
2807 | } |
2847 | } |
2808 | |
2848 | |
2809 | void |
2849 | void |
2810 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2850 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2811 | { |
2851 | { |
2812 | io_blocktime = interval; |
2852 | io_blocktime = interval; |
2813 | } |
2853 | } |
2814 | |
2854 | |
2815 | void |
2855 | void |
2816 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2856 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2817 | { |
2857 | { |
2818 | timeout_blocktime = interval; |
2858 | timeout_blocktime = interval; |
2819 | } |
2859 | } |
2820 | |
2860 | |
2821 | void |
2861 | void |
2822 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2862 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2823 | { |
2863 | { |
2824 | userdata = data; |
2864 | userdata = data; |
2825 | } |
2865 | } |
2826 | |
2866 | |
2827 | void * |
2867 | void * |
2828 | ev_userdata (EV_P) EV_THROW |
2868 | ev_userdata (EV_P) EV_NOEXCEPT |
2829 | { |
2869 | { |
2830 | return userdata; |
2870 | return userdata; |
2831 | } |
2871 | } |
2832 | |
2872 | |
2833 | void |
2873 | void |
2834 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
2874 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2835 | { |
2875 | { |
2836 | invoke_cb = invoke_pending_cb; |
2876 | invoke_cb = invoke_pending_cb; |
2837 | } |
2877 | } |
2838 | |
2878 | |
2839 | void |
2879 | void |
2840 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2880 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2841 | { |
2881 | { |
2842 | release_cb = release; |
2882 | release_cb = release; |
2843 | acquire_cb = acquire; |
2883 | acquire_cb = acquire; |
2844 | } |
2884 | } |
2845 | #endif |
2885 | #endif |
2846 | |
2886 | |
2847 | /* initialise a loop structure, must be zero-initialised */ |
2887 | /* initialise a loop structure, must be zero-initialised */ |
2848 | noinline ecb_cold |
2888 | noinline ecb_cold |
2849 | static void |
2889 | static void |
2850 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2890 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2851 | { |
2891 | { |
2852 | if (!backend) |
2892 | if (!backend) |
2853 | { |
2893 | { |
2854 | origflags = flags; |
2894 | origflags = flags; |
2855 | |
2895 | |
… | |
… | |
2913 | |
2953 | |
2914 | if (!(flags & EVBACKEND_MASK)) |
2954 | if (!(flags & EVBACKEND_MASK)) |
2915 | flags |= ev_recommended_backends (); |
2955 | flags |= ev_recommended_backends (); |
2916 | |
2956 | |
2917 | #if EV_USE_IOCP |
2957 | #if EV_USE_IOCP |
2918 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2958 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2919 | #endif |
2959 | #endif |
2920 | #if EV_USE_PORT |
2960 | #if EV_USE_PORT |
2921 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2961 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2922 | #endif |
2962 | #endif |
2923 | #if EV_USE_KQUEUE |
2963 | #if EV_USE_KQUEUE |
2924 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
2964 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
|
|
2965 | #endif |
|
|
2966 | #if EV_USE_LINUXAIO |
|
|
2967 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2925 | #endif |
2968 | #endif |
2926 | #if EV_USE_EPOLL |
2969 | #if EV_USE_EPOLL |
2927 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2970 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2928 | #endif |
2971 | #endif |
2929 | #if EV_USE_POLL |
2972 | #if EV_USE_POLL |
2930 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2973 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2931 | #endif |
2974 | #endif |
2932 | #if EV_USE_SELECT |
2975 | #if EV_USE_SELECT |
2933 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2976 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2934 | #endif |
2977 | #endif |
2935 | |
2978 | |
2936 | ev_prepare_init (&pending_w, pendingcb); |
2979 | ev_prepare_init (&pending_w, pendingcb); |
2937 | |
2980 | |
2938 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2981 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2993 | |
3036 | |
2994 | if (backend_fd >= 0) |
3037 | if (backend_fd >= 0) |
2995 | close (backend_fd); |
3038 | close (backend_fd); |
2996 | |
3039 | |
2997 | #if EV_USE_IOCP |
3040 | #if EV_USE_IOCP |
2998 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3041 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2999 | #endif |
3042 | #endif |
3000 | #if EV_USE_PORT |
3043 | #if EV_USE_PORT |
3001 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3044 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3002 | #endif |
3045 | #endif |
3003 | #if EV_USE_KQUEUE |
3046 | #if EV_USE_KQUEUE |
3004 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
3047 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3048 | #endif |
|
|
3049 | #if EV_USE_LINUXAIO |
|
|
3050 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3005 | #endif |
3051 | #endif |
3006 | #if EV_USE_EPOLL |
3052 | #if EV_USE_EPOLL |
3007 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3053 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3008 | #endif |
3054 | #endif |
3009 | #if EV_USE_POLL |
3055 | #if EV_USE_POLL |
3010 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3056 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3011 | #endif |
3057 | #endif |
3012 | #if EV_USE_SELECT |
3058 | #if EV_USE_SELECT |
3013 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3059 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3014 | #endif |
3060 | #endif |
3015 | |
3061 | |
3016 | for (i = NUMPRI; i--; ) |
3062 | for (i = NUMPRI; i--; ) |
3017 | { |
3063 | { |
3018 | array_free (pending, [i]); |
3064 | array_free (pending, [i]); |
… | |
… | |
3060 | |
3106 | |
3061 | inline_size void |
3107 | inline_size void |
3062 | loop_fork (EV_P) |
3108 | loop_fork (EV_P) |
3063 | { |
3109 | { |
3064 | #if EV_USE_PORT |
3110 | #if EV_USE_PORT |
3065 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3111 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3066 | #endif |
3112 | #endif |
3067 | #if EV_USE_KQUEUE |
3113 | #if EV_USE_KQUEUE |
3068 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
3114 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3115 | #endif |
|
|
3116 | #if EV_USE_LINUXAIO |
|
|
3117 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3069 | #endif |
3118 | #endif |
3070 | #if EV_USE_EPOLL |
3119 | #if EV_USE_EPOLL |
3071 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3120 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3072 | #endif |
3121 | #endif |
3073 | #if EV_USE_INOTIFY |
3122 | #if EV_USE_INOTIFY |
3074 | infy_fork (EV_A); |
3123 | infy_fork (EV_A); |
3075 | #endif |
3124 | #endif |
3076 | |
3125 | |
… | |
… | |
3096 | |
3145 | |
3097 | #if EV_MULTIPLICITY |
3146 | #if EV_MULTIPLICITY |
3098 | |
3147 | |
3099 | ecb_cold |
3148 | ecb_cold |
3100 | struct ev_loop * |
3149 | struct ev_loop * |
3101 | ev_loop_new (unsigned int flags) EV_THROW |
3150 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3102 | { |
3151 | { |
3103 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3152 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3104 | |
3153 | |
3105 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3154 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3106 | loop_init (EV_A_ flags); |
3155 | loop_init (EV_A_ flags); |
… | |
… | |
3153 | } |
3202 | } |
3154 | #endif |
3203 | #endif |
3155 | |
3204 | |
3156 | #if EV_FEATURE_API |
3205 | #if EV_FEATURE_API |
3157 | void ecb_cold |
3206 | void ecb_cold |
3158 | ev_verify (EV_P) EV_THROW |
3207 | ev_verify (EV_P) EV_NOEXCEPT |
3159 | { |
3208 | { |
3160 | #if EV_VERIFY |
3209 | #if EV_VERIFY |
3161 | int i; |
3210 | int i; |
3162 | WL w, w2; |
3211 | WL w, w2; |
3163 | |
3212 | |
… | |
… | |
3244 | ecb_cold |
3293 | ecb_cold |
3245 | struct ev_loop * |
3294 | struct ev_loop * |
3246 | #else |
3295 | #else |
3247 | int |
3296 | int |
3248 | #endif |
3297 | #endif |
3249 | ev_default_loop (unsigned int flags) EV_THROW |
3298 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3250 | { |
3299 | { |
3251 | if (!ev_default_loop_ptr) |
3300 | if (!ev_default_loop_ptr) |
3252 | { |
3301 | { |
3253 | #if EV_MULTIPLICITY |
3302 | #if EV_MULTIPLICITY |
3254 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3303 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3273 | |
3322 | |
3274 | return ev_default_loop_ptr; |
3323 | return ev_default_loop_ptr; |
3275 | } |
3324 | } |
3276 | |
3325 | |
3277 | void |
3326 | void |
3278 | ev_loop_fork (EV_P) EV_THROW |
3327 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3279 | { |
3328 | { |
3280 | postfork = 1; |
3329 | postfork = 1; |
3281 | } |
3330 | } |
3282 | |
3331 | |
3283 | /*****************************************************************************/ |
3332 | /*****************************************************************************/ |
… | |
… | |
3287 | { |
3336 | { |
3288 | EV_CB_INVOKE ((W)w, revents); |
3337 | EV_CB_INVOKE ((W)w, revents); |
3289 | } |
3338 | } |
3290 | |
3339 | |
3291 | unsigned int |
3340 | unsigned int |
3292 | ev_pending_count (EV_P) EV_THROW |
3341 | ev_pending_count (EV_P) EV_NOEXCEPT |
3293 | { |
3342 | { |
3294 | int pri; |
3343 | int pri; |
3295 | unsigned int count = 0; |
3344 | unsigned int count = 0; |
3296 | |
3345 | |
3297 | for (pri = NUMPRI; pri--; ) |
3346 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3304 | void |
3353 | void |
3305 | ev_invoke_pending (EV_P) |
3354 | ev_invoke_pending (EV_P) |
3306 | { |
3355 | { |
3307 | pendingpri = NUMPRI; |
3356 | pendingpri = NUMPRI; |
3308 | |
3357 | |
3309 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3358 | do |
3310 | { |
3359 | { |
3311 | --pendingpri; |
3360 | --pendingpri; |
3312 | |
3361 | |
|
|
3362 | /* pendingpri possibly gets modified in the inner loop */ |
3313 | while (pendingcnt [pendingpri]) |
3363 | while (pendingcnt [pendingpri]) |
3314 | { |
3364 | { |
3315 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3365 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3316 | |
3366 | |
3317 | p->w->pending = 0; |
3367 | p->w->pending = 0; |
3318 | EV_CB_INVOKE (p->w, p->events); |
3368 | EV_CB_INVOKE (p->w, p->events); |
3319 | EV_FREQUENT_CHECK; |
3369 | EV_FREQUENT_CHECK; |
3320 | } |
3370 | } |
3321 | } |
3371 | } |
|
|
3372 | while (pendingpri); |
3322 | } |
3373 | } |
3323 | |
3374 | |
3324 | #if EV_IDLE_ENABLE |
3375 | #if EV_IDLE_ENABLE |
3325 | /* make idle watchers pending. this handles the "call-idle */ |
3376 | /* make idle watchers pending. this handles the "call-idle */ |
3326 | /* only when higher priorities are idle" logic */ |
3377 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3735 | |
3786 | |
3736 | return activecnt; |
3787 | return activecnt; |
3737 | } |
3788 | } |
3738 | |
3789 | |
3739 | void |
3790 | void |
3740 | ev_break (EV_P_ int how) EV_THROW |
3791 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3741 | { |
3792 | { |
3742 | loop_done = how; |
3793 | loop_done = how; |
3743 | } |
3794 | } |
3744 | |
3795 | |
3745 | void |
3796 | void |
3746 | ev_ref (EV_P) EV_THROW |
3797 | ev_ref (EV_P) EV_NOEXCEPT |
3747 | { |
3798 | { |
3748 | ++activecnt; |
3799 | ++activecnt; |
3749 | } |
3800 | } |
3750 | |
3801 | |
3751 | void |
3802 | void |
3752 | ev_unref (EV_P) EV_THROW |
3803 | ev_unref (EV_P) EV_NOEXCEPT |
3753 | { |
3804 | { |
3754 | --activecnt; |
3805 | --activecnt; |
3755 | } |
3806 | } |
3756 | |
3807 | |
3757 | void |
3808 | void |
3758 | ev_now_update (EV_P) EV_THROW |
3809 | ev_now_update (EV_P) EV_NOEXCEPT |
3759 | { |
3810 | { |
3760 | time_update (EV_A_ 1e100); |
3811 | time_update (EV_A_ 1e100); |
3761 | } |
3812 | } |
3762 | |
3813 | |
3763 | void |
3814 | void |
3764 | ev_suspend (EV_P) EV_THROW |
3815 | ev_suspend (EV_P) EV_NOEXCEPT |
3765 | { |
3816 | { |
3766 | ev_now_update (EV_A); |
3817 | ev_now_update (EV_A); |
3767 | } |
3818 | } |
3768 | |
3819 | |
3769 | void |
3820 | void |
3770 | ev_resume (EV_P) EV_THROW |
3821 | ev_resume (EV_P) EV_NOEXCEPT |
3771 | { |
3822 | { |
3772 | ev_tstamp mn_prev = mn_now; |
3823 | ev_tstamp mn_prev = mn_now; |
3773 | |
3824 | |
3774 | ev_now_update (EV_A); |
3825 | ev_now_update (EV_A); |
3775 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3826 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3814 | w->pending = 0; |
3865 | w->pending = 0; |
3815 | } |
3866 | } |
3816 | } |
3867 | } |
3817 | |
3868 | |
3818 | int |
3869 | int |
3819 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3870 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3820 | { |
3871 | { |
3821 | W w_ = (W)w; |
3872 | W w_ = (W)w; |
3822 | int pending = w_->pending; |
3873 | int pending = w_->pending; |
3823 | |
3874 | |
3824 | if (expect_true (pending)) |
3875 | if (expect_true (pending)) |
… | |
… | |
3858 | |
3909 | |
3859 | /*****************************************************************************/ |
3910 | /*****************************************************************************/ |
3860 | |
3911 | |
3861 | noinline |
3912 | noinline |
3862 | void |
3913 | void |
3863 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3914 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3864 | { |
3915 | { |
3865 | int fd = w->fd; |
3916 | int fd = w->fd; |
3866 | |
3917 | |
3867 | if (expect_false (ev_is_active (w))) |
3918 | if (expect_false (ev_is_active (w))) |
3868 | return; |
3919 | return; |
… | |
… | |
3871 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3922 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3872 | |
3923 | |
3873 | EV_FREQUENT_CHECK; |
3924 | EV_FREQUENT_CHECK; |
3874 | |
3925 | |
3875 | ev_start (EV_A_ (W)w, 1); |
3926 | ev_start (EV_A_ (W)w, 1); |
3876 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3927 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3877 | wlist_add (&anfds[fd].head, (WL)w); |
3928 | wlist_add (&anfds[fd].head, (WL)w); |
3878 | |
3929 | |
3879 | /* common bug, apparently */ |
3930 | /* common bug, apparently */ |
3880 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3931 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3881 | |
3932 | |
… | |
… | |
3885 | EV_FREQUENT_CHECK; |
3936 | EV_FREQUENT_CHECK; |
3886 | } |
3937 | } |
3887 | |
3938 | |
3888 | noinline |
3939 | noinline |
3889 | void |
3940 | void |
3890 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3941 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3891 | { |
3942 | { |
3892 | clear_pending (EV_A_ (W)w); |
3943 | clear_pending (EV_A_ (W)w); |
3893 | if (expect_false (!ev_is_active (w))) |
3944 | if (expect_false (!ev_is_active (w))) |
3894 | return; |
3945 | return; |
3895 | |
3946 | |
… | |
… | |
3905 | EV_FREQUENT_CHECK; |
3956 | EV_FREQUENT_CHECK; |
3906 | } |
3957 | } |
3907 | |
3958 | |
3908 | noinline |
3959 | noinline |
3909 | void |
3960 | void |
3910 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3961 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3911 | { |
3962 | { |
3912 | if (expect_false (ev_is_active (w))) |
3963 | if (expect_false (ev_is_active (w))) |
3913 | return; |
3964 | return; |
3914 | |
3965 | |
3915 | ev_at (w) += mn_now; |
3966 | ev_at (w) += mn_now; |
… | |
… | |
3918 | |
3969 | |
3919 | EV_FREQUENT_CHECK; |
3970 | EV_FREQUENT_CHECK; |
3920 | |
3971 | |
3921 | ++timercnt; |
3972 | ++timercnt; |
3922 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3973 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3923 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3974 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3924 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3975 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3925 | ANHE_at_cache (timers [ev_active (w)]); |
3976 | ANHE_at_cache (timers [ev_active (w)]); |
3926 | upheap (timers, ev_active (w)); |
3977 | upheap (timers, ev_active (w)); |
3927 | |
3978 | |
3928 | EV_FREQUENT_CHECK; |
3979 | EV_FREQUENT_CHECK; |
… | |
… | |
3930 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3981 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3931 | } |
3982 | } |
3932 | |
3983 | |
3933 | noinline |
3984 | noinline |
3934 | void |
3985 | void |
3935 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3986 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3936 | { |
3987 | { |
3937 | clear_pending (EV_A_ (W)w); |
3988 | clear_pending (EV_A_ (W)w); |
3938 | if (expect_false (!ev_is_active (w))) |
3989 | if (expect_false (!ev_is_active (w))) |
3939 | return; |
3990 | return; |
3940 | |
3991 | |
… | |
… | |
3961 | EV_FREQUENT_CHECK; |
4012 | EV_FREQUENT_CHECK; |
3962 | } |
4013 | } |
3963 | |
4014 | |
3964 | noinline |
4015 | noinline |
3965 | void |
4016 | void |
3966 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4017 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3967 | { |
4018 | { |
3968 | EV_FREQUENT_CHECK; |
4019 | EV_FREQUENT_CHECK; |
3969 | |
4020 | |
3970 | clear_pending (EV_A_ (W)w); |
4021 | clear_pending (EV_A_ (W)w); |
3971 | |
4022 | |
… | |
… | |
3988 | |
4039 | |
3989 | EV_FREQUENT_CHECK; |
4040 | EV_FREQUENT_CHECK; |
3990 | } |
4041 | } |
3991 | |
4042 | |
3992 | ev_tstamp |
4043 | ev_tstamp |
3993 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4044 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3994 | { |
4045 | { |
3995 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4046 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3996 | } |
4047 | } |
3997 | |
4048 | |
3998 | #if EV_PERIODIC_ENABLE |
4049 | #if EV_PERIODIC_ENABLE |
3999 | noinline |
4050 | noinline |
4000 | void |
4051 | void |
4001 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4052 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4002 | { |
4053 | { |
4003 | if (expect_false (ev_is_active (w))) |
4054 | if (expect_false (ev_is_active (w))) |
4004 | return; |
4055 | return; |
4005 | |
4056 | |
4006 | if (w->reschedule_cb) |
4057 | if (w->reschedule_cb) |
… | |
… | |
4015 | |
4066 | |
4016 | EV_FREQUENT_CHECK; |
4067 | EV_FREQUENT_CHECK; |
4017 | |
4068 | |
4018 | ++periodiccnt; |
4069 | ++periodiccnt; |
4019 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4070 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4020 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4071 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4021 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4072 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4022 | ANHE_at_cache (periodics [ev_active (w)]); |
4073 | ANHE_at_cache (periodics [ev_active (w)]); |
4023 | upheap (periodics, ev_active (w)); |
4074 | upheap (periodics, ev_active (w)); |
4024 | |
4075 | |
4025 | EV_FREQUENT_CHECK; |
4076 | EV_FREQUENT_CHECK; |
… | |
… | |
4027 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4078 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4028 | } |
4079 | } |
4029 | |
4080 | |
4030 | noinline |
4081 | noinline |
4031 | void |
4082 | void |
4032 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4083 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4033 | { |
4084 | { |
4034 | clear_pending (EV_A_ (W)w); |
4085 | clear_pending (EV_A_ (W)w); |
4035 | if (expect_false (!ev_is_active (w))) |
4086 | if (expect_false (!ev_is_active (w))) |
4036 | return; |
4087 | return; |
4037 | |
4088 | |
… | |
… | |
4056 | EV_FREQUENT_CHECK; |
4107 | EV_FREQUENT_CHECK; |
4057 | } |
4108 | } |
4058 | |
4109 | |
4059 | noinline |
4110 | noinline |
4060 | void |
4111 | void |
4061 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4112 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4062 | { |
4113 | { |
4063 | /* TODO: use adjustheap and recalculation */ |
4114 | /* TODO: use adjustheap and recalculation */ |
4064 | ev_periodic_stop (EV_A_ w); |
4115 | ev_periodic_stop (EV_A_ w); |
4065 | ev_periodic_start (EV_A_ w); |
4116 | ev_periodic_start (EV_A_ w); |
4066 | } |
4117 | } |
… | |
… | |
4072 | |
4123 | |
4073 | #if EV_SIGNAL_ENABLE |
4124 | #if EV_SIGNAL_ENABLE |
4074 | |
4125 | |
4075 | noinline |
4126 | noinline |
4076 | void |
4127 | void |
4077 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4128 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4078 | { |
4129 | { |
4079 | if (expect_false (ev_is_active (w))) |
4130 | if (expect_false (ev_is_active (w))) |
4080 | return; |
4131 | return; |
4081 | |
4132 | |
4082 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4133 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4155 | EV_FREQUENT_CHECK; |
4206 | EV_FREQUENT_CHECK; |
4156 | } |
4207 | } |
4157 | |
4208 | |
4158 | noinline |
4209 | noinline |
4159 | void |
4210 | void |
4160 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4211 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4161 | { |
4212 | { |
4162 | clear_pending (EV_A_ (W)w); |
4213 | clear_pending (EV_A_ (W)w); |
4163 | if (expect_false (!ev_is_active (w))) |
4214 | if (expect_false (!ev_is_active (w))) |
4164 | return; |
4215 | return; |
4165 | |
4216 | |
… | |
… | |
4196 | #endif |
4247 | #endif |
4197 | |
4248 | |
4198 | #if EV_CHILD_ENABLE |
4249 | #if EV_CHILD_ENABLE |
4199 | |
4250 | |
4200 | void |
4251 | void |
4201 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4252 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4202 | { |
4253 | { |
4203 | #if EV_MULTIPLICITY |
4254 | #if EV_MULTIPLICITY |
4204 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4255 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4205 | #endif |
4256 | #endif |
4206 | if (expect_false (ev_is_active (w))) |
4257 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4213 | |
4264 | |
4214 | EV_FREQUENT_CHECK; |
4265 | EV_FREQUENT_CHECK; |
4215 | } |
4266 | } |
4216 | |
4267 | |
4217 | void |
4268 | void |
4218 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4269 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4219 | { |
4270 | { |
4220 | clear_pending (EV_A_ (W)w); |
4271 | clear_pending (EV_A_ (W)w); |
4221 | if (expect_false (!ev_is_active (w))) |
4272 | if (expect_false (!ev_is_active (w))) |
4222 | return; |
4273 | return; |
4223 | |
4274 | |
… | |
… | |
4488 | #else |
4539 | #else |
4489 | # define EV_LSTAT(p,b) lstat (p, b) |
4540 | # define EV_LSTAT(p,b) lstat (p, b) |
4490 | #endif |
4541 | #endif |
4491 | |
4542 | |
4492 | void |
4543 | void |
4493 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4544 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4494 | { |
4545 | { |
4495 | if (lstat (w->path, &w->attr) < 0) |
4546 | if (lstat (w->path, &w->attr) < 0) |
4496 | w->attr.st_nlink = 0; |
4547 | w->attr.st_nlink = 0; |
4497 | else if (!w->attr.st_nlink) |
4548 | else if (!w->attr.st_nlink) |
4498 | w->attr.st_nlink = 1; |
4549 | w->attr.st_nlink = 1; |
… | |
… | |
4538 | ev_feed_event (EV_A_ w, EV_STAT); |
4589 | ev_feed_event (EV_A_ w, EV_STAT); |
4539 | } |
4590 | } |
4540 | } |
4591 | } |
4541 | |
4592 | |
4542 | void |
4593 | void |
4543 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4594 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4544 | { |
4595 | { |
4545 | if (expect_false (ev_is_active (w))) |
4596 | if (expect_false (ev_is_active (w))) |
4546 | return; |
4597 | return; |
4547 | |
4598 | |
4548 | ev_stat_stat (EV_A_ w); |
4599 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4569 | |
4620 | |
4570 | EV_FREQUENT_CHECK; |
4621 | EV_FREQUENT_CHECK; |
4571 | } |
4622 | } |
4572 | |
4623 | |
4573 | void |
4624 | void |
4574 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4625 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4575 | { |
4626 | { |
4576 | clear_pending (EV_A_ (W)w); |
4627 | clear_pending (EV_A_ (W)w); |
4577 | if (expect_false (!ev_is_active (w))) |
4628 | if (expect_false (!ev_is_active (w))) |
4578 | return; |
4629 | return; |
4579 | |
4630 | |
… | |
… | |
4595 | } |
4646 | } |
4596 | #endif |
4647 | #endif |
4597 | |
4648 | |
4598 | #if EV_IDLE_ENABLE |
4649 | #if EV_IDLE_ENABLE |
4599 | void |
4650 | void |
4600 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4651 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4601 | { |
4652 | { |
4602 | if (expect_false (ev_is_active (w))) |
4653 | if (expect_false (ev_is_active (w))) |
4603 | return; |
4654 | return; |
4604 | |
4655 | |
4605 | pri_adjust (EV_A_ (W)w); |
4656 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4610 | int active = ++idlecnt [ABSPRI (w)]; |
4661 | int active = ++idlecnt [ABSPRI (w)]; |
4611 | |
4662 | |
4612 | ++idleall; |
4663 | ++idleall; |
4613 | ev_start (EV_A_ (W)w, active); |
4664 | ev_start (EV_A_ (W)w, active); |
4614 | |
4665 | |
4615 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4666 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4616 | idles [ABSPRI (w)][active - 1] = w; |
4667 | idles [ABSPRI (w)][active - 1] = w; |
4617 | } |
4668 | } |
4618 | |
4669 | |
4619 | EV_FREQUENT_CHECK; |
4670 | EV_FREQUENT_CHECK; |
4620 | } |
4671 | } |
4621 | |
4672 | |
4622 | void |
4673 | void |
4623 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4674 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4624 | { |
4675 | { |
4625 | clear_pending (EV_A_ (W)w); |
4676 | clear_pending (EV_A_ (W)w); |
4626 | if (expect_false (!ev_is_active (w))) |
4677 | if (expect_false (!ev_is_active (w))) |
4627 | return; |
4678 | return; |
4628 | |
4679 | |
… | |
… | |
4642 | } |
4693 | } |
4643 | #endif |
4694 | #endif |
4644 | |
4695 | |
4645 | #if EV_PREPARE_ENABLE |
4696 | #if EV_PREPARE_ENABLE |
4646 | void |
4697 | void |
4647 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4698 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4648 | { |
4699 | { |
4649 | if (expect_false (ev_is_active (w))) |
4700 | if (expect_false (ev_is_active (w))) |
4650 | return; |
4701 | return; |
4651 | |
4702 | |
4652 | EV_FREQUENT_CHECK; |
4703 | EV_FREQUENT_CHECK; |
4653 | |
4704 | |
4654 | ev_start (EV_A_ (W)w, ++preparecnt); |
4705 | ev_start (EV_A_ (W)w, ++preparecnt); |
4655 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4706 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4656 | prepares [preparecnt - 1] = w; |
4707 | prepares [preparecnt - 1] = w; |
4657 | |
4708 | |
4658 | EV_FREQUENT_CHECK; |
4709 | EV_FREQUENT_CHECK; |
4659 | } |
4710 | } |
4660 | |
4711 | |
4661 | void |
4712 | void |
4662 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4713 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4663 | { |
4714 | { |
4664 | clear_pending (EV_A_ (W)w); |
4715 | clear_pending (EV_A_ (W)w); |
4665 | if (expect_false (!ev_is_active (w))) |
4716 | if (expect_false (!ev_is_active (w))) |
4666 | return; |
4717 | return; |
4667 | |
4718 | |
… | |
… | |
4680 | } |
4731 | } |
4681 | #endif |
4732 | #endif |
4682 | |
4733 | |
4683 | #if EV_CHECK_ENABLE |
4734 | #if EV_CHECK_ENABLE |
4684 | void |
4735 | void |
4685 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4736 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4686 | { |
4737 | { |
4687 | if (expect_false (ev_is_active (w))) |
4738 | if (expect_false (ev_is_active (w))) |
4688 | return; |
4739 | return; |
4689 | |
4740 | |
4690 | EV_FREQUENT_CHECK; |
4741 | EV_FREQUENT_CHECK; |
4691 | |
4742 | |
4692 | ev_start (EV_A_ (W)w, ++checkcnt); |
4743 | ev_start (EV_A_ (W)w, ++checkcnt); |
4693 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4744 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4694 | checks [checkcnt - 1] = w; |
4745 | checks [checkcnt - 1] = w; |
4695 | |
4746 | |
4696 | EV_FREQUENT_CHECK; |
4747 | EV_FREQUENT_CHECK; |
4697 | } |
4748 | } |
4698 | |
4749 | |
4699 | void |
4750 | void |
4700 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4751 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4701 | { |
4752 | { |
4702 | clear_pending (EV_A_ (W)w); |
4753 | clear_pending (EV_A_ (W)w); |
4703 | if (expect_false (!ev_is_active (w))) |
4754 | if (expect_false (!ev_is_active (w))) |
4704 | return; |
4755 | return; |
4705 | |
4756 | |
… | |
… | |
4719 | #endif |
4770 | #endif |
4720 | |
4771 | |
4721 | #if EV_EMBED_ENABLE |
4772 | #if EV_EMBED_ENABLE |
4722 | noinline |
4773 | noinline |
4723 | void |
4774 | void |
4724 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4775 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4725 | { |
4776 | { |
4726 | ev_run (w->other, EVRUN_NOWAIT); |
4777 | ev_run (w->other, EVRUN_NOWAIT); |
4727 | } |
4778 | } |
4728 | |
4779 | |
4729 | static void |
4780 | static void |
… | |
… | |
4777 | ev_idle_stop (EV_A_ idle); |
4828 | ev_idle_stop (EV_A_ idle); |
4778 | } |
4829 | } |
4779 | #endif |
4830 | #endif |
4780 | |
4831 | |
4781 | void |
4832 | void |
4782 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4833 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4783 | { |
4834 | { |
4784 | if (expect_false (ev_is_active (w))) |
4835 | if (expect_false (ev_is_active (w))) |
4785 | return; |
4836 | return; |
4786 | |
4837 | |
4787 | { |
4838 | { |
… | |
… | |
4808 | |
4859 | |
4809 | EV_FREQUENT_CHECK; |
4860 | EV_FREQUENT_CHECK; |
4810 | } |
4861 | } |
4811 | |
4862 | |
4812 | void |
4863 | void |
4813 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4864 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4814 | { |
4865 | { |
4815 | clear_pending (EV_A_ (W)w); |
4866 | clear_pending (EV_A_ (W)w); |
4816 | if (expect_false (!ev_is_active (w))) |
4867 | if (expect_false (!ev_is_active (w))) |
4817 | return; |
4868 | return; |
4818 | |
4869 | |
… | |
… | |
4828 | } |
4879 | } |
4829 | #endif |
4880 | #endif |
4830 | |
4881 | |
4831 | #if EV_FORK_ENABLE |
4882 | #if EV_FORK_ENABLE |
4832 | void |
4883 | void |
4833 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4884 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4834 | { |
4885 | { |
4835 | if (expect_false (ev_is_active (w))) |
4886 | if (expect_false (ev_is_active (w))) |
4836 | return; |
4887 | return; |
4837 | |
4888 | |
4838 | EV_FREQUENT_CHECK; |
4889 | EV_FREQUENT_CHECK; |
4839 | |
4890 | |
4840 | ev_start (EV_A_ (W)w, ++forkcnt); |
4891 | ev_start (EV_A_ (W)w, ++forkcnt); |
4841 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4892 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4842 | forks [forkcnt - 1] = w; |
4893 | forks [forkcnt - 1] = w; |
4843 | |
4894 | |
4844 | EV_FREQUENT_CHECK; |
4895 | EV_FREQUENT_CHECK; |
4845 | } |
4896 | } |
4846 | |
4897 | |
4847 | void |
4898 | void |
4848 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4899 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4849 | { |
4900 | { |
4850 | clear_pending (EV_A_ (W)w); |
4901 | clear_pending (EV_A_ (W)w); |
4851 | if (expect_false (!ev_is_active (w))) |
4902 | if (expect_false (!ev_is_active (w))) |
4852 | return; |
4903 | return; |
4853 | |
4904 | |
… | |
… | |
4866 | } |
4917 | } |
4867 | #endif |
4918 | #endif |
4868 | |
4919 | |
4869 | #if EV_CLEANUP_ENABLE |
4920 | #if EV_CLEANUP_ENABLE |
4870 | void |
4921 | void |
4871 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4922 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4872 | { |
4923 | { |
4873 | if (expect_false (ev_is_active (w))) |
4924 | if (expect_false (ev_is_active (w))) |
4874 | return; |
4925 | return; |
4875 | |
4926 | |
4876 | EV_FREQUENT_CHECK; |
4927 | EV_FREQUENT_CHECK; |
4877 | |
4928 | |
4878 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4929 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4879 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4930 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4880 | cleanups [cleanupcnt - 1] = w; |
4931 | cleanups [cleanupcnt - 1] = w; |
4881 | |
4932 | |
4882 | /* cleanup watchers should never keep a refcount on the loop */ |
4933 | /* cleanup watchers should never keep a refcount on the loop */ |
4883 | ev_unref (EV_A); |
4934 | ev_unref (EV_A); |
4884 | EV_FREQUENT_CHECK; |
4935 | EV_FREQUENT_CHECK; |
4885 | } |
4936 | } |
4886 | |
4937 | |
4887 | void |
4938 | void |
4888 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4939 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4889 | { |
4940 | { |
4890 | clear_pending (EV_A_ (W)w); |
4941 | clear_pending (EV_A_ (W)w); |
4891 | if (expect_false (!ev_is_active (w))) |
4942 | if (expect_false (!ev_is_active (w))) |
4892 | return; |
4943 | return; |
4893 | |
4944 | |
… | |
… | |
4907 | } |
4958 | } |
4908 | #endif |
4959 | #endif |
4909 | |
4960 | |
4910 | #if EV_ASYNC_ENABLE |
4961 | #if EV_ASYNC_ENABLE |
4911 | void |
4962 | void |
4912 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4963 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4913 | { |
4964 | { |
4914 | if (expect_false (ev_is_active (w))) |
4965 | if (expect_false (ev_is_active (w))) |
4915 | return; |
4966 | return; |
4916 | |
4967 | |
4917 | w->sent = 0; |
4968 | w->sent = 0; |
… | |
… | |
4919 | evpipe_init (EV_A); |
4970 | evpipe_init (EV_A); |
4920 | |
4971 | |
4921 | EV_FREQUENT_CHECK; |
4972 | EV_FREQUENT_CHECK; |
4922 | |
4973 | |
4923 | ev_start (EV_A_ (W)w, ++asynccnt); |
4974 | ev_start (EV_A_ (W)w, ++asynccnt); |
4924 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4975 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4925 | asyncs [asynccnt - 1] = w; |
4976 | asyncs [asynccnt - 1] = w; |
4926 | |
4977 | |
4927 | EV_FREQUENT_CHECK; |
4978 | EV_FREQUENT_CHECK; |
4928 | } |
4979 | } |
4929 | |
4980 | |
4930 | void |
4981 | void |
4931 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4982 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4932 | { |
4983 | { |
4933 | clear_pending (EV_A_ (W)w); |
4984 | clear_pending (EV_A_ (W)w); |
4934 | if (expect_false (!ev_is_active (w))) |
4985 | if (expect_false (!ev_is_active (w))) |
4935 | return; |
4986 | return; |
4936 | |
4987 | |
… | |
… | |
4947 | |
4998 | |
4948 | EV_FREQUENT_CHECK; |
4999 | EV_FREQUENT_CHECK; |
4949 | } |
5000 | } |
4950 | |
5001 | |
4951 | void |
5002 | void |
4952 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
5003 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4953 | { |
5004 | { |
4954 | w->sent = 1; |
5005 | w->sent = 1; |
4955 | evpipe_write (EV_A_ &async_pending); |
5006 | evpipe_write (EV_A_ &async_pending); |
4956 | } |
5007 | } |
4957 | #endif |
5008 | #endif |
… | |
… | |
4994 | |
5045 | |
4995 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5046 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4996 | } |
5047 | } |
4997 | |
5048 | |
4998 | void |
5049 | void |
4999 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5050 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
5000 | { |
5051 | { |
5001 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5052 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5002 | |
|
|
5003 | if (expect_false (!once)) |
|
|
5004 | { |
|
|
5005 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5006 | return; |
|
|
5007 | } |
|
|
5008 | |
5053 | |
5009 | once->cb = cb; |
5054 | once->cb = cb; |
5010 | once->arg = arg; |
5055 | once->arg = arg; |
5011 | |
5056 | |
5012 | ev_init (&once->io, once_cb_io); |
5057 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5027 | /*****************************************************************************/ |
5072 | /*****************************************************************************/ |
5028 | |
5073 | |
5029 | #if EV_WALK_ENABLE |
5074 | #if EV_WALK_ENABLE |
5030 | ecb_cold |
5075 | ecb_cold |
5031 | void |
5076 | void |
5032 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5077 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
5033 | { |
5078 | { |
5034 | int i, j; |
5079 | int i, j; |
5035 | ev_watcher_list *wl, *wn; |
5080 | ev_watcher_list *wl, *wn; |
5036 | |
5081 | |
5037 | if (types & (EV_IO | EV_EMBED)) |
5082 | if (types & (EV_IO | EV_EMBED)) |