ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.447 by root, Tue Jun 19 12:29:43 2012 UTC vs.
Revision 1.449 by root, Sun Sep 23 21:21:58 2012 UTC

1867static void noinline ecb_cold 1867static void noinline ecb_cold
1868evpipe_init (EV_P) 1868evpipe_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];
2015 2028
2016void 2029void
2017ev_feed_signal (int signum) EV_THROW 2030ev_feed_signal (int signum) EV_THROW
2018{ 2031{
2019#if EV_MULTIPLICITY 2032#if EV_MULTIPLICITY
2033 ECB_MEMORY_FENCE_ACQUIRE;
2020 EV_P = signals [signum - 1].loop; 2034 EV_P = signals [signum - 1].loop;
2021 2035
2022 if (!EV_A) 2036 if (!EV_A)
2023 return; 2037 return;
2024#endif 2038#endif
2025
2026 if (!ev_active (&pipe_w))
2027 return;
2028 2039
2029 signals [signum - 1].pending = 1; 2040 signals [signum - 1].pending = 1;
2030 evpipe_write (EV_A_ &sig_pending); 2041 evpipe_write (EV_A_ &sig_pending);
2031} 2042}
2032 2043
2351#if EV_ASYNC_ENABLE 2362#if EV_ASYNC_ENABLE
2352 async_pending = 0; 2363 async_pending = 0;
2353#endif 2364#endif
2354 pipe_write_skipped = 0; 2365 pipe_write_skipped = 0;
2355 pipe_write_wanted = 0; 2366 pipe_write_wanted = 0;
2367 evpipe [0] = -1;
2368 evpipe [1] = -1;
2356#if EV_USE_INOTIFY 2369#if EV_USE_INOTIFY
2357 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; 2370 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
2358#endif 2371#endif
2359#if EV_USE_SIGNALFD 2372#if EV_USE_SIGNALFD
2360 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 2373 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
2423 if (ev_is_active (&pipe_w)) 2436 if (ev_is_active (&pipe_w))
2424 { 2437 {
2425 /*ev_ref (EV_A);*/ 2438 /*ev_ref (EV_A);*/
2426 /*ev_io_stop (EV_A_ &pipe_w);*/ 2439 /*ev_io_stop (EV_A_ &pipe_w);*/
2427 2440
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]); 2441 if (evpipe [0] >= 0) EV_WIN32_CLOSE_FD (evpipe [0]);
2436 EV_WIN32_CLOSE_FD (evpipe [1]); 2442 if (evpipe [1] >= 0) EV_WIN32_CLOSE_FD (evpipe [1]);
2437 }
2438 } 2443 }
2439 2444
2440#if EV_USE_SIGNALFD 2445#if EV_USE_SIGNALFD
2441 if (ev_is_active (&sigfd_w)) 2446 if (ev_is_active (&sigfd_w))
2442 close (sigfd); 2447 close (sigfd);
2528#endif 2533#endif
2529#if EV_USE_INOTIFY 2534#if EV_USE_INOTIFY
2530 infy_fork (EV_A); 2535 infy_fork (EV_A);
2531#endif 2536#endif
2532 2537
2538#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2533 if (ev_is_active (&pipe_w)) 2539 if (ev_is_active (&pipe_w))
2534 { 2540 {
2535 /* pipe_write_wanted must be false now, so modifying fd vars should be safe */ 2541 /* pipe_write_wanted must be false now, so modifying fd vars should be safe */
2536 2542
2537 ev_ref (EV_A); 2543 ev_ref (EV_A);
2538 ev_io_stop (EV_A_ &pipe_w); 2544 ev_io_stop (EV_A_ &pipe_w);
2539 2545
2540#if EV_USE_EVENTFD
2541 if (evfd >= 0)
2542 close (evfd);
2543#endif
2544
2545 if (evpipe [0] >= 0) 2546 if (evpipe [0] >= 0)
2546 {
2547 EV_WIN32_CLOSE_FD (evpipe [0]); 2547 EV_WIN32_CLOSE_FD (evpipe [0]);
2548 EV_WIN32_CLOSE_FD (evpipe [1]);
2549 }
2550 2548
2551#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2552 evpipe_init (EV_A); 2549 evpipe_init (EV_A);
2553 /* iterate over everything, in case we missed something before */ 2550 /* iterate over everything, in case we missed something before */
2554 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 2551 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
2555#endif
2556 } 2552 }
2553#endif
2557 2554
2558 postfork = 0; 2555 postfork = 0;
2559} 2556}
2560 2557
2561#if EV_MULTIPLICITY 2558#if EV_MULTIPLICITY
3530#if EV_MULTIPLICITY 3527#if EV_MULTIPLICITY
3531 assert (("libev: a signal must not be attached to two different loops", 3528 assert (("libev: a signal must not be attached to two different loops",
3532 !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); 3529 !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop));
3533 3530
3534 signals [w->signum - 1].loop = EV_A; 3531 signals [w->signum - 1].loop = EV_A;
3532 ECB_MEMORY_FENCE_RELEASE;
3535#endif 3533#endif
3536 3534
3537 EV_FREQUENT_CHECK; 3535 EV_FREQUENT_CHECK;
3538 3536
3539#if EV_USE_SIGNALFD 3537#if EV_USE_SIGNALFD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines