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

Comparing libev/ev.c (file contents):
Revision 1.366 by root, Mon Jan 10 01:58:54 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;
2111 for (pri = NUMPRI; pri--; ) 2122 for (pri = NUMPRI; pri--; )
2112 while (pendingcnt [pri]) 2123 while (pendingcnt [pri])
2113 { 2124 {
2114 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2125 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
2115 2126
2116 /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/
2117 /* ^ this is no longer true, as pending_w could be here */
2118
2119 p->w->pending = 0; 2127 p->w->pending = 0;
2120 EV_CB_INVOKE (p->w, p->events); 2128 EV_CB_INVOKE (p->w, p->events);
2121 EV_FREQUENT_CHECK; 2129 EV_FREQUENT_CHECK;
2122 } 2130 }
2123} 2131}
2184 feed_reverse_done (EV_A_ EV_TIMER); 2192 feed_reverse_done (EV_A_ EV_TIMER);
2185 } 2193 }
2186} 2194}
2187 2195
2188#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
2189/* make periodics pending */ 2206/* make periodics pending */
2190inline_size void 2207inline_size void
2191periodics_reify (EV_P) 2208periodics_reify (EV_P)
2192{ 2209{
2193 EV_FREQUENT_CHECK; 2210 EV_FREQUENT_CHECK;
2212 ANHE_at_cache (periodics [HEAP0]); 2229 ANHE_at_cache (periodics [HEAP0]);
2213 downheap (periodics, periodiccnt, HEAP0); 2230 downheap (periodics, periodiccnt, HEAP0);
2214 } 2231 }
2215 else if (w->interval) 2232 else if (w->interval)
2216 { 2233 {
2217 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2234 periodic_recalc (EV_A_ w);
2235
2218 /* 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 */
2219 /* this might happen because of floating point inexactness */ 2237 /* this might happen because of floating point inexactness */
2220 if (ev_at (w) - ev_rt_now < TIME_EPSILON) 2238 if (ev_at (w) - ev_rt_now < TIME_EPSILON)
2221 { 2239 {
2222 ev_at (w) += w->interval; 2240 ev_at (w) += w->interval;
2256 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); 2274 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]);
2257 2275
2258 if (w->reschedule_cb) 2276 if (w->reschedule_cb)
2259 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2277 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2260 else if (w->interval) 2278 else if (w->interval)
2261 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2279 periodic_recalc (EV_A_ w);
2262 2280
2263 ANHE_at_cache (periodics [i]); 2281 ANHE_at_cache (periodics [i]);
2264 } 2282 }
2265 2283
2266 reheap (periodics, periodiccnt); 2284 reheap (periodics, periodiccnt);
2758 if (w->reschedule_cb) 2776 if (w->reschedule_cb)
2759 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2777 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2760 else if (w->interval) 2778 else if (w->interval)
2761 { 2779 {
2762 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.));
2763 /* this formula differs from the one in periodic_reify because we do not always round up */ 2781 periodic_recalc (EV_A_ w);
2764 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2765 } 2782 }
2766 else 2783 else
2767 ev_at (w) = w->offset; 2784 ev_at (w) = w->offset;
2768 2785
2769 EV_FREQUENT_CHECK; 2786 EV_FREQUENT_CHECK;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines