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

Comparing libev/ev.c (file contents):
Revision 1.303 by root, Sun Jul 19 01:36:34 2009 UTC vs.
Revision 1.313 by root, Wed Aug 19 23:44:51 2009 UTC

186# endif 186# endif
187#endif 187#endif
188 188
189/* this block tries to deduce configuration from header-defined symbols and defaults */ 189/* this block tries to deduce configuration from header-defined symbols and defaults */
190 190
191/* try to deduce the maximum number of signals on this platform */
192#if defined (EV_NSIG)
193/* use what's provided */
194#elif defined (NSIG)
195# define EV_NSIG (NSIG)
196#elif defined(_NSIG)
197# define EV_NSIG (_NSIG)
198#elif defined (SIGMAX)
199# define EV_NSIG (SIGMAX+1)
200#elif defined (SIG_MAX)
201# define EV_NSIG (SIG_MAX+1)
202#elif defined (_SIG_MAX)
203# define EV_NSIG (_SIG_MAX+1)
204#elif defined (MAXSIG)
205# define EV_NSIG (MAXSIG+1)
206#elif defined (MAX_SIG)
207# define EV_NSIG (MAX_SIG+1)
208#elif defined (SIGARRAYSIZE)
209# define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */
210#elif defined (_sys_nsig)
211# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */
212#else
213# error "unable to find value for NSIG, please report"
214/* to make it compile regardless, just remove the above line */
215# define EV_NSIG 65
216#endif
217
191#ifndef EV_USE_CLOCK_SYSCALL 218#ifndef EV_USE_CLOCK_SYSCALL
192# if __linux && __GLIBC__ >= 2 219# if __linux && __GLIBC__ >= 2
193# define EV_USE_CLOCK_SYSCALL 1 220# define EV_USE_CLOCK_SYSCALL 1
194# else 221# else
195# define EV_USE_CLOCK_SYSCALL 0 222# define EV_USE_CLOCK_SYSCALL 0
359# include <stdint.h> 386# include <stdint.h>
360# ifndef EFD_NONBLOCK 387# ifndef EFD_NONBLOCK
361# define EFD_NONBLOCK O_NONBLOCK 388# define EFD_NONBLOCK O_NONBLOCK
362# endif 389# endif
363# ifndef EFD_CLOEXEC 390# ifndef EFD_CLOEXEC
391# ifdef O_CLOEXEC
364# define EFD_CLOEXEC O_CLOEXEC 392# define EFD_CLOEXEC O_CLOEXEC
393# else
394# define EFD_CLOEXEC 02000000
395# endif
365# endif 396# endif
366# ifdef __cplusplus 397# ifdef __cplusplus
367extern "C" { 398extern "C" {
368# endif 399# endif
369int eventfd (unsigned int initval, int flags); 400int eventfd (unsigned int initval, int flags);
445 476
446#if EV_USE_MONOTONIC 477#if EV_USE_MONOTONIC
447static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 478static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
448#endif 479#endif
449 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
450#ifdef _WIN32 491#ifdef _WIN32
451# include "ev_win32.c" 492# include "ev_win32.c"
452#endif 493#endif
453 494
454/*****************************************************************************/ 495/*****************************************************************************/
845 886
846#if EV_SELECT_IS_WINSOCKET 887#if EV_SELECT_IS_WINSOCKET
847 if (events) 888 if (events)
848 { 889 {
849 unsigned long arg; 890 unsigned long arg;
850 #ifdef EV_FD_TO_WIN32_HANDLE
851 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); 891 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
852 #else
853 anfd->handle = _get_osfhandle (fd);
854 #endif
855 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));
856 } 893 }
857#endif 894#endif
858 895
859 { 896 {
930 967
931 for (fd = anfdmax; fd--; ) 968 for (fd = anfdmax; fd--; )
932 if (anfds [fd].events) 969 if (anfds [fd].events)
933 { 970 {
934 fd_kill (EV_A_ fd); 971 fd_kill (EV_A_ fd);
935 return; 972 break;
936 } 973 }
937} 974}
938 975
939/* 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 */
940static void noinline 977static void noinline
1030 1067
1031 for (;;) 1068 for (;;)
1032 { 1069 {
1033 int c = k << 1; 1070 int c = k << 1;
1034 1071
1035 if (c > N + HEAP0 - 1) 1072 if (c >= N + HEAP0)
1036 break; 1073 break;
1037 1074
1038 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])
1039 ? 1 : 0; 1076 ? 1 : 0;
1040 1077
1076 1113
1077/* move an element suitably so it is in a correct place */ 1114/* move an element suitably so it is in a correct place */
1078inline_size void 1115inline_size void
1079adjustheap (ANHE *heap, int N, int k) 1116adjustheap (ANHE *heap, int N, int k)
1080{ 1117{
1081 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)]))
1082 upheap (heap, k); 1119 upheap (heap, k);
1083 else 1120 else
1084 downheap (heap, N, k); 1121 downheap (heap, N, k);
1085} 1122}
1086 1123
1099/*****************************************************************************/ 1136/*****************************************************************************/
1100 1137
1101/* associate signal watchers to a signal signal */ 1138/* associate signal watchers to a signal signal */
1102typedef struct 1139typedef struct
1103{ 1140{
1141 EV_ATOMIC_T pending;
1142#if EV_MULTIPLICITY
1143 EV_P;
1144#endif
1104 WL head; 1145 WL head;
1105 EV_ATOMIC_T gotsig;
1106} ANSIG; 1146} ANSIG;
1107 1147
1108static ANSIG *signals; 1148static ANSIG signals [EV_NSIG - 1];
1109static int signalmax;
1110
1111static EV_ATOMIC_T gotsig;
1112 1149
1113/*****************************************************************************/ 1150/*****************************************************************************/
1114 1151
1115/* used to prepare libev internal fd's */ 1152/* used to prepare libev internal fd's */
1116/* this is not fork-safe */ 1153/* this is not fork-safe */
1184/* called whenever the libev signal pipe */ 1221/* called whenever the libev signal pipe */
1185/* got some events (signal, async) */ 1222/* got some events (signal, async) */
1186static void 1223static void
1187pipecb (EV_P_ ev_io *iow, int revents) 1224pipecb (EV_P_ ev_io *iow, int revents)
1188{ 1225{
1226 int i;
1227
1189#if EV_USE_EVENTFD 1228#if EV_USE_EVENTFD
1190 if (evfd >= 0) 1229 if (evfd >= 0)
1191 { 1230 {
1192 uint64_t counter; 1231 uint64_t counter;
1193 read (evfd, &counter, sizeof (uint64_t)); 1232 read (evfd, &counter, sizeof (uint64_t));
1197 { 1236 {
1198 char dummy; 1237 char dummy;
1199 read (evpipe [0], &dummy, 1); 1238 read (evpipe [0], &dummy, 1);
1200 } 1239 }
1201 1240
1202 if (gotsig && ev_is_default_loop (EV_A)) 1241 if (sig_pending)
1203 { 1242 {
1204 int signum; 1243 sig_pending = 0;
1205 gotsig = 0;
1206 1244
1207 for (signum = signalmax; signum--; ) 1245 for (i = EV_NSIG - 1; i--; )
1208 if (signals [signum].gotsig) 1246 if (expect_false (signals [i].pending))
1209 ev_feed_signal_event (EV_A_ signum + 1); 1247 ev_feed_signal_event (EV_A_ i + 1);
1210 } 1248 }
1211 1249
1212#if EV_ASYNC_ENABLE 1250#if EV_ASYNC_ENABLE
1213 if (gotasync) 1251 if (async_pending)
1214 { 1252 {
1215 int i; 1253 async_pending = 0;
1216 gotasync = 0;
1217 1254
1218 for (i = asynccnt; i--; ) 1255 for (i = asynccnt; i--; )
1219 if (asyncs [i]->sent) 1256 if (asyncs [i]->sent)
1220 { 1257 {
1221 asyncs [i]->sent = 0; 1258 asyncs [i]->sent = 0;
1229 1266
1230static void 1267static void
1231ev_sighandler (int signum) 1268ev_sighandler (int signum)
1232{ 1269{
1233#if EV_MULTIPLICITY 1270#if EV_MULTIPLICITY
1234 struct ev_loop *loop = &default_loop_struct; 1271 EV_P = signals [signum - 1].loop;
1235#endif 1272#endif
1236 1273
1237#if _WIN32 1274#if _WIN32
1238 signal (signum, ev_sighandler); 1275 signal (signum, ev_sighandler);
1239#endif 1276#endif
1240 1277
1241 signals [signum - 1].gotsig = 1; 1278 signals [signum - 1].pending = 1;
1242 evpipe_write (EV_A_ &gotsig); 1279 evpipe_write (EV_A_ &sig_pending);
1243} 1280}
1244 1281
1245void noinline 1282void noinline
1246ev_feed_signal_event (EV_P_ int signum) 1283ev_feed_signal_event (EV_P_ int signum)
1247{ 1284{
1248 WL w; 1285 WL w;
1249 1286
1287 if (expect_false (signum <= 0 || signum > EV_NSIG))
1288 return;
1289
1290 --signum;
1291
1250#if EV_MULTIPLICITY 1292#if EV_MULTIPLICITY
1251 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 */
1252#endif 1294 /* or, likely more useful, feeding a signal nobody is waiting for */
1253 1295
1254 --signum; 1296 if (expect_false (signals [signum].loop != EV_A))
1255
1256 if (signum < 0 || signum >= signalmax)
1257 return; 1297 return;
1298#endif
1258 1299
1259 signals [signum].gotsig = 0; 1300 signals [signum].pending = 0;
1260 1301
1261 for (w = signals [signum].head; w; w = w->next) 1302 for (w = signals [signum].head; w; w = w->next)
1262 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 1303 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
1263} 1304}
1264 1305
1265#if EV_USE_SIGNALFD 1306#if EV_USE_SIGNALFD
1266static void 1307static void
1267sigfdcb (EV_P_ ev_io *iow, int revents) 1308sigfdcb (EV_P_ ev_io *iow, int revents)
1268{ 1309{
1269 struct signalfd_siginfo si[4], *sip; 1310 struct signalfd_siginfo si[2], *sip; /* these structs are big */
1270 1311
1271 for (;;) 1312 for (;;)
1272 { 1313 {
1273 ssize_t res = read (sigfd, si, sizeof (si)); 1314 ssize_t res = read (sigfd, si, sizeof (si));
1274 1315
1508 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 1549 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
1509 have_monotonic = 1; 1550 have_monotonic = 1;
1510 } 1551 }
1511#endif 1552#endif
1512 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
1513 ev_rt_now = ev_time (); 1565 ev_rt_now = ev_time ();
1514 mn_now = get_clock (); 1566 mn_now = get_clock ();
1515 now_floor = mn_now; 1567 now_floor = mn_now;
1516 rtmn_diff = ev_rt_now - mn_now; 1568 rtmn_diff = ev_rt_now - mn_now;
1517#if EV_MINIMAL < 2 1569#if EV_MINIMAL < 2
1520 1572
1521 io_blocktime = 0.; 1573 io_blocktime = 0.;
1522 timeout_blocktime = 0.; 1574 timeout_blocktime = 0.;
1523 backend = 0; 1575 backend = 0;
1524 backend_fd = -1; 1576 backend_fd = -1;
1525 gotasync = 0; 1577 sig_pending = 0;
1578#if EV_ASYNC_ENABLE
1579 async_pending = 0;
1580#endif
1526#if EV_USE_INOTIFY 1581#if EV_USE_INOTIFY
1527 fs_fd = -2; 1582 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
1528#endif 1583#endif
1529#if EV_USE_SIGNALFD 1584#if EV_USE_SIGNALFD
1530 sigfd = -2; 1585 sigfd = flags & EVFLAG_NOSIGFD ? -1 : -2;
1531#endif 1586#endif
1532
1533 /* pid check not overridable via env */
1534#ifndef _WIN32
1535 if (flags & EVFLAG_FORKCHECK)
1536 curpid = getpid ();
1537#endif
1538
1539 if (!(flags & EVFLAG_NOENV)
1540 && !enable_secure ()
1541 && getenv ("LIBEV_FLAGS"))
1542 flags = atoi (getenv ("LIBEV_FLAGS"));
1543 1587
1544 if (!(flags & 0x0000ffffU)) 1588 if (!(flags & 0x0000ffffU))
1545 flags |= ev_recommended_backends (); 1589 flags |= ev_recommended_backends ();
1546 1590
1547#if EV_USE_PORT 1591#if EV_USE_PORT
1583 close (evfd); 1627 close (evfd);
1584#endif 1628#endif
1585 1629
1586 if (evpipe [0] >= 0) 1630 if (evpipe [0] >= 0)
1587 { 1631 {
1588 close (evpipe [0]); 1632 EV_WIN32_CLOSE_FD (evpipe [0]);
1589 close (evpipe [1]); 1633 EV_WIN32_CLOSE_FD (evpipe [1]);
1590 } 1634 }
1591 } 1635 }
1592 1636
1593#if EV_USE_SIGNALFD 1637#if EV_USE_SIGNALFD
1594 if (ev_is_active (&sigfd_w)) 1638 if (ev_is_active (&sigfd_w))
1630#if EV_IDLE_ENABLE 1674#if EV_IDLE_ENABLE
1631 array_free (idle, [i]); 1675 array_free (idle, [i]);
1632#endif 1676#endif
1633 } 1677 }
1634 1678
1635 ev_free (anfds); anfdmax = 0; 1679 ev_free (anfds); anfds = 0; anfdmax = 0;
1636 1680
1637 /* have to use the microsoft-never-gets-it-right macro */ 1681 /* have to use the microsoft-never-gets-it-right macro */
1638 array_free (rfeed, EMPTY); 1682 array_free (rfeed, EMPTY);
1639 array_free (fdchange, EMPTY); 1683 array_free (fdchange, EMPTY);
1640 array_free (timer, EMPTY); 1684 array_free (timer, EMPTY);
1675 1719
1676 if (ev_is_active (&pipe_w)) 1720 if (ev_is_active (&pipe_w))
1677 { 1721 {
1678 /* this "locks" the handlers against writing to the pipe */ 1722 /* this "locks" the handlers against writing to the pipe */
1679 /* while we modify the fd vars */ 1723 /* while we modify the fd vars */
1680 gotsig = 1; 1724 sig_pending = 1;
1681#if EV_ASYNC_ENABLE 1725#if EV_ASYNC_ENABLE
1682 gotasync = 1; 1726 async_pending = 1;
1683#endif 1727#endif
1684 1728
1685 ev_ref (EV_A); 1729 ev_ref (EV_A);
1686 ev_io_stop (EV_A_ &pipe_w); 1730 ev_io_stop (EV_A_ &pipe_w);
1687 1731
1690 close (evfd); 1734 close (evfd);
1691#endif 1735#endif
1692 1736
1693 if (evpipe [0] >= 0) 1737 if (evpipe [0] >= 0)
1694 { 1738 {
1695 close (evpipe [0]); 1739 EV_WIN32_CLOSE_FD (evpipe [0]);
1696 close (evpipe [1]); 1740 EV_WIN32_CLOSE_FD (evpipe [1]);
1697 } 1741 }
1698 1742
1699 evpipe_init (EV_A); 1743 evpipe_init (EV_A);
1700 /* now iterate over everything, in case we missed something */ 1744 /* now iterate over everything, in case we missed something */
1701 pipecb (EV_A_ &pipe_w, EV_READ); 1745 pipecb (EV_A_ &pipe_w, EV_READ);
1707#if EV_MULTIPLICITY 1751#if EV_MULTIPLICITY
1708 1752
1709struct ev_loop * 1753struct ev_loop *
1710ev_loop_new (unsigned int flags) 1754ev_loop_new (unsigned int flags)
1711{ 1755{
1712 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));
1713 1757
1714 memset (loop, 0, sizeof (struct ev_loop)); 1758 memset (EV_A, 0, sizeof (struct ev_loop));
1715 loop_init (EV_A_ flags); 1759 loop_init (EV_A_ flags);
1716 1760
1717 if (ev_backend (EV_A)) 1761 if (ev_backend (EV_A))
1718 return loop; 1762 return EV_A;
1719 1763
1720 return 0; 1764 return 0;
1721} 1765}
1722 1766
1723void 1767void
1827 assert (checkmax >= checkcnt); 1871 assert (checkmax >= checkcnt);
1828 array_verify (EV_A_ (W *)checks, checkcnt); 1872 array_verify (EV_A_ (W *)checks, checkcnt);
1829 1873
1830# if 0 1874# if 0
1831 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)
1832 for (signum = signalmax; signum--; ) if (signals [signum].gotsig) 1876 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending)
1833# endif 1877# endif
1834#endif 1878#endif
1835} 1879}
1836#endif 1880#endif
1837 1881
1844#endif 1888#endif
1845{ 1889{
1846 if (!ev_default_loop_ptr) 1890 if (!ev_default_loop_ptr)
1847 { 1891 {
1848#if EV_MULTIPLICITY 1892#if EV_MULTIPLICITY
1849 struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; 1893 EV_P = ev_default_loop_ptr = &default_loop_struct;
1850#else 1894#else
1851 ev_default_loop_ptr = 1; 1895 ev_default_loop_ptr = 1;
1852#endif 1896#endif
1853 1897
1854 loop_init (EV_A_ flags); 1898 loop_init (EV_A_ flags);
1871 1915
1872void 1916void
1873ev_default_destroy (void) 1917ev_default_destroy (void)
1874{ 1918{
1875#if EV_MULTIPLICITY 1919#if EV_MULTIPLICITY
1876 struct ev_loop *loop = ev_default_loop_ptr; 1920 EV_P = ev_default_loop_ptr;
1877#endif 1921#endif
1878 1922
1879 ev_default_loop_ptr = 0; 1923 ev_default_loop_ptr = 0;
1880 1924
1881#ifndef _WIN32 1925#ifndef _WIN32
1888 1932
1889void 1933void
1890ev_default_fork (void) 1934ev_default_fork (void)
1891{ 1935{
1892#if EV_MULTIPLICITY 1936#if EV_MULTIPLICITY
1893 struct ev_loop *loop = ev_default_loop_ptr; 1937 EV_P = ev_default_loop_ptr;
1894#endif 1938#endif
1895 1939
1896 postfork = 1; /* must be in line with ev_loop_fork */ 1940 postfork = 1; /* must be in line with ev_loop_fork */
1897} 1941}
1898 1942
2364inline_size void 2408inline_size void
2365wlist_del (WL *head, WL elem) 2409wlist_del (WL *head, WL elem)
2366{ 2410{
2367 while (*head) 2411 while (*head)
2368 { 2412 {
2369 if (*head == elem) 2413 if (expect_true (*head == elem))
2370 { 2414 {
2371 *head = elem->next; 2415 *head = elem->next;
2372 return; 2416 break;
2373 } 2417 }
2374 2418
2375 head = &(*head)->next; 2419 head = &(*head)->next;
2376 } 2420 }
2377} 2421}
2631#endif 2675#endif
2632 2676
2633void noinline 2677void noinline
2634ev_signal_start (EV_P_ ev_signal *w) 2678ev_signal_start (EV_P_ ev_signal *w)
2635{ 2679{
2636#if EV_MULTIPLICITY
2637 assert (("libev: signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
2638#endif
2639 if (expect_false (ev_is_active (w))) 2680 if (expect_false (ev_is_active (w)))
2640 return; 2681 return;
2641 2682
2642 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
2643 2691
2644 EV_FREQUENT_CHECK; 2692 EV_FREQUENT_CHECK;
2645 2693
2646#if EV_USE_SIGNALFD 2694#if EV_USE_SIGNALFD
2647 if (sigfd == -2) 2695 if (sigfd == -2)
2669 sigaddset (&sigfd_set, w->signum); 2717 sigaddset (&sigfd_set, w->signum);
2670 sigprocmask (SIG_BLOCK, &sigfd_set, 0); 2718 sigprocmask (SIG_BLOCK, &sigfd_set, 0);
2671 2719
2672 signalfd (sigfd, &sigfd_set, 0); 2720 signalfd (sigfd, &sigfd_set, 0);
2673 } 2721 }
2674 else
2675#endif 2722#endif
2676 evpipe_init (EV_A);
2677
2678 {
2679#ifndef _WIN32
2680 sigset_t full, prev;
2681 sigfillset (&full);
2682 sigprocmask (SIG_SETMASK, &full, &prev);
2683#endif
2684
2685 array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero);
2686
2687#ifndef _WIN32
2688 if (sigfd < 0)/*TODO*/
2689 sigdelset (&prev, w->signum);
2690 sigprocmask (SIG_SETMASK, &prev, 0);
2691#endif
2692 }
2693 2723
2694 ev_start (EV_A_ (W)w, 1); 2724 ev_start (EV_A_ (W)w, 1);
2695 wlist_add (&signals [w->signum - 1].head, (WL)w); 2725 wlist_add (&signals [w->signum - 1].head, (WL)w);
2696 2726
2697 if (!((WL)w)->next) 2727 if (!((WL)w)->next)
2728# if EV_USE_SIGNALFD
2729 if (sigfd < 0) /*TODO*/
2730# endif
2698 { 2731 {
2699#if _WIN32 2732# if _WIN32
2700 signal (w->signum, ev_sighandler); 2733 signal (w->signum, ev_sighandler);
2701#else 2734# else
2702 if (sigfd < 0) /*TODO*/
2703 {
2704 struct sigaction sa = { }; 2735 struct sigaction sa;
2736
2737 evpipe_init (EV_A);
2738
2705 sa.sa_handler = ev_sighandler; 2739 sa.sa_handler = ev_sighandler;
2706 sigfillset (&sa.sa_mask); 2740 sigfillset (&sa.sa_mask);
2707 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 */
2708 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
2709 } 2748 }
2710#endif
2711 }
2712 2749
2713 EV_FREQUENT_CHECK; 2750 EV_FREQUENT_CHECK;
2714} 2751}
2715 2752
2716void noinline 2753void noinline
2724 2761
2725 wlist_del (&signals [w->signum - 1].head, (WL)w); 2762 wlist_del (&signals [w->signum - 1].head, (WL)w);
2726 ev_stop (EV_A_ (W)w); 2763 ev_stop (EV_A_ (W)w);
2727 2764
2728 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
2729#if EV_USE_SIGNALFD 2770#if EV_USE_SIGNALFD
2730 if (sigfd >= 0) 2771 if (sigfd >= 0)
2731 { 2772 {
2732 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D 2773 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D
2733 sigdelset (&sigfd_set, w->signum); 2774 sigdelset (&sigfd_set, w->signum);
2734 signalfd (sigfd, &sigfd_set, 0); 2775 signalfd (sigfd, &sigfd_set, 0);
2735 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D 2776 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D
2736 /*TODO: maybe unblock signal? */ 2777 /*TODO: maybe unblock signal? */
2737 } 2778 }
2738 else 2779 else
2739#endif 2780#endif
2740 signal (w->signum, SIG_DFL); 2781 signal (w->signum, SIG_DFL);
2782 }
2741 2783
2742 EV_FREQUENT_CHECK; 2784 EV_FREQUENT_CHECK;
2743} 2785}
2744 2786
2745void 2787void
2825 } 2867 }
2826 } 2868 }
2827 2869
2828 if (w->wd >= 0) 2870 if (w->wd >= 0)
2829 { 2871 {
2872 struct statfs sfs;
2873
2830 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);
2831 2875
2832 /* 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 */
2833 /* 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 */
2834 /* also do poll on <2.6.25, but with normal frequency */ 2878 /* also do poll on <2.6.25, but with normal frequency */
2835 struct statfs sfs;
2836 2879
2837 if (fs_2625 && !statfs (w->path, &sfs)) 2880 if (fs_2625 && !statfs (w->path, &sfs))
2838 if (sfs.f_type == 0x1373 /* devfs */ 2881 if (sfs.f_type == 0x1373 /* devfs */
2839 || sfs.f_type == 0xEF53 /* ext2/3 */ 2882 || sfs.f_type == 0xEF53 /* ext2/3 */
2840 || sfs.f_type == 0x3153464a /* jfs */ 2883 || sfs.f_type == 0x3153464a /* jfs */
3225embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) 3268embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents)
3226{ 3269{
3227 ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); 3270 ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare));
3228 3271
3229 { 3272 {
3230 struct ev_loop *loop = w->other; 3273 EV_P = w->other;
3231 3274
3232 while (fdchangecnt) 3275 while (fdchangecnt)
3233 { 3276 {
3234 fd_reify (EV_A); 3277 fd_reify (EV_A);
3235 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3278 ev_loop (EV_A_ EVLOOP_NONBLOCK);
3243 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));
3244 3287
3245 ev_embed_stop (EV_A_ w); 3288 ev_embed_stop (EV_A_ w);
3246 3289
3247 { 3290 {
3248 struct ev_loop *loop = w->other; 3291 EV_P = w->other;
3249 3292
3250 ev_loop_fork (EV_A); 3293 ev_loop_fork (EV_A);
3251 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3294 ev_loop (EV_A_ EVLOOP_NONBLOCK);
3252 } 3295 }
3253 3296
3267{ 3310{
3268 if (expect_false (ev_is_active (w))) 3311 if (expect_false (ev_is_active (w)))
3269 return; 3312 return;
3270 3313
3271 { 3314 {
3272 struct ev_loop *loop = w->other; 3315 EV_P = w->other;
3273 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 ()));
3274 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);
3275 } 3318 }
3276 3319
3277 EV_FREQUENT_CHECK; 3320 EV_FREQUENT_CHECK;
3389 3432
3390void 3433void
3391ev_async_send (EV_P_ ev_async *w) 3434ev_async_send (EV_P_ ev_async *w)
3392{ 3435{
3393 w->sent = 1; 3436 w->sent = 1;
3394 evpipe_write (EV_A_ &gotasync); 3437 evpipe_write (EV_A_ &async_pending);
3395} 3438}
3396#endif 3439#endif
3397 3440
3398/*****************************************************************************/ 3441/*****************************************************************************/
3399 3442
3548 if (types & EV_CHECK) 3591 if (types & EV_CHECK)
3549 for (i = checkcnt; i--; ) 3592 for (i = checkcnt; i--; )
3550 cb (EV_A_ EV_CHECK, checks [i]); 3593 cb (EV_A_ EV_CHECK, checks [i]);
3551 3594
3552 if (types & EV_SIGNAL) 3595 if (types & EV_SIGNAL)
3553 for (i = 0; i < signalmax; ++i) 3596 for (i = 0; i < EV_NSIG - 1; ++i)
3554 for (wl = signals [i].head; wl; ) 3597 for (wl = signals [i].head; wl; )
3555 { 3598 {
3556 wn = wl->next; 3599 wn = wl->next;
3557 cb (EV_A_ EV_SIGNAL, wl); 3600 cb (EV_A_ EV_SIGNAL, wl);
3558 wl = wn; 3601 wl = wn;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines