… | |
… | |
133 | # else |
133 | # else |
134 | # define EV_USE_INOTIFY 0 |
134 | # define EV_USE_INOTIFY 0 |
135 | # endif |
135 | # endif |
136 | # endif |
136 | # endif |
137 | |
137 | |
|
|
138 | # ifndef EV_USE_SIGNALFD |
|
|
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
140 | # define EV_USE_SIGNALFD 1 |
|
|
141 | # else |
|
|
142 | # define EV_USE_SIGNALFD 0 |
|
|
143 | # endif |
|
|
144 | # endif |
|
|
145 | |
138 | # ifndef EV_USE_EVENTFD |
146 | # ifndef EV_USE_EVENTFD |
139 | # if HAVE_EVENTFD |
147 | # if HAVE_EVENTFD |
140 | # define EV_USE_EVENTFD 1 |
148 | # define EV_USE_EVENTFD 1 |
141 | # else |
149 | # else |
142 | # define EV_USE_EVENTFD 0 |
150 | # define EV_USE_EVENTFD 0 |
… | |
… | |
263 | #ifndef EV_USE_EVENTFD |
271 | #ifndef EV_USE_EVENTFD |
264 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
272 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
265 | # define EV_USE_EVENTFD 1 |
273 | # define EV_USE_EVENTFD 1 |
266 | # else |
274 | # else |
267 | # define EV_USE_EVENTFD 0 |
275 | # define EV_USE_EVENTFD 0 |
|
|
276 | # endif |
|
|
277 | #endif |
|
|
278 | |
|
|
279 | #ifndef EV_USE_SIGNALFD |
|
|
280 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9)) |
|
|
281 | # define EV_USE_SIGNALFD 1 |
|
|
282 | # else |
|
|
283 | # define EV_USE_SIGNALFD 0 |
268 | # endif |
284 | # endif |
269 | #endif |
285 | #endif |
270 | |
286 | |
271 | #if 0 /* debugging */ |
287 | #if 0 /* debugging */ |
272 | # define EV_VERIFY 3 |
288 | # define EV_VERIFY 3 |
… | |
… | |
339 | #endif |
355 | #endif |
340 | |
356 | |
341 | #if EV_USE_EVENTFD |
357 | #if EV_USE_EVENTFD |
342 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
358 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
343 | # include <stdint.h> |
359 | # include <stdint.h> |
|
|
360 | # ifndef EFD_NONBLOCK |
|
|
361 | # define EFD_NONBLOCK O_NONBLOCK |
|
|
362 | # endif |
|
|
363 | # ifndef EFD_CLOEXEC |
|
|
364 | # define EFD_CLOEXEC O_CLOEXEC |
|
|
365 | # endif |
344 | # ifdef __cplusplus |
366 | # ifdef __cplusplus |
345 | extern "C" { |
367 | extern "C" { |
346 | # endif |
368 | # endif |
347 | int eventfd (unsigned int initval, int flags); |
369 | int eventfd (unsigned int initval, int flags); |
348 | # ifdef __cplusplus |
370 | # ifdef __cplusplus |
349 | } |
371 | } |
350 | # endif |
372 | # endif |
|
|
373 | #endif |
|
|
374 | |
|
|
375 | #if EV_USE_SIGNALFD |
|
|
376 | # include <sys/signalfd.h> |
351 | #endif |
377 | #endif |
352 | |
378 | |
353 | /**/ |
379 | /**/ |
354 | |
380 | |
355 | #if EV_VERIFY >= 3 |
381 | #if EV_VERIFY >= 3 |
… | |
… | |
490 | #define ev_malloc(size) ev_realloc (0, (size)) |
516 | #define ev_malloc(size) ev_realloc (0, (size)) |
491 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
517 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
492 | |
518 | |
493 | /*****************************************************************************/ |
519 | /*****************************************************************************/ |
494 | |
520 | |
|
|
521 | /* set in reify when reification needed */ |
|
|
522 | #define EV_ANFD_REIFY 1 |
|
|
523 | |
495 | /* file descriptor info structure */ |
524 | /* file descriptor info structure */ |
496 | typedef struct |
525 | typedef struct |
497 | { |
526 | { |
498 | WL head; |
527 | WL head; |
499 | unsigned char events; /* the events watched for */ |
528 | unsigned char events; /* the events watched for */ |
500 | unsigned char reify; /* flag set when this ANFD needs reification */ |
529 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
501 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
530 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
502 | unsigned char unused; |
531 | unsigned char unused; |
503 | #if EV_USE_EPOLL |
532 | #if EV_USE_EPOLL |
504 | unsigned int egen; /* generation counter to counter epoll bugs */ |
533 | unsigned int egen; /* generation counter to counter epoll bugs */ |
505 | #endif |
534 | #endif |
… | |
… | |
568 | static int ev_default_loop_ptr; |
597 | static int ev_default_loop_ptr; |
569 | |
598 | |
570 | #endif |
599 | #endif |
571 | |
600 | |
572 | #if EV_MINIMAL < 2 |
601 | #if EV_MINIMAL < 2 |
573 | # define EV_SUSPEND_CB if (expect_false (suspend_cb)) suspend_cb (EV_A) |
|
|
574 | # define EV_RESUME_CB if (expect_false (resume_cb )) resume_cb (EV_A) |
602 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
|
|
603 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
575 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
604 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
576 | #else |
605 | #else |
577 | # define EV_SUSPEND_CB (void)0 |
|
|
578 | # define EV_RESUME_CB (void)0 |
606 | # define EV_RELEASE_CB (void)0 |
|
|
607 | # define EV_ACQUIRE_CB (void)0 |
579 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
608 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
580 | #endif |
609 | #endif |
|
|
610 | |
|
|
611 | #define EVUNLOOP_RECURSE 0x80 |
581 | |
612 | |
582 | /*****************************************************************************/ |
613 | /*****************************************************************************/ |
583 | |
614 | |
584 | #ifndef EV_HAVE_EV_TIME |
615 | #ifndef EV_HAVE_EV_TIME |
585 | ev_tstamp |
616 | ev_tstamp |
… | |
… | |
642 | |
673 | |
643 | tv.tv_sec = (time_t)delay; |
674 | tv.tv_sec = (time_t)delay; |
644 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
675 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
645 | |
676 | |
646 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
677 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
647 | /* somehting not guaranteed by newer posix versions, but guaranteed */ |
678 | /* something not guaranteed by newer posix versions, but guaranteed */ |
648 | /* by older ones */ |
679 | /* by older ones */ |
649 | select (0, 0, 0, 0, &tv); |
680 | select (0, 0, 0, 0, &tv); |
650 | #endif |
681 | #endif |
651 | } |
682 | } |
652 | } |
683 | } |
… | |
… | |
760 | } |
791 | } |
761 | |
792 | |
762 | /*****************************************************************************/ |
793 | /*****************************************************************************/ |
763 | |
794 | |
764 | inline_speed void |
795 | inline_speed void |
765 | fd_event (EV_P_ int fd, int revents) |
796 | fd_event_nc (EV_P_ int fd, int revents) |
766 | { |
797 | { |
767 | ANFD *anfd = anfds + fd; |
798 | ANFD *anfd = anfds + fd; |
768 | ev_io *w; |
799 | ev_io *w; |
769 | |
800 | |
770 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
801 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
774 | if (ev) |
805 | if (ev) |
775 | ev_feed_event (EV_A_ (W)w, ev); |
806 | ev_feed_event (EV_A_ (W)w, ev); |
776 | } |
807 | } |
777 | } |
808 | } |
778 | |
809 | |
|
|
810 | /* do not submit kernel events for fds that have reify set */ |
|
|
811 | /* because that means they changed while we were polling for new events */ |
|
|
812 | inline_speed void |
|
|
813 | fd_event (EV_P_ int fd, int revents) |
|
|
814 | { |
|
|
815 | ANFD *anfd = anfds + fd; |
|
|
816 | |
|
|
817 | if (expect_true (!anfd->reify)) |
|
|
818 | fd_event_nc (EV_A_ fd, revents); |
|
|
819 | } |
|
|
820 | |
779 | void |
821 | void |
780 | ev_feed_fd_event (EV_P_ int fd, int revents) |
822 | ev_feed_fd_event (EV_P_ int fd, int revents) |
781 | { |
823 | { |
782 | if (fd >= 0 && fd < anfdmax) |
824 | if (fd >= 0 && fd < anfdmax) |
783 | fd_event (EV_A_ fd, revents); |
825 | fd_event_nc (EV_A_ fd, revents); |
784 | } |
826 | } |
785 | |
827 | |
786 | /* make sure the external fd watch events are in-sync */ |
828 | /* make sure the external fd watch events are in-sync */ |
787 | /* with the kernel/libev internal state */ |
829 | /* with the kernel/libev internal state */ |
788 | inline_size void |
830 | inline_size void |
… | |
… | |
903 | for (fd = 0; fd < anfdmax; ++fd) |
945 | for (fd = 0; fd < anfdmax; ++fd) |
904 | if (anfds [fd].events) |
946 | if (anfds [fd].events) |
905 | { |
947 | { |
906 | anfds [fd].events = 0; |
948 | anfds [fd].events = 0; |
907 | anfds [fd].emask = 0; |
949 | anfds [fd].emask = 0; |
908 | fd_change (EV_A_ fd, EV__IOFDSET | 1); |
950 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
909 | } |
951 | } |
910 | } |
952 | } |
911 | |
953 | |
912 | /*****************************************************************************/ |
954 | /*****************************************************************************/ |
913 | |
955 | |
… | |
… | |
1088 | evpipe_init (EV_P) |
1130 | evpipe_init (EV_P) |
1089 | { |
1131 | { |
1090 | if (!ev_is_active (&pipe_w)) |
1132 | if (!ev_is_active (&pipe_w)) |
1091 | { |
1133 | { |
1092 | #if EV_USE_EVENTFD |
1134 | #if EV_USE_EVENTFD |
|
|
1135 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
|
|
1136 | if (evfd < 0 && errno == EINVAL) |
1093 | if ((evfd = eventfd (0, 0)) >= 0) |
1137 | evfd = eventfd (0, 0); |
|
|
1138 | |
|
|
1139 | if (evfd >= 0) |
1094 | { |
1140 | { |
1095 | evpipe [0] = -1; |
1141 | evpipe [0] = -1; |
1096 | fd_intern (evfd); |
1142 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1097 | ev_io_set (&pipe_w, evfd, EV_READ); |
1143 | ev_io_set (&pipe_w, evfd, EV_READ); |
1098 | } |
1144 | } |
1099 | else |
1145 | else |
1100 | #endif |
1146 | #endif |
1101 | { |
1147 | { |
… | |
… | |
1213 | signals [signum].gotsig = 0; |
1259 | signals [signum].gotsig = 0; |
1214 | |
1260 | |
1215 | for (w = signals [signum].head; w; w = w->next) |
1261 | for (w = signals [signum].head; w; w = w->next) |
1216 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1262 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1217 | } |
1263 | } |
|
|
1264 | |
|
|
1265 | #if EV_USE_SIGNALFD |
|
|
1266 | static void |
|
|
1267 | sigfdcb (EV_P_ ev_io *iow, int revents) |
|
|
1268 | { |
|
|
1269 | struct signalfd_siginfo si[4], *sip; |
|
|
1270 | |
|
|
1271 | for (;;) |
|
|
1272 | { |
|
|
1273 | ssize_t res = read (sigfd, si, sizeof (si)); |
|
|
1274 | |
|
|
1275 | /* not ISO-C, as res might be -1, but works with SuS */ |
|
|
1276 | for (sip = si; (char *)sip < (char *)si + res; ++sip) |
|
|
1277 | ev_feed_signal_event (EV_A_ sip->ssi_signo); |
|
|
1278 | |
|
|
1279 | if (res < (ssize_t)sizeof (si)) |
|
|
1280 | break; |
|
|
1281 | } |
|
|
1282 | } |
|
|
1283 | #endif |
1218 | |
1284 | |
1219 | /*****************************************************************************/ |
1285 | /*****************************************************************************/ |
1220 | |
1286 | |
1221 | static WL childs [EV_PID_HASHSIZE]; |
1287 | static WL childs [EV_PID_HASHSIZE]; |
1222 | |
1288 | |
… | |
… | |
1409 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
1475 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
1410 | { |
1476 | { |
1411 | invoke_cb = invoke_pending_cb; |
1477 | invoke_cb = invoke_pending_cb; |
1412 | } |
1478 | } |
1413 | |
1479 | |
1414 | void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P)) |
1480 | void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
1415 | { |
1481 | { |
1416 | suspend_cb = suspend_cb_; |
1482 | release_cb = release; |
1417 | resume_cb = resume_cb_; |
1483 | acquire_cb = acquire; |
1418 | } |
1484 | } |
1419 | #endif |
1485 | #endif |
1420 | |
1486 | |
1421 | /* initialise a loop structure, must be zero-initialised */ |
1487 | /* initialise a loop structure, must be zero-initialised */ |
1422 | static void noinline |
1488 | static void noinline |
… | |
… | |
1458 | backend_fd = -1; |
1524 | backend_fd = -1; |
1459 | gotasync = 0; |
1525 | gotasync = 0; |
1460 | #if EV_USE_INOTIFY |
1526 | #if EV_USE_INOTIFY |
1461 | fs_fd = -2; |
1527 | fs_fd = -2; |
1462 | #endif |
1528 | #endif |
|
|
1529 | #if EV_USE_SIGNALFD |
|
|
1530 | sigfd = -2; |
|
|
1531 | #endif |
1463 | |
1532 | |
1464 | /* pid check not overridable via env */ |
1533 | /* pid check not overridable via env */ |
1465 | #ifndef _WIN32 |
1534 | #ifndef _WIN32 |
1466 | if (flags & EVFLAG_FORKCHECK) |
1535 | if (flags & EVFLAG_FORKCHECK) |
1467 | curpid = getpid (); |
1536 | curpid = getpid (); |
… | |
… | |
1504 | { |
1573 | { |
1505 | int i; |
1574 | int i; |
1506 | |
1575 | |
1507 | if (ev_is_active (&pipe_w)) |
1576 | if (ev_is_active (&pipe_w)) |
1508 | { |
1577 | { |
1509 | ev_ref (EV_A); /* signal watcher */ |
1578 | /*ev_ref (EV_A);*/ |
1510 | ev_io_stop (EV_A_ &pipe_w); |
1579 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
1511 | |
1580 | |
1512 | #if EV_USE_EVENTFD |
1581 | #if EV_USE_EVENTFD |
1513 | if (evfd >= 0) |
1582 | if (evfd >= 0) |
1514 | close (evfd); |
1583 | close (evfd); |
1515 | #endif |
1584 | #endif |
… | |
… | |
1518 | { |
1587 | { |
1519 | close (evpipe [0]); |
1588 | close (evpipe [0]); |
1520 | close (evpipe [1]); |
1589 | close (evpipe [1]); |
1521 | } |
1590 | } |
1522 | } |
1591 | } |
|
|
1592 | |
|
|
1593 | #if EV_USE_SIGNALFD |
|
|
1594 | if (ev_is_active (&sigfd_w)) |
|
|
1595 | { |
|
|
1596 | /*ev_ref (EV_A);*/ |
|
|
1597 | /*ev_io_stop (EV_A_ &sigfd_w);*/ |
|
|
1598 | |
|
|
1599 | close (sigfd); |
|
|
1600 | } |
|
|
1601 | #endif |
1523 | |
1602 | |
1524 | #if EV_USE_INOTIFY |
1603 | #if EV_USE_INOTIFY |
1525 | if (fs_fd >= 0) |
1604 | if (fs_fd >= 0) |
1526 | close (fs_fd); |
1605 | close (fs_fd); |
1527 | #endif |
1606 | #endif |
… | |
… | |
1631 | ev_loop_new (unsigned int flags) |
1710 | ev_loop_new (unsigned int flags) |
1632 | { |
1711 | { |
1633 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1712 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1634 | |
1713 | |
1635 | memset (loop, 0, sizeof (struct ev_loop)); |
1714 | memset (loop, 0, sizeof (struct ev_loop)); |
1636 | |
|
|
1637 | loop_init (EV_A_ flags); |
1715 | loop_init (EV_A_ flags); |
1638 | |
1716 | |
1639 | if (ev_backend (EV_A)) |
1717 | if (ev_backend (EV_A)) |
1640 | return loop; |
1718 | return loop; |
1641 | |
1719 | |
… | |
… | |
1822 | |
1900 | |
1823 | void |
1901 | void |
1824 | ev_invoke (EV_P_ void *w, int revents) |
1902 | ev_invoke (EV_P_ void *w, int revents) |
1825 | { |
1903 | { |
1826 | EV_CB_INVOKE ((W)w, revents); |
1904 | EV_CB_INVOKE ((W)w, revents); |
|
|
1905 | } |
|
|
1906 | |
|
|
1907 | unsigned int |
|
|
1908 | ev_pending_count (EV_P) |
|
|
1909 | { |
|
|
1910 | int pri; |
|
|
1911 | unsigned int count = 0; |
|
|
1912 | |
|
|
1913 | for (pri = NUMPRI; pri--; ) |
|
|
1914 | count += pendingcnt [pri]; |
|
|
1915 | |
|
|
1916 | return count; |
1827 | } |
1917 | } |
1828 | |
1918 | |
1829 | void noinline |
1919 | void noinline |
1830 | ev_invoke_pending (EV_P) |
1920 | ev_invoke_pending (EV_P) |
1831 | { |
1921 | { |
… | |
… | |
2077 | { |
2167 | { |
2078 | #if EV_MINIMAL < 2 |
2168 | #if EV_MINIMAL < 2 |
2079 | ++loop_depth; |
2169 | ++loop_depth; |
2080 | #endif |
2170 | #endif |
2081 | |
2171 | |
|
|
2172 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
|
|
2173 | |
2082 | loop_done = EVUNLOOP_CANCEL; |
2174 | loop_done = EVUNLOOP_CANCEL; |
2083 | |
2175 | |
2084 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2176 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2085 | |
2177 | |
2086 | do |
2178 | do |
… | |
… | |
2113 | { |
2205 | { |
2114 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2206 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2115 | EV_INVOKE_PENDING; |
2207 | EV_INVOKE_PENDING; |
2116 | } |
2208 | } |
2117 | |
2209 | |
|
|
2210 | if (expect_false (loop_done)) |
|
|
2211 | break; |
|
|
2212 | |
2118 | /* we might have forked, so reify kernel state if necessary */ |
2213 | /* we might have forked, so reify kernel state if necessary */ |
2119 | if (expect_false (postfork)) |
2214 | if (expect_false (postfork)) |
2120 | loop_fork (EV_A); |
2215 | loop_fork (EV_A); |
2121 | |
2216 | |
2122 | /* update fd-related kernel structures */ |
2217 | /* update fd-related kernel structures */ |
… | |
… | |
2172 | } |
2267 | } |
2173 | |
2268 | |
2174 | #if EV_MINIMAL < 2 |
2269 | #if EV_MINIMAL < 2 |
2175 | ++loop_count; |
2270 | ++loop_count; |
2176 | #endif |
2271 | #endif |
|
|
2272 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2177 | backend_poll (EV_A_ waittime); |
2273 | backend_poll (EV_A_ waittime); |
|
|
2274 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2178 | |
2275 | |
2179 | /* update ev_rt_now, do magic */ |
2276 | /* update ev_rt_now, do magic */ |
2180 | time_update (EV_A_ waittime + sleeptime); |
2277 | time_update (EV_A_ waittime + sleeptime); |
2181 | } |
2278 | } |
2182 | |
2279 | |
… | |
… | |
2348 | |
2445 | |
2349 | ev_start (EV_A_ (W)w, 1); |
2446 | ev_start (EV_A_ (W)w, 1); |
2350 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2447 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2351 | wlist_add (&anfds[fd].head, (WL)w); |
2448 | wlist_add (&anfds[fd].head, (WL)w); |
2352 | |
2449 | |
2353 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | 1); |
2450 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
2354 | w->events &= ~EV__IOFDSET; |
2451 | w->events &= ~EV__IOFDSET; |
2355 | |
2452 | |
2356 | EV_FREQUENT_CHECK; |
2453 | EV_FREQUENT_CHECK; |
2357 | } |
2454 | } |
2358 | |
2455 | |
… | |
… | |
2452 | } |
2549 | } |
2453 | |
2550 | |
2454 | EV_FREQUENT_CHECK; |
2551 | EV_FREQUENT_CHECK; |
2455 | } |
2552 | } |
2456 | |
2553 | |
|
|
2554 | ev_tstamp |
|
|
2555 | ev_timer_remaining (EV_P_ ev_timer *w) |
|
|
2556 | { |
|
|
2557 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
|
|
2558 | } |
|
|
2559 | |
2457 | #if EV_PERIODIC_ENABLE |
2560 | #if EV_PERIODIC_ENABLE |
2458 | void noinline |
2561 | void noinline |
2459 | ev_periodic_start (EV_P_ ev_periodic *w) |
2562 | ev_periodic_start (EV_P_ ev_periodic *w) |
2460 | { |
2563 | { |
2461 | if (expect_false (ev_is_active (w))) |
2564 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2536 | if (expect_false (ev_is_active (w))) |
2639 | if (expect_false (ev_is_active (w))) |
2537 | return; |
2640 | return; |
2538 | |
2641 | |
2539 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0)); |
2642 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0)); |
2540 | |
2643 | |
|
|
2644 | EV_FREQUENT_CHECK; |
|
|
2645 | |
|
|
2646 | #if EV_USE_SIGNALFD |
|
|
2647 | if (sigfd == -2) |
|
|
2648 | { |
|
|
2649 | sigfd = signalfd (-1, &sigfd_set, SFD_NONBLOCK | SFD_CLOEXEC); |
|
|
2650 | if (sigfd < 0 && errno == EINVAL) |
|
|
2651 | sigfd = signalfd (-1, &sigfd_set, 0); /* retry without flags */ |
|
|
2652 | |
|
|
2653 | if (sigfd >= 0) |
|
|
2654 | { |
|
|
2655 | fd_intern (sigfd); /* doing it twice will not hurt */ |
|
|
2656 | |
|
|
2657 | sigemptyset (&sigfd_set); |
|
|
2658 | |
|
|
2659 | ev_io_init (&sigfd_w, sigfdcb, sigfd, EV_READ); |
|
|
2660 | ev_set_priority (&sigfd_w, EV_MAXPRI); |
|
|
2661 | ev_io_start (EV_A_ &sigfd_w); |
|
|
2662 | ev_unref (EV_A); /* signalfd watcher should not keep loop alive */ |
|
|
2663 | } |
|
|
2664 | } |
|
|
2665 | |
|
|
2666 | if (sigfd >= 0) |
|
|
2667 | { |
|
|
2668 | /* TODO: check .head */ |
|
|
2669 | sigaddset (&sigfd_set, w->signum); |
|
|
2670 | sigprocmask (SIG_BLOCK, &sigfd_set, 0); |
|
|
2671 | |
|
|
2672 | signalfd (sigfd, &sigfd_set, 0); |
|
|
2673 | } |
|
|
2674 | else |
|
|
2675 | #endif |
2541 | evpipe_init (EV_A); |
2676 | evpipe_init (EV_A); |
2542 | |
|
|
2543 | EV_FREQUENT_CHECK; |
|
|
2544 | |
2677 | |
2545 | { |
2678 | { |
2546 | #ifndef _WIN32 |
2679 | #ifndef _WIN32 |
2547 | sigset_t full, prev; |
2680 | sigset_t full, prev; |
2548 | sigfillset (&full); |
2681 | sigfillset (&full); |
… | |
… | |
2550 | #endif |
2683 | #endif |
2551 | |
2684 | |
2552 | array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero); |
2685 | array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero); |
2553 | |
2686 | |
2554 | #ifndef _WIN32 |
2687 | #ifndef _WIN32 |
|
|
2688 | if (sigfd < 0)/*TODO*/ |
|
|
2689 | sigdelset (&prev, w->signum); |
2555 | sigprocmask (SIG_SETMASK, &prev, 0); |
2690 | sigprocmask (SIG_SETMASK, &prev, 0); |
2556 | #endif |
2691 | #endif |
2557 | } |
2692 | } |
2558 | |
2693 | |
2559 | ev_start (EV_A_ (W)w, 1); |
2694 | ev_start (EV_A_ (W)w, 1); |
… | |
… | |
2562 | if (!((WL)w)->next) |
2697 | if (!((WL)w)->next) |
2563 | { |
2698 | { |
2564 | #if _WIN32 |
2699 | #if _WIN32 |
2565 | signal (w->signum, ev_sighandler); |
2700 | signal (w->signum, ev_sighandler); |
2566 | #else |
2701 | #else |
|
|
2702 | if (sigfd < 0) /*TODO*/ |
|
|
2703 | { |
2567 | struct sigaction sa; |
2704 | struct sigaction sa = { }; |
2568 | sa.sa_handler = ev_sighandler; |
2705 | sa.sa_handler = ev_sighandler; |
2569 | sigfillset (&sa.sa_mask); |
2706 | sigfillset (&sa.sa_mask); |
2570 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2707 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2571 | sigaction (w->signum, &sa, 0); |
2708 | sigaction (w->signum, &sa, 0); |
|
|
2709 | } |
2572 | #endif |
2710 | #endif |
2573 | } |
2711 | } |
2574 | |
2712 | |
2575 | EV_FREQUENT_CHECK; |
2713 | EV_FREQUENT_CHECK; |
2576 | } |
2714 | } |
… | |
… | |
2586 | |
2724 | |
2587 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2725 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2588 | ev_stop (EV_A_ (W)w); |
2726 | ev_stop (EV_A_ (W)w); |
2589 | |
2727 | |
2590 | if (!signals [w->signum - 1].head) |
2728 | if (!signals [w->signum - 1].head) |
|
|
2729 | #if EV_USE_SIGNALFD |
|
|
2730 | if (sigfd >= 0) |
|
|
2731 | { |
|
|
2732 | sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D |
|
|
2733 | sigdelset (&sigfd_set, w->signum); |
|
|
2734 | signalfd (sigfd, &sigfd_set, 0); |
|
|
2735 | sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D |
|
|
2736 | /*TODO: maybe unblock signal? */ |
|
|
2737 | } |
|
|
2738 | else |
|
|
2739 | #endif |
2591 | signal (w->signum, SIG_DFL); |
2740 | signal (w->signum, SIG_DFL); |
2592 | |
2741 | |
2593 | EV_FREQUENT_CHECK; |
2742 | EV_FREQUENT_CHECK; |
2594 | } |
2743 | } |
2595 | |
2744 | |
2596 | void |
2745 | void |