… | |
… | |
35 | * and other provisions required by the GPL. If you do not delete the |
35 | * and other provisions required by the GPL. If you do not delete the |
36 | * provisions above, a recipient may use your version of this file under |
36 | * provisions above, a recipient may use your version of this file under |
37 | * either the BSD or the GPL. |
37 | * either the BSD or the GPL. |
38 | */ |
38 | */ |
39 | |
39 | |
40 | #ifdef __cplusplus |
|
|
41 | extern "C" { |
|
|
42 | #endif |
|
|
43 | |
|
|
44 | /* this big block deduces configuration from config.h */ |
40 | /* this big block deduces configuration from config.h */ |
45 | #ifndef EV_STANDALONE |
41 | #ifndef EV_STANDALONE |
46 | # ifdef EV_CONFIG_H |
42 | # ifdef EV_CONFIG_H |
47 | # include EV_CONFIG_H |
43 | # include EV_CONFIG_H |
48 | # else |
44 | # else |
… | |
… | |
182 | # include EV_H |
178 | # include EV_H |
183 | #else |
179 | #else |
184 | # include "ev.h" |
180 | # include "ev.h" |
185 | #endif |
181 | #endif |
186 | |
182 | |
|
|
183 | EV_CPP(extern "C" {) |
|
|
184 | |
187 | #ifndef _WIN32 |
185 | #ifndef _WIN32 |
188 | # include <sys/time.h> |
186 | # include <sys/time.h> |
189 | # include <sys/wait.h> |
187 | # include <sys/wait.h> |
190 | # include <unistd.h> |
188 | # include <unistd.h> |
191 | #else |
189 | #else |
… | |
… | |
384 | # include <sys/select.h> |
382 | # include <sys/select.h> |
385 | # endif |
383 | # endif |
386 | #endif |
384 | #endif |
387 | |
385 | |
388 | #if EV_USE_INOTIFY |
386 | #if EV_USE_INOTIFY |
389 | # include <sys/utsname.h> |
|
|
390 | # include <sys/statfs.h> |
387 | # include <sys/statfs.h> |
391 | # include <sys/inotify.h> |
388 | # include <sys/inotify.h> |
392 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
389 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
393 | # ifndef IN_DONT_FOLLOW |
390 | # ifndef IN_DONT_FOLLOW |
394 | # undef EV_USE_INOTIFY |
391 | # undef EV_USE_INOTIFY |
… | |
… | |
411 | # define EFD_CLOEXEC O_CLOEXEC |
408 | # define EFD_CLOEXEC O_CLOEXEC |
412 | # else |
409 | # else |
413 | # define EFD_CLOEXEC 02000000 |
410 | # define EFD_CLOEXEC 02000000 |
414 | # endif |
411 | # endif |
415 | # endif |
412 | # endif |
416 | # ifdef __cplusplus |
|
|
417 | extern "C" { |
|
|
418 | # endif |
|
|
419 | int (eventfd) (unsigned int initval, int flags); |
413 | EV_CPP(extern "C") int (eventfd) (unsigned int initval, int flags); |
420 | # ifdef __cplusplus |
|
|
421 | } |
|
|
422 | # endif |
|
|
423 | #endif |
414 | #endif |
424 | |
415 | |
425 | #if EV_USE_SIGNALFD |
416 | #if EV_USE_SIGNALFD |
426 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
417 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
427 | # include <stdint.h> |
418 | # include <stdint.h> |
… | |
… | |
433 | # define SFD_CLOEXEC O_CLOEXEC |
424 | # define SFD_CLOEXEC O_CLOEXEC |
434 | # else |
425 | # else |
435 | # define SFD_CLOEXEC 02000000 |
426 | # define SFD_CLOEXEC 02000000 |
436 | # endif |
427 | # endif |
437 | # endif |
428 | # endif |
438 | # ifdef __cplusplus |
|
|
439 | extern "C" { |
|
|
440 | # endif |
|
|
441 | int signalfd (int fd, const sigset_t *mask, int flags); |
429 | EV_CPP (extern "C") int signalfd (int fd, const sigset_t *mask, int flags); |
442 | |
430 | |
443 | struct signalfd_siginfo |
431 | struct signalfd_siginfo |
444 | { |
432 | { |
445 | uint32_t ssi_signo; |
433 | uint32_t ssi_signo; |
446 | char pad[128 - sizeof (uint32_t)]; |
434 | char pad[128 - sizeof (uint32_t)]; |
447 | }; |
435 | }; |
448 | # ifdef __cplusplus |
|
|
449 | } |
|
|
450 | # endif |
|
|
451 | #endif |
436 | #endif |
452 | |
437 | |
453 | /**/ |
438 | /**/ |
454 | |
439 | |
455 | #if EV_VERIFY >= 3 |
440 | #if EV_VERIFY >= 3 |
… | |
… | |
537 | # include "ev_win32.c" |
522 | # include "ev_win32.c" |
538 | #endif |
523 | #endif |
539 | |
524 | |
540 | /*****************************************************************************/ |
525 | /*****************************************************************************/ |
541 | |
526 | |
|
|
527 | #ifdef __linux |
|
|
528 | # include <sys/utsname.h> |
|
|
529 | #endif |
|
|
530 | |
|
|
531 | static unsigned int noinline |
|
|
532 | ev_linux_version (void) |
|
|
533 | { |
|
|
534 | #ifdef __linux |
|
|
535 | unsigned int v = 0; |
|
|
536 | struct utsname buf; |
|
|
537 | int i; |
|
|
538 | char *p = buf.release; |
|
|
539 | |
|
|
540 | if (uname (&buf)) |
|
|
541 | return 0; |
|
|
542 | |
|
|
543 | for (i = 3+1; --i; ) |
|
|
544 | { |
|
|
545 | unsigned int c = 0; |
|
|
546 | |
|
|
547 | for (;;) |
|
|
548 | { |
|
|
549 | if (*p >= '0' && *p <= '9') |
|
|
550 | c = c * 10 + *p++ - '0'; |
|
|
551 | else |
|
|
552 | { |
|
|
553 | p += *p == '.'; |
|
|
554 | break; |
|
|
555 | } |
|
|
556 | } |
|
|
557 | |
|
|
558 | v = (v << 8) | c; |
|
|
559 | } |
|
|
560 | |
|
|
561 | return v; |
|
|
562 | #else |
|
|
563 | return 0; |
|
|
564 | #endif |
|
|
565 | } |
|
|
566 | |
|
|
567 | /*****************************************************************************/ |
|
|
568 | |
542 | #if EV_AVOID_STDIO |
569 | #if EV_AVOID_STDIO |
543 | static void noinline |
570 | static void noinline |
544 | ev_printerr (const char *msg) |
571 | ev_printerr (const char *msg) |
545 | { |
572 | { |
546 | write (STDERR_FILENO, msg, strlen (msg)); |
573 | write (STDERR_FILENO, msg, strlen (msg)); |
… | |
… | |
641 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
668 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
642 | unsigned char unused; |
669 | unsigned char unused; |
643 | #if EV_USE_EPOLL |
670 | #if EV_USE_EPOLL |
644 | unsigned int egen; /* generation counter to counter epoll bugs */ |
671 | unsigned int egen; /* generation counter to counter epoll bugs */ |
645 | #endif |
672 | #endif |
646 | #if EV_SELECT_IS_WINSOCKET |
673 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
647 | SOCKET handle; |
674 | SOCKET handle; |
|
|
675 | #endif |
|
|
676 | #if EV_USE_IOCP |
|
|
677 | OVERLAPPED or, ow; |
648 | #endif |
678 | #endif |
649 | } ANFD; |
679 | } ANFD; |
650 | |
680 | |
651 | /* stores the pending event set for a given watcher */ |
681 | /* stores the pending event set for a given watcher */ |
652 | typedef struct |
682 | typedef struct |
… | |
… | |
717 | # define EV_RELEASE_CB (void)0 |
747 | # define EV_RELEASE_CB (void)0 |
718 | # define EV_ACQUIRE_CB (void)0 |
748 | # define EV_ACQUIRE_CB (void)0 |
719 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
749 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
720 | #endif |
750 | #endif |
721 | |
751 | |
722 | #define EVUNLOOP_RECURSE 0x80 |
752 | #define EVBREAK_RECURSE 0x80 |
723 | |
753 | |
724 | /*****************************************************************************/ |
754 | /*****************************************************************************/ |
725 | |
755 | |
726 | #ifndef EV_HAVE_EV_TIME |
756 | #ifndef EV_HAVE_EV_TIME |
727 | ev_tstamp |
757 | ev_tstamp |
… | |
… | |
948 | unsigned char o_events = anfd->events; |
978 | unsigned char o_events = anfd->events; |
949 | unsigned char o_reify = anfd->reify; |
979 | unsigned char o_reify = anfd->reify; |
950 | |
980 | |
951 | anfd->reify = 0; |
981 | anfd->reify = 0; |
952 | |
982 | |
953 | #if EV_SELECT_IS_WINSOCKET |
983 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
954 | if (o_reify & EV__IOFDSET) |
984 | if (o_reify & EV__IOFDSET) |
955 | { |
985 | { |
956 | unsigned long arg; |
986 | unsigned long arg; |
957 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
987 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
958 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
988 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
|
|
989 | printf ("oi %d %x\n", fd, anfd->handle);//D |
959 | } |
990 | } |
960 | #endif |
991 | #endif |
961 | |
992 | |
962 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
993 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
963 | { |
994 | { |
… | |
… | |
1462 | |
1493 | |
1463 | #endif |
1494 | #endif |
1464 | |
1495 | |
1465 | /*****************************************************************************/ |
1496 | /*****************************************************************************/ |
1466 | |
1497 | |
|
|
1498 | #if EV_USE_IOCP |
|
|
1499 | # include "ev_iocp.c" |
|
|
1500 | #endif |
1467 | #if EV_USE_PORT |
1501 | #if EV_USE_PORT |
1468 | # include "ev_port.c" |
1502 | # include "ev_port.c" |
1469 | #endif |
1503 | #endif |
1470 | #if EV_USE_KQUEUE |
1504 | #if EV_USE_KQUEUE |
1471 | # include "ev_kqueue.c" |
1505 | # include "ev_kqueue.c" |
… | |
… | |
1544 | ev_embeddable_backends (void) |
1578 | ev_embeddable_backends (void) |
1545 | { |
1579 | { |
1546 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
1580 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
1547 | |
1581 | |
1548 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
1582 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
1549 | /* please fix it and tell me how to detect the fix */ |
1583 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
1550 | flags &= ~EVBACKEND_EPOLL; |
1584 | flags &= ~EVBACKEND_EPOLL; |
1551 | |
1585 | |
1552 | return flags; |
1586 | return flags; |
1553 | } |
1587 | } |
1554 | |
1588 | |
1555 | unsigned int |
1589 | unsigned int |
… | |
… | |
1668 | #endif |
1702 | #endif |
1669 | |
1703 | |
1670 | if (!(flags & 0x0000ffffU)) |
1704 | if (!(flags & 0x0000ffffU)) |
1671 | flags |= ev_recommended_backends (); |
1705 | flags |= ev_recommended_backends (); |
1672 | |
1706 | |
|
|
1707 | #if EV_USE_IOCP |
|
|
1708 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
|
|
1709 | #endif |
1673 | #if EV_USE_PORT |
1710 | #if EV_USE_PORT |
1674 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1711 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1675 | #endif |
1712 | #endif |
1676 | #if EV_USE_KQUEUE |
1713 | #if EV_USE_KQUEUE |
1677 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
1714 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
… | |
… | |
1694 | #endif |
1731 | #endif |
1695 | } |
1732 | } |
1696 | } |
1733 | } |
1697 | |
1734 | |
1698 | /* free up a loop structure */ |
1735 | /* free up a loop structure */ |
1699 | static void noinline |
1736 | void |
1700 | loop_destroy (EV_P) |
1737 | ev_loop_destroy (EV_P) |
1701 | { |
1738 | { |
1702 | int i; |
1739 | int i; |
|
|
1740 | |
|
|
1741 | #if EV_CHILD_ENABLE |
|
|
1742 | if (ev_is_active (&childev)) |
|
|
1743 | { |
|
|
1744 | ev_ref (EV_A); /* child watcher */ |
|
|
1745 | ev_signal_stop (EV_A_ &childev); |
|
|
1746 | } |
|
|
1747 | #endif |
1703 | |
1748 | |
1704 | if (ev_is_active (&pipe_w)) |
1749 | if (ev_is_active (&pipe_w)) |
1705 | { |
1750 | { |
1706 | /*ev_ref (EV_A);*/ |
1751 | /*ev_ref (EV_A);*/ |
1707 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
1752 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
… | |
… | |
1729 | #endif |
1774 | #endif |
1730 | |
1775 | |
1731 | if (backend_fd >= 0) |
1776 | if (backend_fd >= 0) |
1732 | close (backend_fd); |
1777 | close (backend_fd); |
1733 | |
1778 | |
|
|
1779 | #if EV_USE_IOCP |
|
|
1780 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
|
|
1781 | #endif |
1734 | #if EV_USE_PORT |
1782 | #if EV_USE_PORT |
1735 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
1783 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
1736 | #endif |
1784 | #endif |
1737 | #if EV_USE_KQUEUE |
1785 | #if EV_USE_KQUEUE |
1738 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
1786 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
… | |
… | |
1765 | array_free (periodic, EMPTY); |
1813 | array_free (periodic, EMPTY); |
1766 | #endif |
1814 | #endif |
1767 | #if EV_FORK_ENABLE |
1815 | #if EV_FORK_ENABLE |
1768 | array_free (fork, EMPTY); |
1816 | array_free (fork, EMPTY); |
1769 | #endif |
1817 | #endif |
|
|
1818 | #if EV_CLEANUP_ENABLE |
|
|
1819 | array_free (cleanup, EMPTY); |
|
|
1820 | #endif |
1770 | array_free (prepare, EMPTY); |
1821 | array_free (prepare, EMPTY); |
1771 | array_free (check, EMPTY); |
1822 | array_free (check, EMPTY); |
1772 | #if EV_ASYNC_ENABLE |
1823 | #if EV_ASYNC_ENABLE |
1773 | array_free (async, EMPTY); |
1824 | array_free (async, EMPTY); |
1774 | #endif |
1825 | #endif |
1775 | |
1826 | |
1776 | backend = 0; |
1827 | backend = 0; |
|
|
1828 | |
|
|
1829 | #if EV_MULTIPLICITY |
|
|
1830 | if (ev_is_default_loop (EV_A)) |
|
|
1831 | #endif |
|
|
1832 | ev_default_loop_ptr = 0; |
|
|
1833 | #if EV_MULTIPLICITY |
|
|
1834 | else |
|
|
1835 | ev_free (EV_A); |
|
|
1836 | #endif |
1777 | } |
1837 | } |
1778 | |
1838 | |
1779 | #if EV_USE_INOTIFY |
1839 | #if EV_USE_INOTIFY |
1780 | inline_size void infy_fork (EV_P); |
1840 | inline_size void infy_fork (EV_P); |
1781 | #endif |
1841 | #endif |
… | |
… | |
1840 | loop_init (EV_A_ flags); |
1900 | loop_init (EV_A_ flags); |
1841 | |
1901 | |
1842 | if (ev_backend (EV_A)) |
1902 | if (ev_backend (EV_A)) |
1843 | return EV_A; |
1903 | return EV_A; |
1844 | |
1904 | |
|
|
1905 | ev_free (EV_A); |
1845 | return 0; |
1906 | return 0; |
1846 | } |
1907 | } |
1847 | |
1908 | |
1848 | void |
|
|
1849 | ev_loop_destroy (EV_P) |
|
|
1850 | { |
|
|
1851 | loop_destroy (EV_A); |
|
|
1852 | ev_free (loop); |
|
|
1853 | } |
|
|
1854 | |
|
|
1855 | void |
|
|
1856 | ev_loop_fork (EV_P) |
|
|
1857 | { |
|
|
1858 | postfork = 1; /* must be in line with ev_default_fork */ |
|
|
1859 | } |
|
|
1860 | #endif /* multiplicity */ |
1909 | #endif /* multiplicity */ |
1861 | |
1910 | |
1862 | #if EV_VERIFY |
1911 | #if EV_VERIFY |
1863 | static void noinline |
1912 | static void noinline |
1864 | verify_watcher (EV_P_ W w) |
1913 | verify_watcher (EV_P_ W w) |
… | |
… | |
1939 | #if EV_FORK_ENABLE |
1988 | #if EV_FORK_ENABLE |
1940 | assert (forkmax >= forkcnt); |
1989 | assert (forkmax >= forkcnt); |
1941 | array_verify (EV_A_ (W *)forks, forkcnt); |
1990 | array_verify (EV_A_ (W *)forks, forkcnt); |
1942 | #endif |
1991 | #endif |
1943 | |
1992 | |
|
|
1993 | #if EV_CLEANUP_ENABLE |
|
|
1994 | assert (cleanupmax >= cleanupcnt); |
|
|
1995 | array_verify (EV_A_ (W *)cleanups, cleanupcnt); |
|
|
1996 | #endif |
|
|
1997 | |
1944 | #if EV_ASYNC_ENABLE |
1998 | #if EV_ASYNC_ENABLE |
1945 | assert (asyncmax >= asynccnt); |
1999 | assert (asyncmax >= asynccnt); |
1946 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
2000 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1947 | #endif |
2001 | #endif |
1948 | |
2002 | |
… | |
… | |
1966 | } |
2020 | } |
1967 | #endif |
2021 | #endif |
1968 | |
2022 | |
1969 | #if EV_MULTIPLICITY |
2023 | #if EV_MULTIPLICITY |
1970 | struct ev_loop * |
2024 | struct ev_loop * |
1971 | ev_default_loop_init (unsigned int flags) |
|
|
1972 | #else |
2025 | #else |
1973 | int |
2026 | int |
|
|
2027 | #endif |
1974 | ev_default_loop (unsigned int flags) |
2028 | ev_default_loop (unsigned int flags) |
1975 | #endif |
|
|
1976 | { |
2029 | { |
1977 | if (!ev_default_loop_ptr) |
2030 | if (!ev_default_loop_ptr) |
1978 | { |
2031 | { |
1979 | #if EV_MULTIPLICITY |
2032 | #if EV_MULTIPLICITY |
1980 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2033 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
1999 | |
2052 | |
2000 | return ev_default_loop_ptr; |
2053 | return ev_default_loop_ptr; |
2001 | } |
2054 | } |
2002 | |
2055 | |
2003 | void |
2056 | void |
2004 | ev_default_destroy (void) |
2057 | ev_loop_fork (EV_P) |
2005 | { |
2058 | { |
2006 | #if EV_MULTIPLICITY |
|
|
2007 | EV_P = ev_default_loop_ptr; |
|
|
2008 | #endif |
|
|
2009 | |
|
|
2010 | ev_default_loop_ptr = 0; |
|
|
2011 | |
|
|
2012 | #if EV_CHILD_ENABLE |
|
|
2013 | ev_ref (EV_A); /* child watcher */ |
|
|
2014 | ev_signal_stop (EV_A_ &childev); |
|
|
2015 | #endif |
|
|
2016 | |
|
|
2017 | loop_destroy (EV_A); |
|
|
2018 | } |
|
|
2019 | |
|
|
2020 | void |
|
|
2021 | ev_default_fork (void) |
|
|
2022 | { |
|
|
2023 | #if EV_MULTIPLICITY |
|
|
2024 | EV_P = ev_default_loop_ptr; |
|
|
2025 | #endif |
|
|
2026 | |
|
|
2027 | postfork = 1; /* must be in line with ev_loop_fork */ |
2059 | postfork = 1; /* must be in line with ev_default_fork */ |
2028 | } |
2060 | } |
2029 | |
2061 | |
2030 | /*****************************************************************************/ |
2062 | /*****************************************************************************/ |
2031 | |
2063 | |
2032 | void |
2064 | void |
… | |
… | |
2292 | mn_now = ev_rt_now; |
2324 | mn_now = ev_rt_now; |
2293 | } |
2325 | } |
2294 | } |
2326 | } |
2295 | |
2327 | |
2296 | void |
2328 | void |
2297 | ev_loop (EV_P_ int flags) |
2329 | ev_run (EV_P_ int flags) |
2298 | { |
2330 | { |
2299 | #if EV_FEATURE_API |
2331 | #if EV_FEATURE_API |
2300 | ++loop_depth; |
2332 | ++loop_depth; |
2301 | #endif |
2333 | #endif |
2302 | |
2334 | |
2303 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2335 | assert (("libev: ev_loop recursion during release detected", loop_done != EVBREAK_RECURSE)); |
2304 | |
2336 | |
2305 | loop_done = EVUNLOOP_CANCEL; |
2337 | loop_done = EVBREAK_CANCEL; |
2306 | |
2338 | |
2307 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2339 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2308 | |
2340 | |
2309 | do |
2341 | do |
2310 | { |
2342 | { |
… | |
… | |
2353 | /* calculate blocking time */ |
2385 | /* calculate blocking time */ |
2354 | { |
2386 | { |
2355 | ev_tstamp waittime = 0.; |
2387 | ev_tstamp waittime = 0.; |
2356 | ev_tstamp sleeptime = 0.; |
2388 | ev_tstamp sleeptime = 0.; |
2357 | |
2389 | |
|
|
2390 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2391 | ev_tstamp prev_mn_now = mn_now; |
|
|
2392 | |
|
|
2393 | /* update time to cancel out callback processing overhead */ |
|
|
2394 | time_update (EV_A_ 1e100); |
|
|
2395 | |
2358 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2396 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt))) |
2359 | { |
2397 | { |
2360 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2361 | ev_tstamp prev_mn_now = mn_now; |
|
|
2362 | |
|
|
2363 | /* update time to cancel out callback processing overhead */ |
|
|
2364 | time_update (EV_A_ 1e100); |
|
|
2365 | |
|
|
2366 | waittime = MAX_BLOCKTIME; |
2398 | waittime = MAX_BLOCKTIME; |
2367 | |
2399 | |
2368 | if (timercnt) |
2400 | if (timercnt) |
2369 | { |
2401 | { |
2370 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
2402 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
… | |
… | |
2400 | } |
2432 | } |
2401 | |
2433 | |
2402 | #if EV_FEATURE_API |
2434 | #if EV_FEATURE_API |
2403 | ++loop_count; |
2435 | ++loop_count; |
2404 | #endif |
2436 | #endif |
2405 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2437 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2406 | backend_poll (EV_A_ waittime); |
2438 | backend_poll (EV_A_ waittime); |
2407 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2439 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2408 | |
2440 | |
2409 | /* update ev_rt_now, do magic */ |
2441 | /* update ev_rt_now, do magic */ |
2410 | time_update (EV_A_ waittime + sleeptime); |
2442 | time_update (EV_A_ waittime + sleeptime); |
2411 | } |
2443 | } |
2412 | |
2444 | |
… | |
… | |
2430 | EV_INVOKE_PENDING; |
2462 | EV_INVOKE_PENDING; |
2431 | } |
2463 | } |
2432 | while (expect_true ( |
2464 | while (expect_true ( |
2433 | activecnt |
2465 | activecnt |
2434 | && !loop_done |
2466 | && !loop_done |
2435 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2467 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
2436 | )); |
2468 | )); |
2437 | |
2469 | |
2438 | if (loop_done == EVUNLOOP_ONE) |
2470 | if (loop_done == EVBREAK_ONE) |
2439 | loop_done = EVUNLOOP_CANCEL; |
2471 | loop_done = EVBREAK_CANCEL; |
2440 | |
2472 | |
2441 | #if EV_FEATURE_API |
2473 | #if EV_FEATURE_API |
2442 | --loop_depth; |
2474 | --loop_depth; |
2443 | #endif |
2475 | #endif |
2444 | } |
2476 | } |
2445 | |
2477 | |
2446 | void |
2478 | void |
2447 | ev_unloop (EV_P_ int how) |
2479 | ev_break (EV_P_ int how) |
2448 | { |
2480 | { |
2449 | loop_done = how; |
2481 | loop_done = how; |
2450 | } |
2482 | } |
2451 | |
2483 | |
2452 | void |
2484 | void |
… | |
… | |
3062 | { |
3094 | { |
3063 | struct inotify_event *ev = (struct inotify_event *)(buf + ofs); |
3095 | struct inotify_event *ev = (struct inotify_event *)(buf + ofs); |
3064 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3096 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3065 | ofs += sizeof (struct inotify_event) + ev->len; |
3097 | ofs += sizeof (struct inotify_event) + ev->len; |
3066 | } |
3098 | } |
3067 | } |
|
|
3068 | |
|
|
3069 | inline_size unsigned int |
|
|
3070 | ev_linux_version (void) |
|
|
3071 | { |
|
|
3072 | struct utsname buf; |
|
|
3073 | unsigned int v; |
|
|
3074 | int i; |
|
|
3075 | char *p = buf.release; |
|
|
3076 | |
|
|
3077 | if (uname (&buf)) |
|
|
3078 | return 0; |
|
|
3079 | |
|
|
3080 | for (i = 3+1; --i; ) |
|
|
3081 | { |
|
|
3082 | unsigned int c = 0; |
|
|
3083 | |
|
|
3084 | for (;;) |
|
|
3085 | { |
|
|
3086 | if (*p >= '0' && *p <= '9') |
|
|
3087 | c = c * 10 + *p++ - '0'; |
|
|
3088 | else |
|
|
3089 | { |
|
|
3090 | p += *p == '.'; |
|
|
3091 | break; |
|
|
3092 | } |
|
|
3093 | } |
|
|
3094 | |
|
|
3095 | v = (v << 8) | c; |
|
|
3096 | } |
|
|
3097 | |
|
|
3098 | return v; |
|
|
3099 | } |
3099 | } |
3100 | |
3100 | |
3101 | inline_size void |
3101 | inline_size void |
3102 | ev_check_2625 (EV_P) |
3102 | ev_check_2625 (EV_P) |
3103 | { |
3103 | { |
… | |
… | |
3427 | |
3427 | |
3428 | #if EV_EMBED_ENABLE |
3428 | #if EV_EMBED_ENABLE |
3429 | void noinline |
3429 | void noinline |
3430 | ev_embed_sweep (EV_P_ ev_embed *w) |
3430 | ev_embed_sweep (EV_P_ ev_embed *w) |
3431 | { |
3431 | { |
3432 | ev_loop (w->other, EVLOOP_NONBLOCK); |
3432 | ev_run (w->other, EVRUN_NOWAIT); |
3433 | } |
3433 | } |
3434 | |
3434 | |
3435 | static void |
3435 | static void |
3436 | embed_io_cb (EV_P_ ev_io *io, int revents) |
3436 | embed_io_cb (EV_P_ ev_io *io, int revents) |
3437 | { |
3437 | { |
3438 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
3438 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
3439 | |
3439 | |
3440 | if (ev_cb (w)) |
3440 | if (ev_cb (w)) |
3441 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
3441 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
3442 | else |
3442 | else |
3443 | ev_loop (w->other, EVLOOP_NONBLOCK); |
3443 | ev_run (w->other, EVRUN_NOWAIT); |
3444 | } |
3444 | } |
3445 | |
3445 | |
3446 | static void |
3446 | static void |
3447 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3447 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3448 | { |
3448 | { |
… | |
… | |
3452 | EV_P = w->other; |
3452 | EV_P = w->other; |
3453 | |
3453 | |
3454 | while (fdchangecnt) |
3454 | while (fdchangecnt) |
3455 | { |
3455 | { |
3456 | fd_reify (EV_A); |
3456 | fd_reify (EV_A); |
3457 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3457 | ev_run (EV_A_ EVRUN_NOWAIT); |
3458 | } |
3458 | } |
3459 | } |
3459 | } |
3460 | } |
3460 | } |
3461 | |
3461 | |
3462 | static void |
3462 | static void |
… | |
… | |
3468 | |
3468 | |
3469 | { |
3469 | { |
3470 | EV_P = w->other; |
3470 | EV_P = w->other; |
3471 | |
3471 | |
3472 | ev_loop_fork (EV_A); |
3472 | ev_loop_fork (EV_A); |
3473 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3473 | ev_run (EV_A_ EVRUN_NOWAIT); |
3474 | } |
3474 | } |
3475 | |
3475 | |
3476 | ev_embed_start (EV_A_ w); |
3476 | ev_embed_start (EV_A_ w); |
3477 | } |
3477 | } |
3478 | |
3478 | |
… | |
… | |
3562 | { |
3562 | { |
3563 | int active = ev_active (w); |
3563 | int active = ev_active (w); |
3564 | |
3564 | |
3565 | forks [active - 1] = forks [--forkcnt]; |
3565 | forks [active - 1] = forks [--forkcnt]; |
3566 | ev_active (forks [active - 1]) = active; |
3566 | ev_active (forks [active - 1]) = active; |
|
|
3567 | } |
|
|
3568 | |
|
|
3569 | ev_stop (EV_A_ (W)w); |
|
|
3570 | |
|
|
3571 | EV_FREQUENT_CHECK; |
|
|
3572 | } |
|
|
3573 | #endif |
|
|
3574 | |
|
|
3575 | #if EV_CLEANUP_ENABLE |
|
|
3576 | void |
|
|
3577 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
|
|
3578 | { |
|
|
3579 | if (expect_false (ev_is_active (w))) |
|
|
3580 | return; |
|
|
3581 | |
|
|
3582 | EV_FREQUENT_CHECK; |
|
|
3583 | |
|
|
3584 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
|
|
3585 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
|
|
3586 | cleanups [cleanupcnt - 1] = w; |
|
|
3587 | |
|
|
3588 | EV_FREQUENT_CHECK; |
|
|
3589 | } |
|
|
3590 | |
|
|
3591 | void |
|
|
3592 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
|
|
3593 | { |
|
|
3594 | clear_pending (EV_A_ (W)w); |
|
|
3595 | if (expect_false (!ev_is_active (w))) |
|
|
3596 | return; |
|
|
3597 | |
|
|
3598 | EV_FREQUENT_CHECK; |
|
|
3599 | |
|
|
3600 | { |
|
|
3601 | int active = ev_active (w); |
|
|
3602 | |
|
|
3603 | cleanups [active - 1] = cleanups [--cleanupcnt]; |
|
|
3604 | ev_active (cleanups [active - 1]) = active; |
3567 | } |
3605 | } |
3568 | |
3606 | |
3569 | ev_stop (EV_A_ (W)w); |
3607 | ev_stop (EV_A_ (W)w); |
3570 | |
3608 | |
3571 | EV_FREQUENT_CHECK; |
3609 | EV_FREQUENT_CHECK; |
… | |
… | |
3807 | |
3845 | |
3808 | #if EV_MULTIPLICITY |
3846 | #if EV_MULTIPLICITY |
3809 | #include "ev_wrap.h" |
3847 | #include "ev_wrap.h" |
3810 | #endif |
3848 | #endif |
3811 | |
3849 | |
3812 | #ifdef __cplusplus |
3850 | EV_CPP(}) |
3813 | } |
|
|
3814 | #endif |
|
|
3815 | |
3851 | |