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

Comparing libev/ev.c (file contents):
Revision 1.291 by root, Mon Jun 29 04:44:18 2009 UTC vs.
Revision 1.294 by root, Wed Jul 8 02:46:05 2009 UTC

564 564
565#endif 565#endif
566 566
567/*****************************************************************************/ 567/*****************************************************************************/
568 568
569#ifndef EV_HAVE_EV_TIME
569ev_tstamp 570ev_tstamp
570ev_time (void) 571ev_time (void)
571{ 572{
572#if EV_USE_REALTIME 573#if EV_USE_REALTIME
573 if (expect_true (have_realtime)) 574 if (expect_true (have_realtime))
580 581
581 struct timeval tv; 582 struct timeval tv;
582 gettimeofday (&tv, 0); 583 gettimeofday (&tv, 0);
583 return tv.tv_sec + tv.tv_usec * 1e-6; 584 return tv.tv_sec + tv.tv_usec * 1e-6;
584} 585}
586#endif
585 587
586inline_size ev_tstamp 588inline_size ev_tstamp
587get_clock (void) 589get_clock (void)
588{ 590{
589#if EV_USE_MONOTONIC 591#if EV_USE_MONOTONIC
625 627
626 tv.tv_sec = (time_t)delay; 628 tv.tv_sec = (time_t)delay;
627 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); 629 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6);
628 630
629 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ 631 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
630 /* somehting nto guaranteed by newer posix versions, but guaranteed */ 632 /* somehting not guaranteed by newer posix versions, but guaranteed */
631 /* by older ones */ 633 /* by older ones */
632 select (0, 0, 0, 0, &tv); 634 select (0, 0, 0, 0, &tv);
633#endif 635#endif
634 } 636 }
635} 637}
1356ev_loop_count (EV_P) 1358ev_loop_count (EV_P)
1357{ 1359{
1358 return loop_count; 1360 return loop_count;
1359} 1361}
1360 1362
1363unsigned int
1364ev_loop_depth (EV_P)
1365{
1366 return loop_depth;
1367}
1368
1361void 1369void
1362ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 1370ev_set_io_collect_interval (EV_P_ ev_tstamp interval)
1363{ 1371{
1364 io_blocktime = interval; 1372 io_blocktime = interval;
1365} 1373}
2018 2026
2019 mn_now = ev_rt_now; 2027 mn_now = ev_rt_now;
2020 } 2028 }
2021} 2029}
2022 2030
2023static int loop_done;
2024
2025void 2031void
2026ev_loop (EV_P_ int flags) 2032ev_loop (EV_P_ int flags)
2027{ 2033{
2034 ++loop_depth;
2035
2028 loop_done = EVUNLOOP_CANCEL; 2036 loop_done = EVUNLOOP_CANCEL;
2029 2037
2030 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ 2038 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
2031 2039
2032 do 2040 do
2073 ev_tstamp waittime = 0.; 2081 ev_tstamp waittime = 0.;
2074 ev_tstamp sleeptime = 0.; 2082 ev_tstamp sleeptime = 0.;
2075 2083
2076 if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) 2084 if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt)))
2077 { 2085 {
2086 /* remember old timestamp for io_blocktime calculation */
2087 ev_tstamp prev_mn_now = mn_now;
2088
2078 /* update time to cancel out callback processing overhead */ 2089 /* update time to cancel out callback processing overhead */
2079 time_update (EV_A_ 1e100); 2090 time_update (EV_A_ 1e100);
2080 2091
2081 waittime = MAX_BLOCKTIME; 2092 waittime = MAX_BLOCKTIME;
2082 2093
2092 ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; 2103 ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge;
2093 if (waittime > to) waittime = to; 2104 if (waittime > to) waittime = to;
2094 } 2105 }
2095#endif 2106#endif
2096 2107
2108 /* don't let timeouts decrease the waittime below timeout_blocktime */
2097 if (expect_false (waittime < timeout_blocktime)) 2109 if (expect_false (waittime < timeout_blocktime))
2098 waittime = timeout_blocktime; 2110 waittime = timeout_blocktime;
2099 2111
2100 sleeptime = waittime - backend_fudge; 2112 /* extra check because io_blocktime is commonly 0 */
2101
2102 if (expect_true (sleeptime > io_blocktime)) 2113 if (expect_false (io_blocktime))
2103 sleeptime = io_blocktime;
2104
2105 if (sleeptime)
2106 { 2114 {
2115 sleeptime = io_blocktime - (mn_now - prev_mn_now);
2116
2117 if (sleeptime > waittime - backend_fudge)
2118 sleeptime = waittime - backend_fudge;
2119
2120 if (expect_true (sleeptime > 0.))
2121 {
2107 ev_sleep (sleeptime); 2122 ev_sleep (sleeptime);
2108 waittime -= sleeptime; 2123 waittime -= sleeptime;
2124 }
2109 } 2125 }
2110 } 2126 }
2111 2127
2112 ++loop_count; 2128 ++loop_count;
2113 backend_poll (EV_A_ waittime); 2129 backend_poll (EV_A_ waittime);
2139 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) 2155 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK))
2140 )); 2156 ));
2141 2157
2142 if (loop_done == EVUNLOOP_ONE) 2158 if (loop_done == EVUNLOOP_ONE)
2143 loop_done = EVUNLOOP_CANCEL; 2159 loop_done = EVUNLOOP_CANCEL;
2160
2161 --loop_depth;
2144} 2162}
2145 2163
2146void 2164void
2147ev_unloop (EV_P_ int how) 2165ev_unloop (EV_P_ int how)
2148{ 2166{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines