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

Comparing libev/ev.c (file contents):
Revision 1.305 by root, Sun Jul 19 03:49:04 2009 UTC vs.
Revision 1.313 by root, Wed Aug 19 23:44:51 2009 UTC

210#elif defined (_sys_nsig) 210#elif defined (_sys_nsig)
211# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ 211# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */
212#else 212#else
213# error "unable to find value for NSIG, please report" 213# error "unable to find value for NSIG, please report"
214/* to make it compile regardless, just remove the above line */ 214/* to make it compile regardless, just remove the above line */
215# define EV_NSIG 64 215# define EV_NSIG 65
216#endif 216#endif
217 217
218/* Default to some arbitrary number that's big enough to get most
219 of the common signals.
220*/
221#ifndef NSIG
222# define NSIG 50
223#endif
224/* <-- NSIG logic from Configure */
225#ifndef EV_USE_CLOCK_SYSCALL 218#ifndef EV_USE_CLOCK_SYSCALL
226# if __linux && __GLIBC__ >= 2 219# if __linux && __GLIBC__ >= 2
227# define EV_USE_CLOCK_SYSCALL 1 220# define EV_USE_CLOCK_SYSCALL 1
228# else 221# else
229# define EV_USE_CLOCK_SYSCALL 0 222# define EV_USE_CLOCK_SYSCALL 0
393# include <stdint.h> 386# include <stdint.h>
394# ifndef EFD_NONBLOCK 387# ifndef EFD_NONBLOCK
395# define EFD_NONBLOCK O_NONBLOCK 388# define EFD_NONBLOCK O_NONBLOCK
396# endif 389# endif
397# ifndef EFD_CLOEXEC 390# ifndef EFD_CLOEXEC
391# ifdef O_CLOEXEC
398# define EFD_CLOEXEC O_CLOEXEC 392# define EFD_CLOEXEC O_CLOEXEC
393# else
394# define EFD_CLOEXEC 02000000
395# endif
399# endif 396# endif
400# ifdef __cplusplus 397# ifdef __cplusplus
401extern "C" { 398extern "C" {
402# endif 399# endif
403int eventfd (unsigned int initval, int flags); 400int eventfd (unsigned int initval, int flags);
479 476
480#if EV_USE_MONOTONIC 477#if EV_USE_MONOTONIC
481static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 478static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
482#endif 479#endif
483 480
481#ifndef EV_FD_TO_WIN32_HANDLE
482# define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd)
483#endif
484#ifndef EV_WIN32_HANDLE_TO_FD
485# define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (fd, 0)
486#endif
487#ifndef EV_WIN32_CLOSE_FD
488# define EV_WIN32_CLOSE_FD(fd) close (fd)
489#endif
490
484#ifdef _WIN32 491#ifdef _WIN32
485# include "ev_win32.c" 492# include "ev_win32.c"
486#endif 493#endif
487 494
488/*****************************************************************************/ 495/*****************************************************************************/
879 886
880#if EV_SELECT_IS_WINSOCKET 887#if EV_SELECT_IS_WINSOCKET
881 if (events) 888 if (events)
882 { 889 {
883 unsigned long arg; 890 unsigned long arg;
884 #ifdef EV_FD_TO_WIN32_HANDLE
885 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); 891 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
886 #else
887 anfd->handle = _get_osfhandle (fd);
888 #endif
889 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); 892 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
890 } 893 }
891#endif 894#endif
892 895
893 { 896 {
964 967
965 for (fd = anfdmax; fd--; ) 968 for (fd = anfdmax; fd--; )
966 if (anfds [fd].events) 969 if (anfds [fd].events)
967 { 970 {
968 fd_kill (EV_A_ fd); 971 fd_kill (EV_A_ fd);
969 return; 972 break;
970 } 973 }
971} 974}
972 975
973/* usually called after fork if backend needs to re-arm all fds from scratch */ 976/* usually called after fork if backend needs to re-arm all fds from scratch */
974static void noinline 977static void noinline
1064 1067
1065 for (;;) 1068 for (;;)
1066 { 1069 {
1067 int c = k << 1; 1070 int c = k << 1;
1068 1071
1069 if (c > N + HEAP0 - 1) 1072 if (c >= N + HEAP0)
1070 break; 1073 break;
1071 1074
1072 c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) 1075 c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1])
1073 ? 1 : 0; 1076 ? 1 : 0;
1074 1077
1110 1113
1111/* move an element suitably so it is in a correct place */ 1114/* move an element suitably so it is in a correct place */
1112inline_size void 1115inline_size void
1113adjustheap (ANHE *heap, int N, int k) 1116adjustheap (ANHE *heap, int N, int k)
1114{ 1117{
1115 if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) 1118 if (k > HEAP0 && ANHE_at (heap [k]) <= ANHE_at (heap [HPARENT (k)]))
1116 upheap (heap, k); 1119 upheap (heap, k);
1117 else 1120 else
1118 downheap (heap, N, k); 1121 downheap (heap, N, k);
1119} 1122}
1120 1123
1133/*****************************************************************************/ 1136/*****************************************************************************/
1134 1137
1135/* associate signal watchers to a signal signal */ 1138/* associate signal watchers to a signal signal */
1136typedef struct 1139typedef struct
1137{ 1140{
1141 EV_ATOMIC_T pending;
1142#if EV_MULTIPLICITY
1143 EV_P;
1144#endif
1138 WL head; 1145 WL head;
1139 EV_ATOMIC_T gotsig;
1140} ANSIG; 1146} ANSIG;
1141 1147
1142static ANSIG *signals; 1148static ANSIG signals [EV_NSIG - 1];
1143static int signalmax;
1144
1145static EV_ATOMIC_T gotsig;
1146 1149
1147/*****************************************************************************/ 1150/*****************************************************************************/
1148 1151
1149/* used to prepare libev internal fd's */ 1152/* used to prepare libev internal fd's */
1150/* this is not fork-safe */ 1153/* this is not fork-safe */
1218/* called whenever the libev signal pipe */ 1221/* called whenever the libev signal pipe */
1219/* got some events (signal, async) */ 1222/* got some events (signal, async) */
1220static void 1223static void
1221pipecb (EV_P_ ev_io *iow, int revents) 1224pipecb (EV_P_ ev_io *iow, int revents)
1222{ 1225{
1226 int i;
1227
1223#if EV_USE_EVENTFD 1228#if EV_USE_EVENTFD
1224 if (evfd >= 0) 1229 if (evfd >= 0)
1225 { 1230 {
1226 uint64_t counter; 1231 uint64_t counter;
1227 read (evfd, &counter, sizeof (uint64_t)); 1232 read (evfd, &counter, sizeof (uint64_t));
1231 { 1236 {
1232 char dummy; 1237 char dummy;
1233 read (evpipe [0], &dummy, 1); 1238 read (evpipe [0], &dummy, 1);
1234 } 1239 }
1235 1240
1236 if (gotsig && ev_is_default_loop (EV_A)) 1241 if (sig_pending)
1237 { 1242 {
1238 int signum; 1243 sig_pending = 0;
1239 gotsig = 0;
1240 1244
1241 for (signum = signalmax; signum--; ) 1245 for (i = EV_NSIG - 1; i--; )
1242 if (signals [signum].gotsig) 1246 if (expect_false (signals [i].pending))
1243 ev_feed_signal_event (EV_A_ signum + 1); 1247 ev_feed_signal_event (EV_A_ i + 1);
1244 } 1248 }
1245 1249
1246#if EV_ASYNC_ENABLE 1250#if EV_ASYNC_ENABLE
1247 if (gotasync) 1251 if (async_pending)
1248 { 1252 {
1249 int i; 1253 async_pending = 0;
1250 gotasync = 0;
1251 1254
1252 for (i = asynccnt; i--; ) 1255 for (i = asynccnt; i--; )
1253 if (asyncs [i]->sent) 1256 if (asyncs [i]->sent)
1254 { 1257 {
1255 asyncs [i]->sent = 0; 1258 asyncs [i]->sent = 0;
1263 1266
1264static void 1267static void
1265ev_sighandler (int signum) 1268ev_sighandler (int signum)
1266{ 1269{
1267#if EV_MULTIPLICITY 1270#if EV_MULTIPLICITY
1268 struct ev_loop *loop = &default_loop_struct; 1271 EV_P = signals [signum - 1].loop;
1269#endif 1272#endif
1270 1273
1271#if _WIN32 1274#if _WIN32
1272 signal (signum, ev_sighandler); 1275 signal (signum, ev_sighandler);
1273#endif 1276#endif
1274 1277
1275 signals [signum - 1].gotsig = 1; 1278 signals [signum - 1].pending = 1;
1276 evpipe_write (EV_A_ &gotsig); 1279 evpipe_write (EV_A_ &sig_pending);
1277} 1280}
1278 1281
1279void noinline 1282void noinline
1280ev_feed_signal_event (EV_P_ int signum) 1283ev_feed_signal_event (EV_P_ int signum)
1281{ 1284{
1282 WL w; 1285 WL w;
1283 1286
1287 if (expect_false (signum <= 0 || signum > EV_NSIG))
1288 return;
1289
1290 --signum;
1291
1284#if EV_MULTIPLICITY 1292#if EV_MULTIPLICITY
1285 assert (("libev: feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); 1293 /* it is permissible to try to feed a signal to the wrong loop */
1286#endif 1294 /* or, likely more useful, feeding a signal nobody is waiting for */
1287 1295
1288 --signum; 1296 if (expect_false (signals [signum].loop != EV_A))
1289
1290 if (signum < 0 || signum >= signalmax)
1291 return; 1297 return;
1298#endif
1292 1299
1293 signals [signum].gotsig = 0; 1300 signals [signum].pending = 0;
1294 1301
1295 for (w = signals [signum].head; w; w = w->next) 1302 for (w = signals [signum].head; w; w = w->next)
1296 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 1303 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
1297} 1304}
1298 1305
1299#if EV_USE_SIGNALFD 1306#if EV_USE_SIGNALFD
1300static void 1307static void
1301sigfdcb (EV_P_ ev_io *iow, int revents) 1308sigfdcb (EV_P_ ev_io *iow, int revents)
1302{ 1309{
1303 struct signalfd_siginfo si[4], *sip; 1310 struct signalfd_siginfo si[2], *sip; /* these structs are big */
1304 1311
1305 for (;;) 1312 for (;;)
1306 { 1313 {
1307 ssize_t res = read (sigfd, si, sizeof (si)); 1314 ssize_t res = read (sigfd, si, sizeof (si));
1308 1315
1542 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 1549 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
1543 have_monotonic = 1; 1550 have_monotonic = 1;
1544 } 1551 }
1545#endif 1552#endif
1546 1553
1554 /* pid check not overridable via env */
1555#ifndef _WIN32
1556 if (flags & EVFLAG_FORKCHECK)
1557 curpid = getpid ();
1558#endif
1559
1560 if (!(flags & EVFLAG_NOENV)
1561 && !enable_secure ()
1562 && getenv ("LIBEV_FLAGS"))
1563 flags = atoi (getenv ("LIBEV_FLAGS"));
1564
1547 ev_rt_now = ev_time (); 1565 ev_rt_now = ev_time ();
1548 mn_now = get_clock (); 1566 mn_now = get_clock ();
1549 now_floor = mn_now; 1567 now_floor = mn_now;
1550 rtmn_diff = ev_rt_now - mn_now; 1568 rtmn_diff = ev_rt_now - mn_now;
1551#if EV_MINIMAL < 2 1569#if EV_MINIMAL < 2
1554 1572
1555 io_blocktime = 0.; 1573 io_blocktime = 0.;
1556 timeout_blocktime = 0.; 1574 timeout_blocktime = 0.;
1557 backend = 0; 1575 backend = 0;
1558 backend_fd = -1; 1576 backend_fd = -1;
1559 gotasync = 0; 1577 sig_pending = 0;
1578#if EV_ASYNC_ENABLE
1579 async_pending = 0;
1580#endif
1560#if EV_USE_INOTIFY 1581#if EV_USE_INOTIFY
1561 fs_fd = -2; 1582 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
1562#endif 1583#endif
1563#if EV_USE_SIGNALFD 1584#if EV_USE_SIGNALFD
1564 sigfd = -2; 1585 sigfd = flags & EVFLAG_NOSIGFD ? -1 : -2;
1565#endif 1586#endif
1566
1567 /* pid check not overridable via env */
1568#ifndef _WIN32
1569 if (flags & EVFLAG_FORKCHECK)
1570 curpid = getpid ();
1571#endif
1572
1573 if (!(flags & EVFLAG_NOENV)
1574 && !enable_secure ()
1575 && getenv ("LIBEV_FLAGS"))
1576 flags = atoi (getenv ("LIBEV_FLAGS"));
1577 1587
1578 if (!(flags & 0x0000ffffU)) 1588 if (!(flags & 0x0000ffffU))
1579 flags |= ev_recommended_backends (); 1589 flags |= ev_recommended_backends ();
1580 1590
1581#if EV_USE_PORT 1591#if EV_USE_PORT
1617 close (evfd); 1627 close (evfd);
1618#endif 1628#endif
1619 1629
1620 if (evpipe [0] >= 0) 1630 if (evpipe [0] >= 0)
1621 { 1631 {
1622 close (evpipe [0]); 1632 EV_WIN32_CLOSE_FD (evpipe [0]);
1623 close (evpipe [1]); 1633 EV_WIN32_CLOSE_FD (evpipe [1]);
1624 } 1634 }
1625 } 1635 }
1626 1636
1627#if EV_USE_SIGNALFD 1637#if EV_USE_SIGNALFD
1628 if (ev_is_active (&sigfd_w)) 1638 if (ev_is_active (&sigfd_w))
1709 1719
1710 if (ev_is_active (&pipe_w)) 1720 if (ev_is_active (&pipe_w))
1711 { 1721 {
1712 /* this "locks" the handlers against writing to the pipe */ 1722 /* this "locks" the handlers against writing to the pipe */
1713 /* while we modify the fd vars */ 1723 /* while we modify the fd vars */
1714 gotsig = 1; 1724 sig_pending = 1;
1715#if EV_ASYNC_ENABLE 1725#if EV_ASYNC_ENABLE
1716 gotasync = 1; 1726 async_pending = 1;
1717#endif 1727#endif
1718 1728
1719 ev_ref (EV_A); 1729 ev_ref (EV_A);
1720 ev_io_stop (EV_A_ &pipe_w); 1730 ev_io_stop (EV_A_ &pipe_w);
1721 1731
1724 close (evfd); 1734 close (evfd);
1725#endif 1735#endif
1726 1736
1727 if (evpipe [0] >= 0) 1737 if (evpipe [0] >= 0)
1728 { 1738 {
1729 close (evpipe [0]); 1739 EV_WIN32_CLOSE_FD (evpipe [0]);
1730 close (evpipe [1]); 1740 EV_WIN32_CLOSE_FD (evpipe [1]);
1731 } 1741 }
1732 1742
1733 evpipe_init (EV_A); 1743 evpipe_init (EV_A);
1734 /* now iterate over everything, in case we missed something */ 1744 /* now iterate over everything, in case we missed something */
1735 pipecb (EV_A_ &pipe_w, EV_READ); 1745 pipecb (EV_A_ &pipe_w, EV_READ);
1741#if EV_MULTIPLICITY 1751#if EV_MULTIPLICITY
1742 1752
1743struct ev_loop * 1753struct ev_loop *
1744ev_loop_new (unsigned int flags) 1754ev_loop_new (unsigned int flags)
1745{ 1755{
1746 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 1756 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
1747 1757
1748 memset (loop, 0, sizeof (struct ev_loop)); 1758 memset (EV_A, 0, sizeof (struct ev_loop));
1749 loop_init (EV_A_ flags); 1759 loop_init (EV_A_ flags);
1750 1760
1751 if (ev_backend (EV_A)) 1761 if (ev_backend (EV_A))
1752 return loop; 1762 return EV_A;
1753 1763
1754 return 0; 1764 return 0;
1755} 1765}
1756 1766
1757void 1767void
1861 assert (checkmax >= checkcnt); 1871 assert (checkmax >= checkcnt);
1862 array_verify (EV_A_ (W *)checks, checkcnt); 1872 array_verify (EV_A_ (W *)checks, checkcnt);
1863 1873
1864# if 0 1874# if 0
1865 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1875 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
1866 for (signum = signalmax; signum--; ) if (signals [signum].gotsig) 1876 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending)
1867# endif 1877# endif
1868#endif 1878#endif
1869} 1879}
1870#endif 1880#endif
1871 1881
1878#endif 1888#endif
1879{ 1889{
1880 if (!ev_default_loop_ptr) 1890 if (!ev_default_loop_ptr)
1881 { 1891 {
1882#if EV_MULTIPLICITY 1892#if EV_MULTIPLICITY
1883 struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; 1893 EV_P = ev_default_loop_ptr = &default_loop_struct;
1884#else 1894#else
1885 ev_default_loop_ptr = 1; 1895 ev_default_loop_ptr = 1;
1886#endif 1896#endif
1887 1897
1888 loop_init (EV_A_ flags); 1898 loop_init (EV_A_ flags);
1905 1915
1906void 1916void
1907ev_default_destroy (void) 1917ev_default_destroy (void)
1908{ 1918{
1909#if EV_MULTIPLICITY 1919#if EV_MULTIPLICITY
1910 struct ev_loop *loop = ev_default_loop_ptr; 1920 EV_P = ev_default_loop_ptr;
1911#endif 1921#endif
1912 1922
1913 ev_default_loop_ptr = 0; 1923 ev_default_loop_ptr = 0;
1914 1924
1915#ifndef _WIN32 1925#ifndef _WIN32
1922 1932
1923void 1933void
1924ev_default_fork (void) 1934ev_default_fork (void)
1925{ 1935{
1926#if EV_MULTIPLICITY 1936#if EV_MULTIPLICITY
1927 struct ev_loop *loop = ev_default_loop_ptr; 1937 EV_P = ev_default_loop_ptr;
1928#endif 1938#endif
1929 1939
1930 postfork = 1; /* must be in line with ev_loop_fork */ 1940 postfork = 1; /* must be in line with ev_loop_fork */
1931} 1941}
1932 1942
2398inline_size void 2408inline_size void
2399wlist_del (WL *head, WL elem) 2409wlist_del (WL *head, WL elem)
2400{ 2410{
2401 while (*head) 2411 while (*head)
2402 { 2412 {
2403 if (*head == elem) 2413 if (expect_true (*head == elem))
2404 { 2414 {
2405 *head = elem->next; 2415 *head = elem->next;
2406 return; 2416 break;
2407 } 2417 }
2408 2418
2409 head = &(*head)->next; 2419 head = &(*head)->next;
2410 } 2420 }
2411} 2421}
2665#endif 2675#endif
2666 2676
2667void noinline 2677void noinline
2668ev_signal_start (EV_P_ ev_signal *w) 2678ev_signal_start (EV_P_ ev_signal *w)
2669{ 2679{
2670#if EV_MULTIPLICITY
2671 assert (("libev: signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
2672#endif
2673 if (expect_false (ev_is_active (w))) 2680 if (expect_false (ev_is_active (w)))
2674 return; 2681 return;
2675 2682
2676 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0)); 2683 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
2684
2685#if EV_MULTIPLICITY
2686 assert (("libev: a signal must not be attached to two different loops",
2687 !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop));
2688
2689 signals [w->signum - 1].loop = EV_A;
2690#endif
2677 2691
2678 EV_FREQUENT_CHECK; 2692 EV_FREQUENT_CHECK;
2679 2693
2680#if EV_USE_SIGNALFD 2694#if EV_USE_SIGNALFD
2681 if (sigfd == -2) 2695 if (sigfd == -2)
2703 sigaddset (&sigfd_set, w->signum); 2717 sigaddset (&sigfd_set, w->signum);
2704 sigprocmask (SIG_BLOCK, &sigfd_set, 0); 2718 sigprocmask (SIG_BLOCK, &sigfd_set, 0);
2705 2719
2706 signalfd (sigfd, &sigfd_set, 0); 2720 signalfd (sigfd, &sigfd_set, 0);
2707 } 2721 }
2708 else
2709#endif
2710 evpipe_init (EV_A);
2711
2712 {
2713#ifndef _WIN32
2714 sigset_t full, prev;
2715 sigfillset (&full);
2716 sigprocmask (SIG_SETMASK, &full, &prev);
2717#endif
2718
2719 array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero);
2720
2721#ifndef _WIN32
2722# if EV_USE_SIGNALFD
2723 if (sigfd < 0)/*TODO*/
2724# endif 2722#endif
2725 sigdelset (&prev, w->signum);
2726 sigprocmask (SIG_SETMASK, &prev, 0);
2727#endif
2728 }
2729 2723
2730 ev_start (EV_A_ (W)w, 1); 2724 ev_start (EV_A_ (W)w, 1);
2731 wlist_add (&signals [w->signum - 1].head, (WL)w); 2725 wlist_add (&signals [w->signum - 1].head, (WL)w);
2732 2726
2733 if (!((WL)w)->next) 2727 if (!((WL)w)->next)
2734 {
2735#if _WIN32
2736 signal (w->signum, ev_sighandler);
2737#else
2738# if EV_USE_SIGNALFD 2728# if EV_USE_SIGNALFD
2739 if (sigfd < 0) /*TODO*/ 2729 if (sigfd < 0) /*TODO*/
2740# endif 2730# endif
2741 { 2731 {
2732# if _WIN32
2733 signal (w->signum, ev_sighandler);
2734# else
2742 struct sigaction sa = { }; 2735 struct sigaction sa;
2736
2737 evpipe_init (EV_A);
2738
2743 sa.sa_handler = ev_sighandler; 2739 sa.sa_handler = ev_sighandler;
2744 sigfillset (&sa.sa_mask); 2740 sigfillset (&sa.sa_mask);
2745 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 2741 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
2746 sigaction (w->signum, &sa, 0); 2742 sigaction (w->signum, &sa, 0);
2743
2744 sigemptyset (&sa.sa_mask);
2745 sigaddset (&sa.sa_mask, w->signum);
2746 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
2747#endif
2747 } 2748 }
2748#endif
2749 }
2750 2749
2751 EV_FREQUENT_CHECK; 2750 EV_FREQUENT_CHECK;
2752} 2751}
2753 2752
2754void noinline 2753void noinline
2762 2761
2763 wlist_del (&signals [w->signum - 1].head, (WL)w); 2762 wlist_del (&signals [w->signum - 1].head, (WL)w);
2764 ev_stop (EV_A_ (W)w); 2763 ev_stop (EV_A_ (W)w);
2765 2764
2766 if (!signals [w->signum - 1].head) 2765 if (!signals [w->signum - 1].head)
2766 {
2767#if EV_MULTIPLICITY
2768 signals [w->signum - 1].loop = 0; /* unattach from signal */
2769#endif
2767#if EV_USE_SIGNALFD 2770#if EV_USE_SIGNALFD
2768 if (sigfd >= 0) 2771 if (sigfd >= 0)
2769 { 2772 {
2770 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D 2773 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D
2771 sigdelset (&sigfd_set, w->signum); 2774 sigdelset (&sigfd_set, w->signum);
2772 signalfd (sigfd, &sigfd_set, 0); 2775 signalfd (sigfd, &sigfd_set, 0);
2773 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D 2776 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D
2774 /*TODO: maybe unblock signal? */ 2777 /*TODO: maybe unblock signal? */
2775 } 2778 }
2776 else 2779 else
2777#endif 2780#endif
2778 signal (w->signum, SIG_DFL); 2781 signal (w->signum, SIG_DFL);
2782 }
2779 2783
2780 EV_FREQUENT_CHECK; 2784 EV_FREQUENT_CHECK;
2781} 2785}
2782 2786
2783void 2787void
2863 } 2867 }
2864 } 2868 }
2865 2869
2866 if (w->wd >= 0) 2870 if (w->wd >= 0)
2867 { 2871 {
2872 struct statfs sfs;
2873
2868 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 2874 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w);
2869 2875
2870 /* now local changes will be tracked by inotify, but remote changes won't */ 2876 /* now local changes will be tracked by inotify, but remote changes won't */
2871 /* unless the filesystem it known to be local, we therefore still poll */ 2877 /* unless the filesystem it known to be local, we therefore still poll */
2872 /* also do poll on <2.6.25, but with normal frequency */ 2878 /* also do poll on <2.6.25, but with normal frequency */
2873 struct statfs sfs;
2874 2879
2875 if (fs_2625 && !statfs (w->path, &sfs)) 2880 if (fs_2625 && !statfs (w->path, &sfs))
2876 if (sfs.f_type == 0x1373 /* devfs */ 2881 if (sfs.f_type == 0x1373 /* devfs */
2877 || sfs.f_type == 0xEF53 /* ext2/3 */ 2882 || sfs.f_type == 0xEF53 /* ext2/3 */
2878 || sfs.f_type == 0x3153464a /* jfs */ 2883 || sfs.f_type == 0x3153464a /* jfs */
3263embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) 3268embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents)
3264{ 3269{
3265 ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); 3270 ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare));
3266 3271
3267 { 3272 {
3268 struct ev_loop *loop = w->other; 3273 EV_P = w->other;
3269 3274
3270 while (fdchangecnt) 3275 while (fdchangecnt)
3271 { 3276 {
3272 fd_reify (EV_A); 3277 fd_reify (EV_A);
3273 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3278 ev_loop (EV_A_ EVLOOP_NONBLOCK);
3281 ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); 3286 ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork));
3282 3287
3283 ev_embed_stop (EV_A_ w); 3288 ev_embed_stop (EV_A_ w);
3284 3289
3285 { 3290 {
3286 struct ev_loop *loop = w->other; 3291 EV_P = w->other;
3287 3292
3288 ev_loop_fork (EV_A); 3293 ev_loop_fork (EV_A);
3289 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3294 ev_loop (EV_A_ EVLOOP_NONBLOCK);
3290 } 3295 }
3291 3296
3305{ 3310{
3306 if (expect_false (ev_is_active (w))) 3311 if (expect_false (ev_is_active (w)))
3307 return; 3312 return;
3308 3313
3309 { 3314 {
3310 struct ev_loop *loop = w->other; 3315 EV_P = w->other;
3311 assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); 3316 assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
3312 ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); 3317 ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ);
3313 } 3318 }
3314 3319
3315 EV_FREQUENT_CHECK; 3320 EV_FREQUENT_CHECK;
3427 3432
3428void 3433void
3429ev_async_send (EV_P_ ev_async *w) 3434ev_async_send (EV_P_ ev_async *w)
3430{ 3435{
3431 w->sent = 1; 3436 w->sent = 1;
3432 evpipe_write (EV_A_ &gotasync); 3437 evpipe_write (EV_A_ &async_pending);
3433} 3438}
3434#endif 3439#endif
3435 3440
3436/*****************************************************************************/ 3441/*****************************************************************************/
3437 3442
3586 if (types & EV_CHECK) 3591 if (types & EV_CHECK)
3587 for (i = checkcnt; i--; ) 3592 for (i = checkcnt; i--; )
3588 cb (EV_A_ EV_CHECK, checks [i]); 3593 cb (EV_A_ EV_CHECK, checks [i]);
3589 3594
3590 if (types & EV_SIGNAL) 3595 if (types & EV_SIGNAL)
3591 for (i = 0; i < signalmax; ++i) 3596 for (i = 0; i < EV_NSIG - 1; ++i)
3592 for (wl = signals [i].head; wl; ) 3597 for (wl = signals [i].head; wl; )
3593 { 3598 {
3594 wn = wl->next; 3599 wn = wl->next;
3595 cb (EV_A_ EV_SIGNAL, wl); 3600 cb (EV_A_ EV_SIGNAL, wl);
3596 wl = wn; 3601 wl = wn;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines