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

Comparing libev/ev.c (file contents):
Revision 1.209 by root, Tue Feb 5 23:56:33 2008 UTC vs.
Revision 1.217 by root, Sat Mar 22 13:42:45 2008 UTC

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
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--; )
877#if _WIN32 876#if _WIN32
878 signal (signum, sighandler); 877 signal (signum, sighandler);
879#endif 878#endif
880 879
881 signals [signum - 1].gotsig = 1; 880 signals [signum - 1].gotsig = 1;
882 evpipe_write (EV_A_ 1, 0); 881 evpipe_write (EV_A_ &gotsig);
883} 882}
884 883
885void noinline 884void noinline
886ev_feed_signal_event (EV_P_ int signum) 885ev_feed_signal_event (EV_P_ int signum)
887{ 886{
913#ifndef WIFCONTINUED 912#ifndef WIFCONTINUED
914# define WIFCONTINUED(status) 0 913# define WIFCONTINUED(status) 0
915#endif 914#endif
916 915
917void inline_speed 916void inline_speed
918child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 917child_reap (EV_P_ int chain, int pid, int status)
919{ 918{
920 ev_child *w; 919 ev_child *w;
921 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 920 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
922 921
923 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)
924 { 923 {
925 if ((w->pid == pid || !w->pid) 924 if ((w->pid == pid || !w->pid)
926 && (!traced || (w->flags & 1))) 925 && (!traced || (w->flags & 1)))
927 { 926 {
928 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 */
929 w->rpid = pid; 928 w->rpid = pid;
930 w->rstatus = status; 929 w->rstatus = status;
931 ev_feed_event (EV_A_ (W)w, EV_CHILD); 930 ev_feed_event (EV_A_ (W)w, EV_CHILD);
932 } 931 }
933 } 932 }
947 if (!WCONTINUED 946 if (!WCONTINUED
948 || errno != EINVAL 947 || errno != EINVAL
949 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) 948 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED)))
950 return; 949 return;
951 950
952 /* 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 */
953 /* 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 */
954 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 953 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
955 954
956 child_reap (EV_A_ sw, pid, pid, status); 955 child_reap (EV_A_ pid, pid, status);
957 if (EV_PID_HASHSIZE > 1) 956 if (EV_PID_HASHSIZE > 1)
958 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 */
959} 958}
960 959
961#endif 960#endif
962 961
963/*****************************************************************************/ 962/*****************************************************************************/
1217#endif 1216#endif
1218 1217
1219 if (ev_is_active (&pipeev)) 1218 if (ev_is_active (&pipeev))
1220 { 1219 {
1221 /* 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
1222 gotsig = gotasync = 1; 1224 gotasync = 1;
1225#endif
1223 1226
1224 ev_ref (EV_A); 1227 ev_ref (EV_A);
1225 ev_io_stop (EV_A_ &pipeev); 1228 ev_io_stop (EV_A_ &pipeev);
1226 close (evpipe [0]); 1229 close (evpipe [0]);
1227 close (evpipe [1]); 1230 close (evpipe [1]);
2463 2466
2464void 2467void
2465ev_async_send (EV_P_ ev_async *w) 2468ev_async_send (EV_P_ ev_async *w)
2466{ 2469{
2467 w->sent = 1; 2470 w->sent = 1;
2468 evpipe_write (EV_A_ 0, 1); 2471 evpipe_write (EV_A_ &gotasync);
2469} 2472}
2470#endif 2473#endif
2471 2474
2472/*****************************************************************************/ 2475/*****************************************************************************/
2473 2476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines