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

Comparing libev/ev.c (file contents):
Revision 1.211 by root, Tue Feb 19 17:09:28 2008 UTC vs.
Revision 1.218 by root, Sun Mar 23 00:05:03 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);
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); /* watcher should not keep loop alive */ 815 ev_unref (EV_A); /* watcher should not keep loop alive */
816
817 /* in case we received the signal before we had the chance of installing a handler */
818 ev_feed_event (EV_A_ &pipeev, 0);
819 } 816 }
820} 817}
821 818
822void inline_size 819void inline_size
823evpipe_write (EV_P_ int sig, int async) 820evpipe_write (EV_P_ EV_ATOMIC_T *flag)
824{ 821{
825 if (!(gotasync || gotsig)) 822 if (!*flag)
826 { 823 {
827 int old_errno = errno; /* save errno becaue write might clobber it */ 824 int old_errno = errno; /* save errno because write might clobber it */
828 825
829 if (sig) gotsig = 1; 826 *flag = 1;
830 if (async) gotasync = 1;
831
832 write (evpipe [1], &old_errno, 1); 827 write (evpipe [1], &old_errno, 1);
833 828
834 errno = old_errno; 829 errno = old_errno;
835 } 830 }
836} 831}
870} 865}
871 866
872/*****************************************************************************/ 867/*****************************************************************************/
873 868
874static void 869static void
875sighandler (int signum) 870ev_sighandler (int signum)
876{ 871{
877#if EV_MULTIPLICITY 872#if EV_MULTIPLICITY
878 struct ev_loop *loop = &default_loop_struct; 873 struct ev_loop *loop = &default_loop_struct;
879#endif 874#endif
880 875
881#if _WIN32 876#if _WIN32
882 signal (signum, sighandler); 877 signal (signum, ev_sighandler);
883#endif 878#endif
884 879
885 signals [signum - 1].gotsig = 1; 880 signals [signum - 1].gotsig = 1;
886 evpipe_write (EV_A_ 1, 0); 881 evpipe_write (EV_A_ &gotsig);
887} 882}
888 883
889void noinline 884void noinline
890ev_feed_signal_event (EV_P_ int signum) 885ev_feed_signal_event (EV_P_ int signum)
891{ 886{
917#ifndef WIFCONTINUED 912#ifndef WIFCONTINUED
918# define WIFCONTINUED(status) 0 913# define WIFCONTINUED(status) 0
919#endif 914#endif
920 915
921void inline_speed 916void inline_speed
922child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 917child_reap (EV_P_ int chain, int pid, int status)
923{ 918{
924 ev_child *w; 919 ev_child *w;
925 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 920 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
926 921
927 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)
928 { 923 {
929 if ((w->pid == pid || !w->pid) 924 if ((w->pid == pid || !w->pid)
930 && (!traced || (w->flags & 1))) 925 && (!traced || (w->flags & 1)))
931 { 926 {
932 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 */
933 w->rpid = pid; 928 w->rpid = pid;
934 w->rstatus = status; 929 w->rstatus = status;
935 ev_feed_event (EV_A_ (W)w, EV_CHILD); 930 ev_feed_event (EV_A_ (W)w, EV_CHILD);
936 } 931 }
937 } 932 }
951 if (!WCONTINUED 946 if (!WCONTINUED
952 || errno != EINVAL 947 || errno != EINVAL
953 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) 948 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED)))
954 return; 949 return;
955 950
956 /* 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 */
957 /* 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 */
958 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 953 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
959 954
960 child_reap (EV_A_ sw, pid, pid, status); 955 child_reap (EV_A_ pid, pid, status);
961 if (EV_PID_HASHSIZE > 1) 956 if (EV_PID_HASHSIZE > 1)
962 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 */
963} 958}
964 959
965#endif 960#endif
966 961
967/*****************************************************************************/ 962/*****************************************************************************/
1221#endif 1216#endif
1222 1217
1223 if (ev_is_active (&pipeev)) 1218 if (ev_is_active (&pipeev))
1224 { 1219 {
1225 /* 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
1226 gotsig = gotasync = 1; 1224 gotasync = 1;
1225#endif
1227 1226
1228 ev_ref (EV_A); 1227 ev_ref (EV_A);
1229 ev_io_stop (EV_A_ &pipeev); 1228 ev_io_stop (EV_A_ &pipeev);
1230 close (evpipe [0]); 1229 close (evpipe [0]);
1231 close (evpipe [1]); 1230 close (evpipe [1]);
1931 wlist_add (&signals [w->signum - 1].head, (WL)w); 1930 wlist_add (&signals [w->signum - 1].head, (WL)w);
1932 1931
1933 if (!((WL)w)->next) 1932 if (!((WL)w)->next)
1934 { 1933 {
1935#if _WIN32 1934#if _WIN32
1936 signal (w->signum, sighandler); 1935 signal (w->signum, ev_sighandler);
1937#else 1936#else
1938 struct sigaction sa; 1937 struct sigaction sa;
1939 sa.sa_handler = sighandler; 1938 sa.sa_handler = ev_sighandler;
1940 sigfillset (&sa.sa_mask); 1939 sigfillset (&sa.sa_mask);
1941 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 1940 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
1942 sigaction (w->signum, &sa, 0); 1941 sigaction (w->signum, &sa, 0);
1943#endif 1942#endif
1944 } 1943 }
2467 2466
2468void 2467void
2469ev_async_send (EV_P_ ev_async *w) 2468ev_async_send (EV_P_ ev_async *w)
2470{ 2469{
2471 w->sent = 1; 2470 w->sent = 1;
2472 evpipe_write (EV_A_ 0, 1); 2471 evpipe_write (EV_A_ &gotasync);
2473} 2472}
2474#endif 2473#endif
2475 2474
2476/*****************************************************************************/ 2475/*****************************************************************************/
2477 2476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines