… | |
… | |
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 | |
|
|
821 | inline_speed int |
|
|
822 | ev_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, */ |
… | |
… | |
965 | inline_size void |
974 | inline_size void |
966 | fd_reify (EV_P) |
975 | fd_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; |
… | |
… | |
2111 | for (pri = NUMPRI; pri--; ) |
2137 | for (pri = NUMPRI; pri--; ) |
2112 | while (pendingcnt [pri]) |
2138 | while (pendingcnt [pri]) |
2113 | { |
2139 | { |
2114 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2140 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2115 | |
2141 | |
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; |
2142 | p->w->pending = 0; |
2120 | EV_CB_INVOKE (p->w, p->events); |
2143 | EV_CB_INVOKE (p->w, p->events); |
2121 | EV_FREQUENT_CHECK; |
2144 | EV_FREQUENT_CHECK; |
2122 | } |
2145 | } |
2123 | } |
2146 | } |
… | |
… | |
2184 | feed_reverse_done (EV_A_ EV_TIMER); |
2207 | feed_reverse_done (EV_A_ EV_TIMER); |
2185 | } |
2208 | } |
2186 | } |
2209 | } |
2187 | |
2210 | |
2188 | #if EV_PERIODIC_ENABLE |
2211 | #if EV_PERIODIC_ENABLE |
|
|
2212 | |
|
|
2213 | inline_speed void |
|
|
2214 | periodic_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 | |
2189 | /* make periodics pending */ |
2221 | /* make periodics pending */ |
2190 | inline_size void |
2222 | inline_size void |
2191 | periodics_reify (EV_P) |
2223 | periodics_reify (EV_P) |
2192 | { |
2224 | { |
2193 | EV_FREQUENT_CHECK; |
2225 | EV_FREQUENT_CHECK; |
… | |
… | |
2212 | ANHE_at_cache (periodics [HEAP0]); |
2244 | ANHE_at_cache (periodics [HEAP0]); |
2213 | downheap (periodics, periodiccnt, HEAP0); |
2245 | downheap (periodics, periodiccnt, HEAP0); |
2214 | } |
2246 | } |
2215 | else if (w->interval) |
2247 | else if (w->interval) |
2216 | { |
2248 | { |
2217 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2249 | periodic_recalc (EV_A_ w); |
|
|
2250 | |
2218 | /* 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 */ |
2219 | /* this might happen because of floating point inexactness */ |
2252 | /* this might happen because of floating point inexactness */ |
2220 | if (ev_at (w) - ev_rt_now < TIME_EPSILON) |
2253 | if (ev_at (w) - ev_rt_now < TIME_EPSILON) |
2221 | { |
2254 | { |
2222 | ev_at (w) += w->interval; |
2255 | ev_at (w) += w->interval; |
… | |
… | |
2256 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); |
2289 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); |
2257 | |
2290 | |
2258 | if (w->reschedule_cb) |
2291 | if (w->reschedule_cb) |
2259 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2292 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2260 | else if (w->interval) |
2293 | else if (w->interval) |
2261 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2294 | periodic_recalc (EV_A_ w); |
2262 | |
2295 | |
2263 | ANHE_at_cache (periodics [i]); |
2296 | ANHE_at_cache (periodics [i]); |
2264 | } |
2297 | } |
2265 | |
2298 | |
2266 | reheap (periodics, periodiccnt); |
2299 | reheap (periodics, periodiccnt); |
… | |
… | |
2758 | if (w->reschedule_cb) |
2791 | if (w->reschedule_cb) |
2759 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2792 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
2760 | else if (w->interval) |
2793 | else if (w->interval) |
2761 | { |
2794 | { |
2762 | 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.)); |
2763 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
2796 | periodic_recalc (EV_A_ w); |
2764 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
2765 | } |
2797 | } |
2766 | else |
2798 | else |
2767 | ev_at (w) = w->offset; |
2799 | ev_at (w) = w->offset; |
2768 | |
2800 | |
2769 | EV_FREQUENT_CHECK; |
2801 | EV_FREQUENT_CHECK; |