… | |
… | |
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); |
… | |
… | |
815 | ev_unref (EV_A); /* 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; /* save errno becaue write might clobber it */ |
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); |
830 | |
828 | |
831 | errno = old_errno; |
829 | errno = old_errno; |
832 | } |
830 | } |
833 | } |
831 | } |
… | |
… | |
867 | } |
865 | } |
868 | |
866 | |
869 | /*****************************************************************************/ |
867 | /*****************************************************************************/ |
870 | |
868 | |
871 | static void |
869 | static void |
872 | sighandler (int signum) |
870 | ev_sighandler (int signum) |
873 | { |
871 | { |
874 | #if EV_MULTIPLICITY |
872 | #if EV_MULTIPLICITY |
875 | struct ev_loop *loop = &default_loop_struct; |
873 | struct ev_loop *loop = &default_loop_struct; |
876 | #endif |
874 | #endif |
877 | |
875 | |
878 | #if _WIN32 |
876 | #if _WIN32 |
879 | signal (signum, sighandler); |
877 | signal (signum, ev_sighandler); |
880 | #endif |
878 | #endif |
881 | |
879 | |
882 | signals [signum - 1].gotsig = 1; |
880 | signals [signum - 1].gotsig = 1; |
883 | evpipe_write (EV_A_ 1, 0); |
881 | evpipe_write (EV_A_ &gotsig); |
884 | } |
882 | } |
885 | |
883 | |
886 | void noinline |
884 | void noinline |
887 | ev_feed_signal_event (EV_P_ int signum) |
885 | ev_feed_signal_event (EV_P_ int signum) |
888 | { |
886 | { |
… | |
… | |
914 | #ifndef WIFCONTINUED |
912 | #ifndef WIFCONTINUED |
915 | # define WIFCONTINUED(status) 0 |
913 | # define WIFCONTINUED(status) 0 |
916 | #endif |
914 | #endif |
917 | |
915 | |
918 | void inline_speed |
916 | void inline_speed |
919 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
917 | child_reap (EV_P_ int chain, int pid, int status) |
920 | { |
918 | { |
921 | ev_child *w; |
919 | ev_child *w; |
922 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
920 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
923 | |
921 | |
924 | 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) |
925 | { |
923 | { |
926 | if ((w->pid == pid || !w->pid) |
924 | if ((w->pid == pid || !w->pid) |
927 | && (!traced || (w->flags & 1))) |
925 | && (!traced || (w->flags & 1))) |
928 | { |
926 | { |
929 | 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 */ |
930 | w->rpid = pid; |
928 | w->rpid = pid; |
931 | w->rstatus = status; |
929 | w->rstatus = status; |
932 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
930 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
933 | } |
931 | } |
934 | } |
932 | } |
… | |
… | |
948 | if (!WCONTINUED |
946 | if (!WCONTINUED |
949 | || errno != EINVAL |
947 | || errno != EINVAL |
950 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
948 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
951 | return; |
949 | return; |
952 | |
950 | |
953 | /* 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 */ |
954 | /* 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 */ |
955 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
953 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
956 | |
954 | |
957 | child_reap (EV_A_ sw, pid, pid, status); |
955 | child_reap (EV_A_ pid, pid, status); |
958 | if (EV_PID_HASHSIZE > 1) |
956 | if (EV_PID_HASHSIZE > 1) |
959 | 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 */ |
960 | } |
958 | } |
961 | |
959 | |
962 | #endif |
960 | #endif |
963 | |
961 | |
964 | /*****************************************************************************/ |
962 | /*****************************************************************************/ |
… | |
… | |
1544 | static int loop_done; |
1542 | static int loop_done; |
1545 | |
1543 | |
1546 | void |
1544 | void |
1547 | ev_loop (EV_P_ int flags) |
1545 | ev_loop (EV_P_ int flags) |
1548 | { |
1546 | { |
1549 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1547 | loop_done = EVUNLOOP_CANCEL; |
1550 | ? EVUNLOOP_ONE |
|
|
1551 | : EVUNLOOP_CANCEL; |
|
|
1552 | |
1548 | |
1553 | 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 */ |
1554 | |
1550 | |
1555 | do |
1551 | do |
1556 | { |
1552 | { |
… | |
… | |
1652 | /* queue check watchers, to be executed first */ |
1648 | /* queue check watchers, to be executed first */ |
1653 | if (expect_false (checkcnt)) |
1649 | if (expect_false (checkcnt)) |
1654 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1650 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1655 | |
1651 | |
1656 | call_pending (EV_A); |
1652 | call_pending (EV_A); |
1657 | |
|
|
1658 | } |
1653 | } |
1659 | while (expect_true (activecnt && !loop_done)); |
1654 | while (expect_true ( |
|
|
1655 | activecnt |
|
|
1656 | && !loop_done |
|
|
1657 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
|
|
1658 | )); |
1660 | |
1659 | |
1661 | if (loop_done == EVUNLOOP_ONE) |
1660 | if (loop_done == EVUNLOOP_ONE) |
1662 | loop_done = EVUNLOOP_CANCEL; |
1661 | loop_done = EVUNLOOP_CANCEL; |
1663 | } |
1662 | } |
1664 | |
1663 | |
… | |
… | |
1932 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1931 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1933 | |
1932 | |
1934 | if (!((WL)w)->next) |
1933 | if (!((WL)w)->next) |
1935 | { |
1934 | { |
1936 | #if _WIN32 |
1935 | #if _WIN32 |
1937 | signal (w->signum, sighandler); |
1936 | signal (w->signum, ev_sighandler); |
1938 | #else |
1937 | #else |
1939 | struct sigaction sa; |
1938 | struct sigaction sa; |
1940 | sa.sa_handler = sighandler; |
1939 | sa.sa_handler = ev_sighandler; |
1941 | sigfillset (&sa.sa_mask); |
1940 | sigfillset (&sa.sa_mask); |
1942 | 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 */ |
1943 | sigaction (w->signum, &sa, 0); |
1942 | sigaction (w->signum, &sa, 0); |
1944 | #endif |
1943 | #endif |
1945 | } |
1944 | } |
… | |
… | |
2468 | |
2467 | |
2469 | void |
2468 | void |
2470 | ev_async_send (EV_P_ ev_async *w) |
2469 | ev_async_send (EV_P_ ev_async *w) |
2471 | { |
2470 | { |
2472 | w->sent = 1; |
2471 | w->sent = 1; |
2473 | evpipe_write (EV_A_ 0, 1); |
2472 | evpipe_write (EV_A_ &gotasync); |
2474 | } |
2473 | } |
2475 | #endif |
2474 | #endif |
2476 | |
2475 | |
2477 | /*****************************************************************************/ |
2476 | /*****************************************************************************/ |
2478 | |
2477 | |