… | |
… | |
1867 | static void noinline ecb_cold |
1867 | static void noinline ecb_cold |
1868 | evpipe_init (EV_P) |
1868 | evpipe_init (EV_P) |
1869 | { |
1869 | { |
1870 | if (!ev_is_active (&pipe_w)) |
1870 | if (!ev_is_active (&pipe_w)) |
1871 | { |
1871 | { |
|
|
1872 | int fds [2]; |
|
|
1873 | |
1872 | # if EV_USE_EVENTFD |
1874 | # if EV_USE_EVENTFD |
|
|
1875 | fds [0] = -1; |
1873 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1876 | fds [1] = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1874 | if (evfd < 0 && errno == EINVAL) |
1877 | if (fds [1] < 0 && errno == EINVAL) |
1875 | evfd = eventfd (0, 0); |
1878 | fds [1] = eventfd (0, 0); |
1876 | |
1879 | |
1877 | if (evfd >= 0) |
1880 | if (fds [1] < 0) |
1878 | { |
|
|
1879 | evpipe [0] = -1; |
|
|
1880 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
|
|
1881 | ev_io_set (&pipe_w, evfd, EV_READ); |
|
|
1882 | } |
|
|
1883 | else |
|
|
1884 | # endif |
1881 | # endif |
1885 | { |
1882 | { |
1886 | while (pipe (evpipe)) |
1883 | while (pipe (fds)) |
1887 | ev_syserr ("(libev) error creating signal/async pipe"); |
1884 | ev_syserr ("(libev) error creating signal/async pipe"); |
1888 | |
1885 | |
1889 | fd_intern (evpipe [0]); |
1886 | fd_intern (fds [0]); |
1890 | fd_intern (evpipe [1]); |
|
|
1891 | ev_io_set (&pipe_w, evpipe [0], EV_READ); |
|
|
1892 | } |
1887 | } |
1893 | |
1888 | |
|
|
1889 | fd_intern (fds [1]); |
|
|
1890 | |
|
|
1891 | evpipe [0] = fds [0]; |
|
|
1892 | |
|
|
1893 | if (evpipe [1] < 0) |
|
|
1894 | evpipe [1] = fds [1]; /* first call, set write fd */ |
|
|
1895 | else |
|
|
1896 | { |
|
|
1897 | /* on subsequent calls, do not change evpipe [1] */ |
|
|
1898 | /* so that evpipe_write can always rely on its value. */ |
|
|
1899 | /* this branch does not do anything sensible on windows, */ |
|
|
1900 | /* so must not be executed on windows */ |
|
|
1901 | |
|
|
1902 | dup2 (fds [1], evpipe [1]); |
|
|
1903 | close (fds [1]); |
|
|
1904 | } |
|
|
1905 | |
|
|
1906 | ev_io_set (&pipe_w, evpipe [0] < 0 ? evpipe [1] : evpipe [0], EV_READ); |
1894 | ev_io_start (EV_A_ &pipe_w); |
1907 | ev_io_start (EV_A_ &pipe_w); |
1895 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1908 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1896 | } |
1909 | } |
1897 | } |
1910 | } |
1898 | |
1911 | |
… | |
… | |
1919 | ECB_MEMORY_FENCE_RELEASE; |
1932 | ECB_MEMORY_FENCE_RELEASE; |
1920 | |
1933 | |
1921 | old_errno = errno; /* save errno because write will clobber it */ |
1934 | old_errno = errno; /* save errno because write will clobber it */ |
1922 | |
1935 | |
1923 | #if EV_USE_EVENTFD |
1936 | #if EV_USE_EVENTFD |
1924 | if (evfd >= 0) |
1937 | if (evpipe [0] < 0) |
1925 | { |
1938 | { |
1926 | uint64_t counter = 1; |
1939 | uint64_t counter = 1; |
1927 | write (evfd, &counter, sizeof (uint64_t)); |
1940 | write (evpipe [1], &counter, sizeof (uint64_t)); |
1928 | } |
1941 | } |
1929 | else |
1942 | else |
1930 | #endif |
1943 | #endif |
1931 | { |
1944 | { |
1932 | #ifdef _WIN32 |
1945 | #ifdef _WIN32 |
… | |
… | |
1952 | int i; |
1965 | int i; |
1953 | |
1966 | |
1954 | if (revents & EV_READ) |
1967 | if (revents & EV_READ) |
1955 | { |
1968 | { |
1956 | #if EV_USE_EVENTFD |
1969 | #if EV_USE_EVENTFD |
1957 | if (evfd >= 0) |
1970 | if (evpipe [0] < 0) |
1958 | { |
1971 | { |
1959 | uint64_t counter; |
1972 | uint64_t counter; |
1960 | read (evfd, &counter, sizeof (uint64_t)); |
1973 | read (evpipe [1], &counter, sizeof (uint64_t)); |
1961 | } |
1974 | } |
1962 | else |
1975 | else |
1963 | #endif |
1976 | #endif |
1964 | { |
1977 | { |
1965 | char dummy[4]; |
1978 | char dummy[4]; |
… | |
… | |
2021 | |
2034 | |
2022 | if (!EV_A) |
2035 | if (!EV_A) |
2023 | return; |
2036 | return; |
2024 | #endif |
2037 | #endif |
2025 | |
2038 | |
2026 | if (!ev_active (&pipe_w)) |
|
|
2027 | return; |
|
|
2028 | |
|
|
2029 | signals [signum - 1].pending = 1; |
2039 | signals [signum - 1].pending = 1; |
2030 | evpipe_write (EV_A_ &sig_pending); |
2040 | evpipe_write (EV_A_ &sig_pending); |
2031 | } |
2041 | } |
2032 | |
2042 | |
2033 | static void |
2043 | static void |
… | |
… | |
2351 | #if EV_ASYNC_ENABLE |
2361 | #if EV_ASYNC_ENABLE |
2352 | async_pending = 0; |
2362 | async_pending = 0; |
2353 | #endif |
2363 | #endif |
2354 | pipe_write_skipped = 0; |
2364 | pipe_write_skipped = 0; |
2355 | pipe_write_wanted = 0; |
2365 | pipe_write_wanted = 0; |
|
|
2366 | evpipe [0] = -1; |
|
|
2367 | evpipe [1] = -1; |
2356 | #if EV_USE_INOTIFY |
2368 | #if EV_USE_INOTIFY |
2357 | fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; |
2369 | fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; |
2358 | #endif |
2370 | #endif |
2359 | #if EV_USE_SIGNALFD |
2371 | #if EV_USE_SIGNALFD |
2360 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
2372 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
… | |
… | |
2423 | if (ev_is_active (&pipe_w)) |
2435 | if (ev_is_active (&pipe_w)) |
2424 | { |
2436 | { |
2425 | /*ev_ref (EV_A);*/ |
2437 | /*ev_ref (EV_A);*/ |
2426 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
2438 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
2427 | |
2439 | |
2428 | #if EV_USE_EVENTFD |
|
|
2429 | if (evfd >= 0) |
|
|
2430 | close (evfd); |
|
|
2431 | #endif |
|
|
2432 | |
|
|
2433 | if (evpipe [0] >= 0) |
|
|
2434 | { |
|
|
2435 | EV_WIN32_CLOSE_FD (evpipe [0]); |
2440 | if (evpipe [0] >= 0) EV_WIN32_CLOSE_FD (evpipe [0]); |
2436 | EV_WIN32_CLOSE_FD (evpipe [1]); |
2441 | if (evpipe [1] >= 0) EV_WIN32_CLOSE_FD (evpipe [1]); |
2437 | } |
|
|
2438 | } |
2442 | } |
2439 | |
2443 | |
2440 | #if EV_USE_SIGNALFD |
2444 | #if EV_USE_SIGNALFD |
2441 | if (ev_is_active (&sigfd_w)) |
2445 | if (ev_is_active (&sigfd_w)) |
2442 | close (sigfd); |
2446 | close (sigfd); |
… | |
… | |
2528 | #endif |
2532 | #endif |
2529 | #if EV_USE_INOTIFY |
2533 | #if EV_USE_INOTIFY |
2530 | infy_fork (EV_A); |
2534 | infy_fork (EV_A); |
2531 | #endif |
2535 | #endif |
2532 | |
2536 | |
|
|
2537 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2533 | if (ev_is_active (&pipe_w)) |
2538 | if (ev_is_active (&pipe_w)) |
2534 | { |
2539 | { |
2535 | /* pipe_write_wanted must be false now, so modifying fd vars should be safe */ |
2540 | /* pipe_write_wanted must be false now, so modifying fd vars should be safe */ |
2536 | |
2541 | |
2537 | ev_ref (EV_A); |
2542 | ev_ref (EV_A); |
2538 | ev_io_stop (EV_A_ &pipe_w); |
2543 | ev_io_stop (EV_A_ &pipe_w); |
2539 | |
2544 | |
2540 | #if EV_USE_EVENTFD |
|
|
2541 | if (evfd >= 0) |
|
|
2542 | close (evfd); |
|
|
2543 | #endif |
|
|
2544 | |
|
|
2545 | if (evpipe [0] >= 0) |
2545 | if (evpipe [0] >= 0) |
2546 | { |
|
|
2547 | EV_WIN32_CLOSE_FD (evpipe [0]); |
2546 | EV_WIN32_CLOSE_FD (evpipe [0]); |
2548 | EV_WIN32_CLOSE_FD (evpipe [1]); |
|
|
2549 | } |
|
|
2550 | |
2547 | |
2551 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
|
|
2552 | evpipe_init (EV_A); |
2548 | evpipe_init (EV_A); |
2553 | /* iterate over everything, in case we missed something before */ |
2549 | /* iterate over everything, in case we missed something before */ |
2554 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
2550 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
2555 | #endif |
|
|
2556 | } |
2551 | } |
|
|
2552 | #endif |
2557 | |
2553 | |
2558 | postfork = 0; |
2554 | postfork = 0; |
2559 | } |
2555 | } |
2560 | |
2556 | |
2561 | #if EV_MULTIPLICITY |
2557 | #if EV_MULTIPLICITY |