… | |
… | |
451 | ts.tv_sec = (time_t)delay; |
451 | ts.tv_sec = (time_t)delay; |
452 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
452 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
453 | |
453 | |
454 | nanosleep (&ts, 0); |
454 | nanosleep (&ts, 0); |
455 | #elif defined(_WIN32) |
455 | #elif defined(_WIN32) |
456 | Sleep (delay * 1e3); |
456 | Sleep ((unsigned long)(delay * 1e3)); |
457 | #else |
457 | #else |
458 | struct timeval tv; |
458 | struct timeval tv; |
459 | |
459 | |
460 | tv.tv_sec = (time_t)delay; |
460 | tv.tv_sec = (time_t)delay; |
461 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
461 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
… | |
… | |
810 | fd_intern (evpipe [0]); |
810 | fd_intern (evpipe [0]); |
811 | fd_intern (evpipe [1]); |
811 | fd_intern (evpipe [1]); |
812 | |
812 | |
813 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
813 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
814 | ev_io_start (EV_A_ &pipeev); |
814 | ev_io_start (EV_A_ &pipeev); |
815 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
815 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
816 | } |
816 | } |
817 | } |
817 | } |
818 | |
818 | |
819 | void inline_size |
819 | void inline_size |
820 | evpipe_write (EV_P_ int sig, int async) |
820 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
821 | { |
821 | { |
822 | if (!(gotasync || gotsig)) |
822 | if (!*flag) |
823 | { |
823 | { |
824 | int old_errno = errno; |
824 | int old_errno = errno; /* save errno because write might clobber it */ |
825 | |
825 | |
826 | if (sig) gotsig = 1; |
826 | *flag = 1; |
827 | if (async) gotasync = 1; |
|
|
828 | |
|
|
829 | write (evpipe [1], &old_errno, 1); |
827 | write (evpipe [1], &old_errno, 1); |
|
|
828 | |
830 | errno = old_errno; |
829 | errno = old_errno; |
831 | } |
830 | } |
832 | } |
831 | } |
833 | |
832 | |
834 | static void |
833 | static void |
… | |
… | |
837 | { |
836 | { |
838 | int dummy; |
837 | int dummy; |
839 | read (evpipe [0], &dummy, 1); |
838 | read (evpipe [0], &dummy, 1); |
840 | } |
839 | } |
841 | |
840 | |
842 | if (gotsig) |
841 | if (gotsig && ev_is_default_loop (EV_A)) |
843 | { |
842 | { |
844 | int signum; |
843 | int signum; |
845 | gotsig = 0; |
844 | gotsig = 0; |
846 | |
845 | |
847 | for (signum = signalmax; signum--; ) |
846 | for (signum = signalmax; signum--; ) |
848 | if (signals [signum].gotsig) |
847 | if (signals [signum].gotsig) |
849 | ev_feed_signal_event (EV_A_ signum + 1); |
848 | ev_feed_signal_event (EV_A_ signum + 1); |
850 | } |
849 | } |
851 | |
850 | |
|
|
851 | #if EV_ASYNC_ENABLE |
852 | if (gotasync) |
852 | if (gotasync) |
853 | { |
853 | { |
854 | int i; |
854 | int i; |
855 | gotasync = 0; |
855 | gotasync = 0; |
856 | |
856 | |
… | |
… | |
859 | { |
859 | { |
860 | asyncs [i]->sent = 0; |
860 | asyncs [i]->sent = 0; |
861 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
861 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
862 | } |
862 | } |
863 | } |
863 | } |
|
|
864 | #endif |
864 | } |
865 | } |
865 | |
866 | |
866 | /*****************************************************************************/ |
867 | /*****************************************************************************/ |
867 | |
868 | |
868 | static void |
869 | static void |
869 | sighandler (int signum) |
870 | ev_sighandler (int signum) |
870 | { |
871 | { |
871 | #if EV_MULTIPLICITY |
872 | #if EV_MULTIPLICITY |
872 | struct ev_loop *loop = &default_loop_struct; |
873 | struct ev_loop *loop = &default_loop_struct; |
873 | #endif |
874 | #endif |
874 | |
875 | |
875 | #if _WIN32 |
876 | #if _WIN32 |
876 | signal (signum, sighandler); |
877 | signal (signum, ev_sighandler); |
877 | #endif |
878 | #endif |
878 | |
879 | |
879 | signals [signum - 1].gotsig = 1; |
880 | signals [signum - 1].gotsig = 1; |
880 | evpipe_write (EV_A_ 1, 0); |
881 | evpipe_write (EV_A_ &gotsig); |
881 | } |
882 | } |
882 | |
883 | |
883 | void noinline |
884 | void noinline |
884 | ev_feed_signal_event (EV_P_ int signum) |
885 | ev_feed_signal_event (EV_P_ int signum) |
885 | { |
886 | { |
… | |
… | |
911 | #ifndef WIFCONTINUED |
912 | #ifndef WIFCONTINUED |
912 | # define WIFCONTINUED(status) 0 |
913 | # define WIFCONTINUED(status) 0 |
913 | #endif |
914 | #endif |
914 | |
915 | |
915 | void inline_speed |
916 | void inline_speed |
916 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
917 | child_reap (EV_P_ int chain, int pid, int status) |
917 | { |
918 | { |
918 | ev_child *w; |
919 | ev_child *w; |
919 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
920 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
920 | |
921 | |
921 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
922 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
922 | { |
923 | { |
923 | if ((w->pid == pid || !w->pid) |
924 | if ((w->pid == pid || !w->pid) |
924 | && (!traced || (w->flags & 1))) |
925 | && (!traced || (w->flags & 1))) |
925 | { |
926 | { |
926 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
927 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
927 | w->rpid = pid; |
928 | w->rpid = pid; |
928 | w->rstatus = status; |
929 | w->rstatus = status; |
929 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
930 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
930 | } |
931 | } |
931 | } |
932 | } |
… | |
… | |
945 | if (!WCONTINUED |
946 | if (!WCONTINUED |
946 | || errno != EINVAL |
947 | || errno != EINVAL |
947 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
948 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
948 | return; |
949 | return; |
949 | |
950 | |
950 | /* make sure we are called again until all childs have been reaped */ |
951 | /* make sure we are called again until all children have been reaped */ |
951 | /* we need to do it this way so that the callback gets called before we continue */ |
952 | /* we need to do it this way so that the callback gets called before we continue */ |
952 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
953 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
953 | |
954 | |
954 | child_reap (EV_A_ sw, pid, pid, status); |
955 | child_reap (EV_A_ pid, pid, status); |
955 | if (EV_PID_HASHSIZE > 1) |
956 | if (EV_PID_HASHSIZE > 1) |
956 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
957 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
957 | } |
958 | } |
958 | |
959 | |
959 | #endif |
960 | #endif |
960 | |
961 | |
961 | /*****************************************************************************/ |
962 | /*****************************************************************************/ |
… | |
… | |
1079 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1080 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1080 | have_monotonic = 1; |
1081 | have_monotonic = 1; |
1081 | } |
1082 | } |
1082 | #endif |
1083 | #endif |
1083 | |
1084 | |
1084 | ev_rt_now = ev_time (); |
1085 | ev_rt_now = ev_time (); |
1085 | mn_now = get_clock (); |
1086 | mn_now = get_clock (); |
1086 | now_floor = mn_now; |
1087 | now_floor = mn_now; |
1087 | rtmn_diff = ev_rt_now - mn_now; |
1088 | rtmn_diff = ev_rt_now - mn_now; |
1088 | |
1089 | |
1089 | io_blocktime = 0.; |
1090 | io_blocktime = 0.; |
1090 | timeout_blocktime = 0.; |
1091 | timeout_blocktime = 0.; |
|
|
1092 | backend = 0; |
|
|
1093 | backend_fd = -1; |
|
|
1094 | gotasync = 0; |
|
|
1095 | #if EV_USE_INOTIFY |
|
|
1096 | fs_fd = -2; |
|
|
1097 | #endif |
1091 | |
1098 | |
1092 | /* pid check not overridable via env */ |
1099 | /* pid check not overridable via env */ |
1093 | #ifndef _WIN32 |
1100 | #ifndef _WIN32 |
1094 | if (flags & EVFLAG_FORKCHECK) |
1101 | if (flags & EVFLAG_FORKCHECK) |
1095 | curpid = getpid (); |
1102 | curpid = getpid (); |
… | |
… | |
1100 | && getenv ("LIBEV_FLAGS")) |
1107 | && getenv ("LIBEV_FLAGS")) |
1101 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1108 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1102 | |
1109 | |
1103 | if (!(flags & 0x0000ffffUL)) |
1110 | if (!(flags & 0x0000ffffUL)) |
1104 | flags |= ev_recommended_backends (); |
1111 | flags |= ev_recommended_backends (); |
1105 | |
|
|
1106 | backend = 0; |
|
|
1107 | backend_fd = -1; |
|
|
1108 | #if EV_USE_INOTIFY |
|
|
1109 | fs_fd = -2; |
|
|
1110 | #endif |
|
|
1111 | |
1112 | |
1112 | #if EV_USE_PORT |
1113 | #if EV_USE_PORT |
1113 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1114 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1114 | #endif |
1115 | #endif |
1115 | #if EV_USE_KQUEUE |
1116 | #if EV_USE_KQUEUE |
… | |
… | |
1187 | #if EV_FORK_ENABLE |
1188 | #if EV_FORK_ENABLE |
1188 | array_free (fork, EMPTY); |
1189 | array_free (fork, EMPTY); |
1189 | #endif |
1190 | #endif |
1190 | array_free (prepare, EMPTY); |
1191 | array_free (prepare, EMPTY); |
1191 | array_free (check, EMPTY); |
1192 | array_free (check, EMPTY); |
|
|
1193 | #if EV_ASYNC_ENABLE |
|
|
1194 | array_free (async, EMPTY); |
|
|
1195 | #endif |
1192 | |
1196 | |
1193 | backend = 0; |
1197 | backend = 0; |
1194 | } |
1198 | } |
1195 | |
1199 | |
1196 | void inline_size infy_fork (EV_P); |
1200 | void inline_size infy_fork (EV_P); |
… | |
… | |
1212 | #endif |
1216 | #endif |
1213 | |
1217 | |
1214 | if (ev_is_active (&pipeev)) |
1218 | if (ev_is_active (&pipeev)) |
1215 | { |
1219 | { |
1216 | /* this "locks" the handlers against writing to the pipe */ |
1220 | /* this "locks" the handlers against writing to the pipe */ |
|
|
1221 | /* while we modify the fd vars */ |
|
|
1222 | gotsig = 1; |
|
|
1223 | #if EV_ASYNC_ENABLE |
1217 | gotsig = gotasync = 1; |
1224 | gotasync = 1; |
|
|
1225 | #endif |
1218 | |
1226 | |
1219 | ev_ref (EV_A); |
1227 | ev_ref (EV_A); |
1220 | ev_io_stop (EV_A_ &pipeev); |
1228 | ev_io_stop (EV_A_ &pipeev); |
1221 | close (evpipe [0]); |
1229 | close (evpipe [0]); |
1222 | close (evpipe [1]); |
1230 | close (evpipe [1]); |
… | |
… | |
1534 | static int loop_done; |
1542 | static int loop_done; |
1535 | |
1543 | |
1536 | void |
1544 | void |
1537 | ev_loop (EV_P_ int flags) |
1545 | ev_loop (EV_P_ int flags) |
1538 | { |
1546 | { |
1539 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1547 | loop_done = EVUNLOOP_CANCEL; |
1540 | ? EVUNLOOP_ONE |
|
|
1541 | : EVUNLOOP_CANCEL; |
|
|
1542 | |
1548 | |
1543 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1549 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1544 | |
1550 | |
1545 | do |
1551 | do |
1546 | { |
1552 | { |
… | |
… | |
1642 | /* queue check watchers, to be executed first */ |
1648 | /* queue check watchers, to be executed first */ |
1643 | if (expect_false (checkcnt)) |
1649 | if (expect_false (checkcnt)) |
1644 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1650 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1645 | |
1651 | |
1646 | call_pending (EV_A); |
1652 | call_pending (EV_A); |
1647 | |
|
|
1648 | } |
1653 | } |
1649 | while (expect_true (activecnt && !loop_done)); |
1654 | while (expect_true ( |
|
|
1655 | activecnt |
|
|
1656 | && !loop_done |
|
|
1657 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
|
|
1658 | )); |
1650 | |
1659 | |
1651 | if (loop_done == EVUNLOOP_ONE) |
1660 | if (loop_done == EVUNLOOP_ONE) |
1652 | loop_done = EVUNLOOP_CANCEL; |
1661 | loop_done = EVUNLOOP_CANCEL; |
1653 | } |
1662 | } |
1654 | |
1663 | |
… | |
… | |
1922 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1931 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1923 | |
1932 | |
1924 | if (!((WL)w)->next) |
1933 | if (!((WL)w)->next) |
1925 | { |
1934 | { |
1926 | #if _WIN32 |
1935 | #if _WIN32 |
1927 | signal (w->signum, sighandler); |
1936 | signal (w->signum, ev_sighandler); |
1928 | #else |
1937 | #else |
1929 | struct sigaction sa; |
1938 | struct sigaction sa; |
1930 | sa.sa_handler = sighandler; |
1939 | sa.sa_handler = ev_sighandler; |
1931 | sigfillset (&sa.sa_mask); |
1940 | sigfillset (&sa.sa_mask); |
1932 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1941 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1933 | sigaction (w->signum, &sa, 0); |
1942 | sigaction (w->signum, &sa, 0); |
1934 | #endif |
1943 | #endif |
1935 | } |
1944 | } |
… | |
… | |
2458 | |
2467 | |
2459 | void |
2468 | void |
2460 | ev_async_send (EV_P_ ev_async *w) |
2469 | ev_async_send (EV_P_ ev_async *w) |
2461 | { |
2470 | { |
2462 | w->sent = 1; |
2471 | w->sent = 1; |
2463 | evpipe_write (EV_A_ 0, 1); |
2472 | evpipe_write (EV_A_ &gotasync); |
2464 | } |
2473 | } |
2465 | #endif |
2474 | #endif |
2466 | |
2475 | |
2467 | /*****************************************************************************/ |
2476 | /*****************************************************************************/ |
2468 | |
2477 | |