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.371 by root, Mon Feb 7 21:45:32 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
815 select (0, 0, 0, 0, &tv); 816 select (0, 0, 0, 0, &tv);
816#endif 817#endif
817 } 818 }
818} 819}
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;
827}
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 */
823 832
824/* find a suitable new size for the given array, */ 833/* find a suitable new size for the given array, */
965inline_size void 974inline_size void
966fd_reify (EV_P) 975fd_reify (EV_P)
967{ 976{
968 int i; 977 int i;
969 978
979#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
980 for (i = 0; i < fdchangecnt; ++i)
981 {
982 int fd = fdchanges [i];
983 ANFD *anfd = anfds + fd;
984
985 if (anfd->reify & EV__IOFDSET)
986 {
987 SOCKET handle = EV_FD_TO_WIN32_HANDLE (fd);
988
989 if (handle != anfd->handle)
990 {
991 unsigned long arg;
992
993 assert (("libev: only socket fds supported in this configuration", ioctlsocket (handle, FIONREAD, &arg) == 0));
994
995 /* handle changed, but fd didn't - we need to do it in two steps */
996 backend_modify (EV_A_ fd, anfd->events, 0);
997 anfd->events = 0;
998 anfd->handle = handle;
999 }
1000 }
1001 }
1002#endif
1003
970 for (i = 0; i < fdchangecnt; ++i) 1004 for (i = 0; i < fdchangecnt; ++i)
971 { 1005 {
972 int fd = fdchanges [i]; 1006 int fd = fdchanges [i];
973 ANFD *anfd = anfds + fd; 1007 ANFD *anfd = anfds + fd;
974 ev_io *w; 1008 ev_io *w;
975 1009
976 unsigned char o_events = anfd->events; 1010 unsigned char o_events = anfd->events;
977 unsigned char o_reify = anfd->reify; 1011 unsigned char o_reify = anfd->reify;
978 1012
979 anfd->reify = 0; 1013 anfd->reify = 0;
980
981#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
982 if (o_reify & EV__IOFDSET)
983 {
984 unsigned long arg;
985 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
986 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
987 printf ("oi %d %x\n", fd, anfd->handle);//D
988 }
989#endif
990 1014
991 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 1015 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
992 { 1016 {
993 anfd->events = 0; 1017 anfd->events = 0;
994 1018
1343 char dummy; 1367 char dummy;
1344 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1368 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1345 read (evpipe [0], &dummy, 1); 1369 read (evpipe [0], &dummy, 1);
1346 } 1370 }
1347 1371
1372#if EV_SIGNAL_ENABLE
1348 if (sig_pending) 1373 if (sig_pending)
1349 { 1374 {
1350 sig_pending = 0; 1375 sig_pending = 0;
1351 1376
1352 for (i = EV_NSIG - 1; i--; ) 1377 for (i = EV_NSIG - 1; i--; )
1353 if (expect_false (signals [i].pending)) 1378 if (expect_false (signals [i].pending))
1354 ev_feed_signal_event (EV_A_ i + 1); 1379 ev_feed_signal_event (EV_A_ i + 1);
1355 } 1380 }
1381#endif
1356 1382
1357#if EV_ASYNC_ENABLE 1383#if EV_ASYNC_ENABLE
1358 if (async_pending) 1384 if (async_pending)
1359 { 1385 {
1360 async_pending = 0; 1386 async_pending = 0;
2181 feed_reverse_done (EV_A_ EV_TIMER); 2207 feed_reverse_done (EV_A_ EV_TIMER);
2182 } 2208 }
2183} 2209}
2184 2210
2185#if EV_PERIODIC_ENABLE 2211#if EV_PERIODIC_ENABLE
2212
2213inline_speed void
2214periodic_recalc (EV_P_ ev_periodic *w)
2215{
2216 /* TODO: use slow but potentially more correct incremental algo, */
2217 /* also do not rely on ceil */
2218 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2219}
2220
2186/* make periodics pending */ 2221/* make periodics pending */
2187inline_size void 2222inline_size void
2188periodics_reify (EV_P) 2223periodics_reify (EV_P)
2189{ 2224{
2190 EV_FREQUENT_CHECK; 2225 EV_FREQUENT_CHECK;
2209 ANHE_at_cache (periodics [HEAP0]); 2244 ANHE_at_cache (periodics [HEAP0]);
2210 downheap (periodics, periodiccnt, HEAP0); 2245 downheap (periodics, periodiccnt, HEAP0);
2211 } 2246 }
2212 else if (w->interval) 2247 else if (w->interval)
2213 { 2248 {
2214 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2249 periodic_recalc (EV_A_ w);
2250
2215 /* if next trigger time is not sufficiently in the future, put it there */ 2251 /* if next trigger time is not sufficiently in the future, put it there */
2216 /* this might happen because of floating point inexactness */ 2252 /* this might happen because of floating point inexactness */
2217 if (ev_at (w) - ev_rt_now < TIME_EPSILON) 2253 if (ev_at (w) - ev_rt_now < TIME_EPSILON)
2218 { 2254 {
2219 ev_at (w) += w->interval; 2255 ev_at (w) += w->interval;
2253 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); 2289 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]);
2254 2290
2255 if (w->reschedule_cb) 2291 if (w->reschedule_cb)
2256 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2292 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2257 else if (w->interval) 2293 else if (w->interval)
2258 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2294 periodic_recalc (EV_A_ w);
2259 2295
2260 ANHE_at_cache (periodics [i]); 2296 ANHE_at_cache (periodics [i]);
2261 } 2297 }
2262 2298
2263 reheap (periodics, periodiccnt); 2299 reheap (periodics, periodiccnt);
2755 if (w->reschedule_cb) 2791 if (w->reschedule_cb)
2756 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2792 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2757 else if (w->interval) 2793 else if (w->interval)
2758 { 2794 {
2759 assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.)); 2795 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 */ 2796 periodic_recalc (EV_A_ w);
2761 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2762 } 2797 }
2763 else 2798 else
2764 ev_at (w) = w->offset; 2799 ev_at (w) = w->offset;
2765 2800
2766 EV_FREQUENT_CHECK; 2801 EV_FREQUENT_CHECK;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines