… | |
… | |
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 |
367 | extern "C" { |
398 | extern "C" { |
368 | # endif |
399 | # endif |
369 | int eventfd (unsigned int initval, int flags); |
400 | int eventfd (unsigned int initval, int flags); |
… | |
… | |
930 | |
961 | |
931 | for (fd = anfdmax; fd--; ) |
962 | for (fd = anfdmax; fd--; ) |
932 | if (anfds [fd].events) |
963 | if (anfds [fd].events) |
933 | { |
964 | { |
934 | fd_kill (EV_A_ fd); |
965 | fd_kill (EV_A_ fd); |
935 | return; |
966 | break; |
936 | } |
967 | } |
937 | } |
968 | } |
938 | |
969 | |
939 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
970 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
940 | static void noinline |
971 | static void noinline |
… | |
… | |
1030 | |
1061 | |
1031 | for (;;) |
1062 | for (;;) |
1032 | { |
1063 | { |
1033 | int c = k << 1; |
1064 | int c = k << 1; |
1034 | |
1065 | |
1035 | if (c > N + HEAP0 - 1) |
1066 | if (c >= N + HEAP0) |
1036 | break; |
1067 | break; |
1037 | |
1068 | |
1038 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
1069 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
1039 | ? 1 : 0; |
1070 | ? 1 : 0; |
1040 | |
1071 | |
… | |
… | |
1076 | |
1107 | |
1077 | /* move an element suitably so it is in a correct place */ |
1108 | /* move an element suitably so it is in a correct place */ |
1078 | inline_size void |
1109 | inline_size void |
1079 | adjustheap (ANHE *heap, int N, int k) |
1110 | adjustheap (ANHE *heap, int N, int k) |
1080 | { |
1111 | { |
1081 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
1112 | if (k > HEAP0 && ANHE_at (heap [k]) <= ANHE_at (heap [HPARENT (k)])) |
1082 | upheap (heap, k); |
1113 | upheap (heap, k); |
1083 | else |
1114 | else |
1084 | downheap (heap, N, k); |
1115 | downheap (heap, N, k); |
1085 | } |
1116 | } |
1086 | |
1117 | |
… | |
… | |
1099 | /*****************************************************************************/ |
1130 | /*****************************************************************************/ |
1100 | |
1131 | |
1101 | /* associate signal watchers to a signal signal */ |
1132 | /* associate signal watchers to a signal signal */ |
1102 | typedef struct |
1133 | typedef struct |
1103 | { |
1134 | { |
|
|
1135 | EV_ATOMIC_T pending; |
|
|
1136 | #if EV_MULTIPLICITY |
|
|
1137 | EV_P; |
|
|
1138 | #endif |
1104 | WL head; |
1139 | WL head; |
1105 | EV_ATOMIC_T gotsig; |
|
|
1106 | } ANSIG; |
1140 | } ANSIG; |
1107 | |
1141 | |
1108 | static ANSIG *signals; |
1142 | static ANSIG signals [EV_NSIG - 1]; |
1109 | static int signalmax; |
|
|
1110 | |
|
|
1111 | static EV_ATOMIC_T gotsig; |
|
|
1112 | |
1143 | |
1113 | /*****************************************************************************/ |
1144 | /*****************************************************************************/ |
1114 | |
1145 | |
1115 | /* used to prepare libev internal fd's */ |
1146 | /* used to prepare libev internal fd's */ |
1116 | /* this is not fork-safe */ |
1147 | /* this is not fork-safe */ |
… | |
… | |
1184 | /* called whenever the libev signal pipe */ |
1215 | /* called whenever the libev signal pipe */ |
1185 | /* got some events (signal, async) */ |
1216 | /* got some events (signal, async) */ |
1186 | static void |
1217 | static void |
1187 | pipecb (EV_P_ ev_io *iow, int revents) |
1218 | pipecb (EV_P_ ev_io *iow, int revents) |
1188 | { |
1219 | { |
|
|
1220 | int i; |
|
|
1221 | |
1189 | #if EV_USE_EVENTFD |
1222 | #if EV_USE_EVENTFD |
1190 | if (evfd >= 0) |
1223 | if (evfd >= 0) |
1191 | { |
1224 | { |
1192 | uint64_t counter; |
1225 | uint64_t counter; |
1193 | read (evfd, &counter, sizeof (uint64_t)); |
1226 | read (evfd, &counter, sizeof (uint64_t)); |
… | |
… | |
1197 | { |
1230 | { |
1198 | char dummy; |
1231 | char dummy; |
1199 | read (evpipe [0], &dummy, 1); |
1232 | read (evpipe [0], &dummy, 1); |
1200 | } |
1233 | } |
1201 | |
1234 | |
1202 | if (gotsig && ev_is_default_loop (EV_A)) |
1235 | if (sig_pending) |
1203 | { |
1236 | { |
1204 | int signum; |
1237 | sig_pending = 0; |
1205 | gotsig = 0; |
|
|
1206 | |
1238 | |
1207 | for (signum = signalmax; signum--; ) |
1239 | for (i = EV_NSIG - 1; i--; ) |
1208 | if (signals [signum].gotsig) |
1240 | if (expect_false (signals [i].pending)) |
1209 | ev_feed_signal_event (EV_A_ signum + 1); |
1241 | ev_feed_signal_event (EV_A_ i + 1); |
1210 | } |
1242 | } |
1211 | |
1243 | |
1212 | #if EV_ASYNC_ENABLE |
1244 | #if EV_ASYNC_ENABLE |
1213 | if (gotasync) |
1245 | if (async_pending) |
1214 | { |
1246 | { |
1215 | int i; |
1247 | async_pending = 0; |
1216 | gotasync = 0; |
|
|
1217 | |
1248 | |
1218 | for (i = asynccnt; i--; ) |
1249 | for (i = asynccnt; i--; ) |
1219 | if (asyncs [i]->sent) |
1250 | if (asyncs [i]->sent) |
1220 | { |
1251 | { |
1221 | asyncs [i]->sent = 0; |
1252 | asyncs [i]->sent = 0; |
… | |
… | |
1229 | |
1260 | |
1230 | static void |
1261 | static void |
1231 | ev_sighandler (int signum) |
1262 | ev_sighandler (int signum) |
1232 | { |
1263 | { |
1233 | #if EV_MULTIPLICITY |
1264 | #if EV_MULTIPLICITY |
1234 | struct ev_loop *loop = &default_loop_struct; |
1265 | EV_P = signals [signum - 1].loop; |
1235 | #endif |
1266 | #endif |
1236 | |
1267 | |
1237 | #if _WIN32 |
1268 | #if _WIN32 |
1238 | signal (signum, ev_sighandler); |
1269 | signal (signum, ev_sighandler); |
1239 | #endif |
1270 | #endif |
1240 | |
1271 | |
1241 | signals [signum - 1].gotsig = 1; |
1272 | signals [signum - 1].pending = 1; |
1242 | evpipe_write (EV_A_ &gotsig); |
1273 | evpipe_write (EV_A_ &sig_pending); |
1243 | } |
1274 | } |
1244 | |
1275 | |
1245 | void noinline |
1276 | void noinline |
1246 | ev_feed_signal_event (EV_P_ int signum) |
1277 | ev_feed_signal_event (EV_P_ int signum) |
1247 | { |
1278 | { |
1248 | WL w; |
1279 | WL w; |
1249 | |
1280 | |
|
|
1281 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
|
|
1282 | return; |
|
|
1283 | |
|
|
1284 | --signum; |
|
|
1285 | |
1250 | #if EV_MULTIPLICITY |
1286 | #if EV_MULTIPLICITY |
1251 | assert (("libev: feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); |
1287 | /* it is permissible to try to feed a signal to the wrong loop */ |
1252 | #endif |
1288 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
1253 | |
1289 | |
1254 | --signum; |
1290 | if (expect_false (signals [signum].loop != EV_A)) |
1255 | |
|
|
1256 | if (signum < 0 || signum >= signalmax) |
|
|
1257 | return; |
1291 | return; |
|
|
1292 | #endif |
1258 | |
1293 | |
1259 | signals [signum].gotsig = 0; |
1294 | signals [signum].pending = 0; |
1260 | |
1295 | |
1261 | for (w = signals [signum].head; w; w = w->next) |
1296 | for (w = signals [signum].head; w; w = w->next) |
1262 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1297 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1263 | } |
1298 | } |
1264 | |
1299 | |
1265 | #if EV_USE_SIGNALFD |
1300 | #if EV_USE_SIGNALFD |
1266 | static void |
1301 | static void |
1267 | sigfdcb (EV_P_ ev_io *iow, int revents) |
1302 | sigfdcb (EV_P_ ev_io *iow, int revents) |
1268 | { |
1303 | { |
1269 | struct signalfd_siginfo si[4], *sip; |
1304 | struct signalfd_siginfo si[2], *sip; /* these structs are big */ |
1270 | |
1305 | |
1271 | for (;;) |
1306 | for (;;) |
1272 | { |
1307 | { |
1273 | ssize_t res = read (sigfd, si, sizeof (si)); |
1308 | ssize_t res = read (sigfd, si, sizeof (si)); |
1274 | |
1309 | |
… | |
… | |
1508 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1543 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1509 | have_monotonic = 1; |
1544 | have_monotonic = 1; |
1510 | } |
1545 | } |
1511 | #endif |
1546 | #endif |
1512 | |
1547 | |
|
|
1548 | /* pid check not overridable via env */ |
|
|
1549 | #ifndef _WIN32 |
|
|
1550 | if (flags & EVFLAG_FORKCHECK) |
|
|
1551 | curpid = getpid (); |
|
|
1552 | #endif |
|
|
1553 | |
|
|
1554 | if (!(flags & EVFLAG_NOENV) |
|
|
1555 | && !enable_secure () |
|
|
1556 | && getenv ("LIBEV_FLAGS")) |
|
|
1557 | flags = atoi (getenv ("LIBEV_FLAGS")); |
|
|
1558 | |
1513 | ev_rt_now = ev_time (); |
1559 | ev_rt_now = ev_time (); |
1514 | mn_now = get_clock (); |
1560 | mn_now = get_clock (); |
1515 | now_floor = mn_now; |
1561 | now_floor = mn_now; |
1516 | rtmn_diff = ev_rt_now - mn_now; |
1562 | rtmn_diff = ev_rt_now - mn_now; |
1517 | #if EV_MINIMAL < 2 |
1563 | #if EV_MINIMAL < 2 |
… | |
… | |
1520 | |
1566 | |
1521 | io_blocktime = 0.; |
1567 | io_blocktime = 0.; |
1522 | timeout_blocktime = 0.; |
1568 | timeout_blocktime = 0.; |
1523 | backend = 0; |
1569 | backend = 0; |
1524 | backend_fd = -1; |
1570 | backend_fd = -1; |
1525 | gotasync = 0; |
1571 | sig_pending = 0; |
|
|
1572 | #if EV_ASYNC_ENABLE |
|
|
1573 | async_pending = 0; |
|
|
1574 | #endif |
1526 | #if EV_USE_INOTIFY |
1575 | #if EV_USE_INOTIFY |
1527 | fs_fd = -2; |
1576 | fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; |
1528 | #endif |
1577 | #endif |
1529 | #if EV_USE_SIGNALFD |
1578 | #if EV_USE_SIGNALFD |
1530 | sigfd = -2; |
1579 | sigfd = flags & EVFLAG_NOSIGFD ? -1 : -2; |
1531 | #endif |
1580 | #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 | |
1581 | |
1544 | if (!(flags & 0x0000ffffU)) |
1582 | if (!(flags & 0x0000ffffU)) |
1545 | flags |= ev_recommended_backends (); |
1583 | flags |= ev_recommended_backends (); |
1546 | |
1584 | |
1547 | #if EV_USE_PORT |
1585 | #if EV_USE_PORT |
… | |
… | |
1630 | #if EV_IDLE_ENABLE |
1668 | #if EV_IDLE_ENABLE |
1631 | array_free (idle, [i]); |
1669 | array_free (idle, [i]); |
1632 | #endif |
1670 | #endif |
1633 | } |
1671 | } |
1634 | |
1672 | |
1635 | ev_free (anfds); anfdmax = 0; |
1673 | ev_free (anfds); anfds = 0; anfdmax = 0; |
1636 | |
1674 | |
1637 | /* have to use the microsoft-never-gets-it-right macro */ |
1675 | /* have to use the microsoft-never-gets-it-right macro */ |
1638 | array_free (rfeed, EMPTY); |
1676 | array_free (rfeed, EMPTY); |
1639 | array_free (fdchange, EMPTY); |
1677 | array_free (fdchange, EMPTY); |
1640 | array_free (timer, EMPTY); |
1678 | array_free (timer, EMPTY); |
… | |
… | |
1675 | |
1713 | |
1676 | if (ev_is_active (&pipe_w)) |
1714 | if (ev_is_active (&pipe_w)) |
1677 | { |
1715 | { |
1678 | /* this "locks" the handlers against writing to the pipe */ |
1716 | /* this "locks" the handlers against writing to the pipe */ |
1679 | /* while we modify the fd vars */ |
1717 | /* while we modify the fd vars */ |
1680 | gotsig = 1; |
1718 | sig_pending = 1; |
1681 | #if EV_ASYNC_ENABLE |
1719 | #if EV_ASYNC_ENABLE |
1682 | gotasync = 1; |
1720 | async_pending = 1; |
1683 | #endif |
1721 | #endif |
1684 | |
1722 | |
1685 | ev_ref (EV_A); |
1723 | ev_ref (EV_A); |
1686 | ev_io_stop (EV_A_ &pipe_w); |
1724 | ev_io_stop (EV_A_ &pipe_w); |
1687 | |
1725 | |
… | |
… | |
1707 | #if EV_MULTIPLICITY |
1745 | #if EV_MULTIPLICITY |
1708 | |
1746 | |
1709 | struct ev_loop * |
1747 | struct ev_loop * |
1710 | ev_loop_new (unsigned int flags) |
1748 | ev_loop_new (unsigned int flags) |
1711 | { |
1749 | { |
1712 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1750 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1713 | |
1751 | |
1714 | memset (loop, 0, sizeof (struct ev_loop)); |
1752 | memset (EV_A, 0, sizeof (struct ev_loop)); |
1715 | loop_init (EV_A_ flags); |
1753 | loop_init (EV_A_ flags); |
1716 | |
1754 | |
1717 | if (ev_backend (EV_A)) |
1755 | if (ev_backend (EV_A)) |
1718 | return loop; |
1756 | return EV_A; |
1719 | |
1757 | |
1720 | return 0; |
1758 | return 0; |
1721 | } |
1759 | } |
1722 | |
1760 | |
1723 | void |
1761 | void |
… | |
… | |
1827 | assert (checkmax >= checkcnt); |
1865 | assert (checkmax >= checkcnt); |
1828 | array_verify (EV_A_ (W *)checks, checkcnt); |
1866 | array_verify (EV_A_ (W *)checks, checkcnt); |
1829 | |
1867 | |
1830 | # if 0 |
1868 | # if 0 |
1831 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1869 | 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) |
1870 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1833 | # endif |
1871 | # endif |
1834 | #endif |
1872 | #endif |
1835 | } |
1873 | } |
1836 | #endif |
1874 | #endif |
1837 | |
1875 | |
… | |
… | |
1844 | #endif |
1882 | #endif |
1845 | { |
1883 | { |
1846 | if (!ev_default_loop_ptr) |
1884 | if (!ev_default_loop_ptr) |
1847 | { |
1885 | { |
1848 | #if EV_MULTIPLICITY |
1886 | #if EV_MULTIPLICITY |
1849 | struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; |
1887 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
1850 | #else |
1888 | #else |
1851 | ev_default_loop_ptr = 1; |
1889 | ev_default_loop_ptr = 1; |
1852 | #endif |
1890 | #endif |
1853 | |
1891 | |
1854 | loop_init (EV_A_ flags); |
1892 | loop_init (EV_A_ flags); |
… | |
… | |
1871 | |
1909 | |
1872 | void |
1910 | void |
1873 | ev_default_destroy (void) |
1911 | ev_default_destroy (void) |
1874 | { |
1912 | { |
1875 | #if EV_MULTIPLICITY |
1913 | #if EV_MULTIPLICITY |
1876 | struct ev_loop *loop = ev_default_loop_ptr; |
1914 | EV_P = ev_default_loop_ptr; |
1877 | #endif |
1915 | #endif |
1878 | |
1916 | |
1879 | ev_default_loop_ptr = 0; |
1917 | ev_default_loop_ptr = 0; |
1880 | |
1918 | |
1881 | #ifndef _WIN32 |
1919 | #ifndef _WIN32 |
… | |
… | |
1888 | |
1926 | |
1889 | void |
1927 | void |
1890 | ev_default_fork (void) |
1928 | ev_default_fork (void) |
1891 | { |
1929 | { |
1892 | #if EV_MULTIPLICITY |
1930 | #if EV_MULTIPLICITY |
1893 | struct ev_loop *loop = ev_default_loop_ptr; |
1931 | EV_P = ev_default_loop_ptr; |
1894 | #endif |
1932 | #endif |
1895 | |
1933 | |
1896 | postfork = 1; /* must be in line with ev_loop_fork */ |
1934 | postfork = 1; /* must be in line with ev_loop_fork */ |
1897 | } |
1935 | } |
1898 | |
1936 | |
… | |
… | |
2364 | inline_size void |
2402 | inline_size void |
2365 | wlist_del (WL *head, WL elem) |
2403 | wlist_del (WL *head, WL elem) |
2366 | { |
2404 | { |
2367 | while (*head) |
2405 | while (*head) |
2368 | { |
2406 | { |
2369 | if (*head == elem) |
2407 | if (expect_true (*head == elem)) |
2370 | { |
2408 | { |
2371 | *head = elem->next; |
2409 | *head = elem->next; |
2372 | return; |
2410 | break; |
2373 | } |
2411 | } |
2374 | |
2412 | |
2375 | head = &(*head)->next; |
2413 | head = &(*head)->next; |
2376 | } |
2414 | } |
2377 | } |
2415 | } |
… | |
… | |
2631 | #endif |
2669 | #endif |
2632 | |
2670 | |
2633 | void noinline |
2671 | void noinline |
2634 | ev_signal_start (EV_P_ ev_signal *w) |
2672 | ev_signal_start (EV_P_ ev_signal *w) |
2635 | { |
2673 | { |
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))) |
2674 | if (expect_false (ev_is_active (w))) |
2640 | return; |
2675 | return; |
2641 | |
2676 | |
2642 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0)); |
2677 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
|
|
2678 | |
|
|
2679 | #if EV_MULTIPLICITY |
|
|
2680 | assert (("libev: a signal must not be attached to two different loops", |
|
|
2681 | !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); |
|
|
2682 | |
|
|
2683 | signals [w->signum - 1].loop = EV_A; |
|
|
2684 | #endif |
2643 | |
2685 | |
2644 | EV_FREQUENT_CHECK; |
2686 | EV_FREQUENT_CHECK; |
2645 | |
2687 | |
2646 | #if EV_USE_SIGNALFD |
2688 | #if EV_USE_SIGNALFD |
2647 | if (sigfd == -2) |
2689 | if (sigfd == -2) |
… | |
… | |
2669 | sigaddset (&sigfd_set, w->signum); |
2711 | sigaddset (&sigfd_set, w->signum); |
2670 | sigprocmask (SIG_BLOCK, &sigfd_set, 0); |
2712 | sigprocmask (SIG_BLOCK, &sigfd_set, 0); |
2671 | |
2713 | |
2672 | signalfd (sigfd, &sigfd_set, 0); |
2714 | signalfd (sigfd, &sigfd_set, 0); |
2673 | } |
2715 | } |
2674 | else |
|
|
2675 | #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 EV_USE_SIGNALFD |
|
|
2689 | if (sigfd < 0)/*TODO*/ |
|
|
2690 | # endif |
2716 | #endif |
2691 | sigdelset (&prev, w->signum); |
|
|
2692 | sigprocmask (SIG_SETMASK, &prev, 0); |
|
|
2693 | #endif |
|
|
2694 | } |
|
|
2695 | |
2717 | |
2696 | ev_start (EV_A_ (W)w, 1); |
2718 | ev_start (EV_A_ (W)w, 1); |
2697 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
2719 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
2698 | |
2720 | |
2699 | if (!((WL)w)->next) |
2721 | if (!((WL)w)->next) |
2700 | { |
|
|
2701 | #if _WIN32 |
|
|
2702 | signal (w->signum, ev_sighandler); |
|
|
2703 | #else |
|
|
2704 | # if EV_USE_SIGNALFD |
2722 | # if EV_USE_SIGNALFD |
2705 | if (sigfd < 0) /*TODO*/ |
2723 | if (sigfd < 0) /*TODO*/ |
2706 | # endif |
2724 | # endif |
2707 | { |
2725 | { |
|
|
2726 | # if _WIN32 |
|
|
2727 | signal (w->signum, ev_sighandler); |
|
|
2728 | # else |
2708 | struct sigaction sa = { }; |
2729 | struct sigaction sa; |
|
|
2730 | |
|
|
2731 | evpipe_init (EV_A); |
|
|
2732 | |
2709 | sa.sa_handler = ev_sighandler; |
2733 | sa.sa_handler = ev_sighandler; |
2710 | sigfillset (&sa.sa_mask); |
2734 | sigfillset (&sa.sa_mask); |
2711 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2735 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2712 | sigaction (w->signum, &sa, 0); |
2736 | sigaction (w->signum, &sa, 0); |
|
|
2737 | |
|
|
2738 | sigemptyset (&sa.sa_mask); |
|
|
2739 | sigaddset (&sa.sa_mask, w->signum); |
|
|
2740 | sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); |
|
|
2741 | #endif |
2713 | } |
2742 | } |
2714 | #endif |
|
|
2715 | } |
|
|
2716 | |
2743 | |
2717 | EV_FREQUENT_CHECK; |
2744 | EV_FREQUENT_CHECK; |
2718 | } |
2745 | } |
2719 | |
2746 | |
2720 | void noinline |
2747 | void noinline |
… | |
… | |
2728 | |
2755 | |
2729 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2756 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2730 | ev_stop (EV_A_ (W)w); |
2757 | ev_stop (EV_A_ (W)w); |
2731 | |
2758 | |
2732 | if (!signals [w->signum - 1].head) |
2759 | if (!signals [w->signum - 1].head) |
|
|
2760 | { |
|
|
2761 | #if EV_MULTIPLICITY |
|
|
2762 | signals [w->signum - 1].loop = 0; /* unattach from signal */ |
|
|
2763 | #endif |
2733 | #if EV_USE_SIGNALFD |
2764 | #if EV_USE_SIGNALFD |
2734 | if (sigfd >= 0) |
2765 | if (sigfd >= 0) |
2735 | { |
2766 | { |
2736 | sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D |
2767 | sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D |
2737 | sigdelset (&sigfd_set, w->signum); |
2768 | sigdelset (&sigfd_set, w->signum); |
2738 | signalfd (sigfd, &sigfd_set, 0); |
2769 | signalfd (sigfd, &sigfd_set, 0); |
2739 | sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D |
2770 | sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D |
2740 | /*TODO: maybe unblock signal? */ |
2771 | /*TODO: maybe unblock signal? */ |
2741 | } |
2772 | } |
2742 | else |
2773 | else |
2743 | #endif |
2774 | #endif |
2744 | signal (w->signum, SIG_DFL); |
2775 | signal (w->signum, SIG_DFL); |
|
|
2776 | } |
2745 | |
2777 | |
2746 | EV_FREQUENT_CHECK; |
2778 | EV_FREQUENT_CHECK; |
2747 | } |
2779 | } |
2748 | |
2780 | |
2749 | void |
2781 | void |
… | |
… | |
3229 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3261 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3230 | { |
3262 | { |
3231 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
3263 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
3232 | |
3264 | |
3233 | { |
3265 | { |
3234 | struct ev_loop *loop = w->other; |
3266 | EV_P = w->other; |
3235 | |
3267 | |
3236 | while (fdchangecnt) |
3268 | while (fdchangecnt) |
3237 | { |
3269 | { |
3238 | fd_reify (EV_A); |
3270 | fd_reify (EV_A); |
3239 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3271 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
… | |
… | |
3247 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
3279 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
3248 | |
3280 | |
3249 | ev_embed_stop (EV_A_ w); |
3281 | ev_embed_stop (EV_A_ w); |
3250 | |
3282 | |
3251 | { |
3283 | { |
3252 | struct ev_loop *loop = w->other; |
3284 | EV_P = w->other; |
3253 | |
3285 | |
3254 | ev_loop_fork (EV_A); |
3286 | ev_loop_fork (EV_A); |
3255 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3287 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3256 | } |
3288 | } |
3257 | |
3289 | |
… | |
… | |
3271 | { |
3303 | { |
3272 | if (expect_false (ev_is_active (w))) |
3304 | if (expect_false (ev_is_active (w))) |
3273 | return; |
3305 | return; |
3274 | |
3306 | |
3275 | { |
3307 | { |
3276 | struct ev_loop *loop = w->other; |
3308 | EV_P = w->other; |
3277 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
3309 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
3278 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
3310 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
3279 | } |
3311 | } |
3280 | |
3312 | |
3281 | EV_FREQUENT_CHECK; |
3313 | EV_FREQUENT_CHECK; |
… | |
… | |
3393 | |
3425 | |
3394 | void |
3426 | void |
3395 | ev_async_send (EV_P_ ev_async *w) |
3427 | ev_async_send (EV_P_ ev_async *w) |
3396 | { |
3428 | { |
3397 | w->sent = 1; |
3429 | w->sent = 1; |
3398 | evpipe_write (EV_A_ &gotasync); |
3430 | evpipe_write (EV_A_ &async_pending); |
3399 | } |
3431 | } |
3400 | #endif |
3432 | #endif |
3401 | |
3433 | |
3402 | /*****************************************************************************/ |
3434 | /*****************************************************************************/ |
3403 | |
3435 | |
… | |
… | |
3552 | if (types & EV_CHECK) |
3584 | if (types & EV_CHECK) |
3553 | for (i = checkcnt; i--; ) |
3585 | for (i = checkcnt; i--; ) |
3554 | cb (EV_A_ EV_CHECK, checks [i]); |
3586 | cb (EV_A_ EV_CHECK, checks [i]); |
3555 | |
3587 | |
3556 | if (types & EV_SIGNAL) |
3588 | if (types & EV_SIGNAL) |
3557 | for (i = 0; i < signalmax; ++i) |
3589 | for (i = 0; i < EV_NSIG - 1; ++i) |
3558 | for (wl = signals [i].head; wl; ) |
3590 | for (wl = signals [i].head; wl; ) |
3559 | { |
3591 | { |
3560 | wn = wl->next; |
3592 | wn = wl->next; |
3561 | cb (EV_A_ EV_SIGNAL, wl); |
3593 | cb (EV_A_ EV_SIGNAL, wl); |
3562 | wl = wn; |
3594 | wl = wn; |