ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.208 by root, Fri Feb 1 13:22:48 2008 UTC vs.
Revision 1.216 by root, Sat Mar 8 07:04:55 2008 UTC

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
819void inline_size 819void inline_size
820evpipe_write (EV_P_ int sig, int async) 820evpipe_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
834static void 833static 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
868static void 869static 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
883void noinline 884void noinline
884ev_feed_signal_event (EV_P_ int signum) 885ev_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
915void inline_speed 916void inline_speed
916child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 917child_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
1196void inline_size infy_fork (EV_P); 1200void 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
2459void 2467void
2460ev_async_send (EV_P_ ev_async *w) 2468ev_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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines