… | |
… | |
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 becaue 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 |
… | |
… | |
875 | #if _WIN32 |
876 | #if _WIN32 |
876 | signal (signum, sighandler); |
877 | signal (signum, 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 | { |
… | |
… | |
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]); |
… | |
… | |
2458 | |
2466 | |
2459 | void |
2467 | void |
2460 | ev_async_send (EV_P_ ev_async *w) |
2468 | ev_async_send (EV_P_ ev_async *w) |
2461 | { |
2469 | { |
2462 | w->sent = 1; |
2470 | w->sent = 1; |
2463 | evpipe_write (EV_A_ 0, 1); |
2471 | evpipe_write (EV_A_ &gotasync); |
2464 | } |
2472 | } |
2465 | #endif |
2473 | #endif |
2466 | |
2474 | |
2467 | /*****************************************************************************/ |
2475 | /*****************************************************************************/ |
2468 | |
2476 | |