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

Comparing libev/ev.c (file contents):
Revision 1.214 by root, Tue Feb 19 19:21:20 2008 UTC vs.
Revision 1.219 by root, Wed Apr 2 10:55:39 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);
819void inline_size 819void inline_size
820evpipe_write (EV_P_ EV_ATOMIC_T *flag) 820evpipe_write (EV_P_ EV_ATOMIC_T *flag)
821{ 821{
822 if (!*flag) 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 *flag = 1; 826 *flag = 1;
827 write (evpipe [1], &old_errno, 1); 827 write (evpipe [1], &old_errno, 1);
828 828
829 errno = old_errno; 829 errno = old_errno;
865} 865}
866 866
867/*****************************************************************************/ 867/*****************************************************************************/
868 868
869static void 869static void
870sighandler (int signum) 870ev_sighandler (int signum)
871{ 871{
872#if EV_MULTIPLICITY 872#if EV_MULTIPLICITY
873 struct ev_loop *loop = &default_loop_struct; 873 struct ev_loop *loop = &default_loop_struct;
874#endif 874#endif
875 875
876#if _WIN32 876#if _WIN32
877 signal (signum, sighandler); 877 signal (signum, ev_sighandler);
878#endif 878#endif
879 879
880 signals [signum - 1].gotsig = 1; 880 signals [signum - 1].gotsig = 1;
881 evpipe_write (EV_A_ &gotsig); 881 evpipe_write (EV_A_ &gotsig);
882} 882}
912#ifndef WIFCONTINUED 912#ifndef WIFCONTINUED
913# define WIFCONTINUED(status) 0 913# define WIFCONTINUED(status) 0
914#endif 914#endif
915 915
916void inline_speed 916void inline_speed
917child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 917child_reap (EV_P_ int chain, int pid, int status)
918{ 918{
919 ev_child *w; 919 ev_child *w;
920 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 920 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
921 921
922 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)
923 { 923 {
924 if ((w->pid == pid || !w->pid) 924 if ((w->pid == pid || !w->pid)
925 && (!traced || (w->flags & 1))) 925 && (!traced || (w->flags & 1)))
926 { 926 {
927 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 */
928 w->rpid = pid; 928 w->rpid = pid;
929 w->rstatus = status; 929 w->rstatus = status;
930 ev_feed_event (EV_A_ (W)w, EV_CHILD); 930 ev_feed_event (EV_A_ (W)w, EV_CHILD);
931 } 931 }
932 } 932 }
946 if (!WCONTINUED 946 if (!WCONTINUED
947 || errno != EINVAL 947 || errno != EINVAL
948 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) 948 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED)))
949 return; 949 return;
950 950
951 /* 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 */
952 /* 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 */
953 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 953 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
954 954
955 child_reap (EV_A_ sw, pid, pid, status); 955 child_reap (EV_A_ pid, pid, status);
956 if (EV_PID_HASHSIZE > 1) 956 if (EV_PID_HASHSIZE > 1)
957 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 */
958} 958}
959 959
960#endif 960#endif
961 961
962/*****************************************************************************/ 962/*****************************************************************************/
1542static int loop_done; 1542static int loop_done;
1543 1543
1544void 1544void
1545ev_loop (EV_P_ int flags) 1545ev_loop (EV_P_ int flags)
1546{ 1546{
1547 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) 1547 loop_done = EVUNLOOP_CANCEL;
1548 ? EVUNLOOP_ONE
1549 : EVUNLOOP_CANCEL;
1550 1548
1551 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 */
1552 1550
1553 do 1551 do
1554 { 1552 {
1650 /* queue check watchers, to be executed first */ 1648 /* queue check watchers, to be executed first */
1651 if (expect_false (checkcnt)) 1649 if (expect_false (checkcnt))
1652 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1650 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1653 1651
1654 call_pending (EV_A); 1652 call_pending (EV_A);
1655
1656 } 1653 }
1657 while (expect_true (activecnt && !loop_done)); 1654 while (expect_true (
1655 activecnt
1656 && !loop_done
1657 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK))
1658 ));
1658 1659
1659 if (loop_done == EVUNLOOP_ONE) 1660 if (loop_done == EVUNLOOP_ONE)
1660 loop_done = EVUNLOOP_CANCEL; 1661 loop_done = EVUNLOOP_CANCEL;
1661} 1662}
1662 1663
1930 wlist_add (&signals [w->signum - 1].head, (WL)w); 1931 wlist_add (&signals [w->signum - 1].head, (WL)w);
1931 1932
1932 if (!((WL)w)->next) 1933 if (!((WL)w)->next)
1933 { 1934 {
1934#if _WIN32 1935#if _WIN32
1935 signal (w->signum, sighandler); 1936 signal (w->signum, ev_sighandler);
1936#else 1937#else
1937 struct sigaction sa; 1938 struct sigaction sa;
1938 sa.sa_handler = sighandler; 1939 sa.sa_handler = ev_sighandler;
1939 sigfillset (&sa.sa_mask); 1940 sigfillset (&sa.sa_mask);
1940 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 */
1941 sigaction (w->signum, &sa, 0); 1942 sigaction (w->signum, &sa, 0);
1942#endif 1943#endif
1943 } 1944 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines