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

Comparing libev/ev.c (file contents):
Revision 1.367 by root, Tue Jan 11 02:15:58 2011 UTC vs.
Revision 1.370 by root, Sun Jan 30 19:05:41 2011 UTC

376# undef EV_USE_INOTIFY 376# undef EV_USE_INOTIFY
377# define EV_USE_INOTIFY 0 377# define EV_USE_INOTIFY 0
378#endif 378#endif
379 379
380#if !EV_USE_NANOSLEEP 380#if !EV_USE_NANOSLEEP
381# ifndef _WIN32 381/* hp-ux has it in sys/time.h, which we unconditionally include above */
382# if !defined(_WIN32) && !defined(__hpux)
382# include <sys/select.h> 383# include <sys/select.h>
383# endif 384# endif
384#endif 385#endif
385 386
386#if EV_USE_INOTIFY 387#if EV_USE_INOTIFY
813 /* by older ones */ 814 /* by older ones */
814 EV_TV_SET (tv, delay); 815 EV_TV_SET (tv, delay);
815 select (0, 0, 0, 0, &tv); 816 select (0, 0, 0, 0, &tv);
816#endif 817#endif
817 } 818 }
819}
820
821inline_speed int
822ev_timeout_to_ms (ev_tstamp timeout)
823{
824 int ms = timeout * 1000. + .999999;
825
826 return expect_true (ms) ? ms : timeout < 1e-6 ? 0 : 1;
818} 827}
819 828
820/*****************************************************************************/ 829/*****************************************************************************/
821 830
822#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ 831#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
1343 char dummy; 1352 char dummy;
1344 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1353 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1345 read (evpipe [0], &dummy, 1); 1354 read (evpipe [0], &dummy, 1);
1346 } 1355 }
1347 1356
1357#if EV_SIGNAL_ENABLE
1348 if (sig_pending) 1358 if (sig_pending)
1349 { 1359 {
1350 sig_pending = 0; 1360 sig_pending = 0;
1351 1361
1352 for (i = EV_NSIG - 1; i--; ) 1362 for (i = EV_NSIG - 1; i--; )
1353 if (expect_false (signals [i].pending)) 1363 if (expect_false (signals [i].pending))
1354 ev_feed_signal_event (EV_A_ i + 1); 1364 ev_feed_signal_event (EV_A_ i + 1);
1355 } 1365 }
1366#endif
1356 1367
1357#if EV_ASYNC_ENABLE 1368#if EV_ASYNC_ENABLE
1358 if (async_pending) 1369 if (async_pending)
1359 { 1370 {
1360 async_pending = 0; 1371 async_pending = 0;
2181 feed_reverse_done (EV_A_ EV_TIMER); 2192 feed_reverse_done (EV_A_ EV_TIMER);
2182 } 2193 }
2183} 2194}
2184 2195
2185#if EV_PERIODIC_ENABLE 2196#if EV_PERIODIC_ENABLE
2197
2198inline_speed
2199periodic_recalc (EV_P_ ev_periodic *w)
2200{
2201 /* TODO: use slow but potentially more correct incremental algo, */
2202 /* also do not rely on ceil */
2203 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2204}
2205
2186/* make periodics pending */ 2206/* make periodics pending */
2187inline_size void 2207inline_size void
2188periodics_reify (EV_P) 2208periodics_reify (EV_P)
2189{ 2209{
2190 EV_FREQUENT_CHECK; 2210 EV_FREQUENT_CHECK;
2209 ANHE_at_cache (periodics [HEAP0]); 2229 ANHE_at_cache (periodics [HEAP0]);
2210 downheap (periodics, periodiccnt, HEAP0); 2230 downheap (periodics, periodiccnt, HEAP0);
2211 } 2231 }
2212 else if (w->interval) 2232 else if (w->interval)
2213 { 2233 {
2214 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2234 periodic_recalc (EV_A_ w);
2235
2215 /* if next trigger time is not sufficiently in the future, put it there */ 2236 /* if next trigger time is not sufficiently in the future, put it there */
2216 /* this might happen because of floating point inexactness */ 2237 /* this might happen because of floating point inexactness */
2217 if (ev_at (w) - ev_rt_now < TIME_EPSILON) 2238 if (ev_at (w) - ev_rt_now < TIME_EPSILON)
2218 { 2239 {
2219 ev_at (w) += w->interval; 2240 ev_at (w) += w->interval;
2253 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); 2274 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]);
2254 2275
2255 if (w->reschedule_cb) 2276 if (w->reschedule_cb)
2256 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2277 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2257 else if (w->interval) 2278 else if (w->interval)
2258 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2279 periodic_recalc (EV_A_ w);
2259 2280
2260 ANHE_at_cache (periodics [i]); 2281 ANHE_at_cache (periodics [i]);
2261 } 2282 }
2262 2283
2263 reheap (periodics, periodiccnt); 2284 reheap (periodics, periodiccnt);
2755 if (w->reschedule_cb) 2776 if (w->reschedule_cb)
2756 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2777 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2757 else if (w->interval) 2778 else if (w->interval)
2758 { 2779 {
2759 assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.)); 2780 assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.));
2760 /* this formula differs from the one in periodic_reify because we do not always round up */ 2781 periodic_recalc (EV_A_ w);
2761 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2762 } 2782 }
2763 else 2783 else
2764 ev_at (w) = w->offset; 2784 ev_at (w) = w->offset;
2765 2785
2766 EV_FREQUENT_CHECK; 2786 EV_FREQUENT_CHECK;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines