… | |
… | |
391 | # define inline_speed static noinline |
391 | # define inline_speed static noinline |
392 | #else |
392 | #else |
393 | # define inline_speed static inline |
393 | # define inline_speed static inline |
394 | #endif |
394 | #endif |
395 | |
395 | |
396 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
396 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
|
|
397 | |
|
|
398 | #if EV_MINPRI == EV_MAXPRI |
|
|
399 | # define ABSPRI(w) (((W)w), 0) |
|
|
400 | #else |
397 | #define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
401 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
|
|
402 | #endif |
398 | |
403 | |
399 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
404 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
400 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
405 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
401 | |
406 | |
402 | typedef ev_watcher *W; |
407 | typedef ev_watcher *W; |
… | |
… | |
564 | |
569 | |
565 | #endif |
570 | #endif |
566 | |
571 | |
567 | /*****************************************************************************/ |
572 | /*****************************************************************************/ |
568 | |
573 | |
|
|
574 | #ifndef EV_HAVE_EV_TIME |
569 | ev_tstamp |
575 | ev_tstamp |
570 | ev_time (void) |
576 | ev_time (void) |
571 | { |
577 | { |
572 | #if EV_USE_REALTIME |
578 | #if EV_USE_REALTIME |
573 | if (expect_true (have_realtime)) |
579 | if (expect_true (have_realtime)) |
… | |
… | |
580 | |
586 | |
581 | struct timeval tv; |
587 | struct timeval tv; |
582 | gettimeofday (&tv, 0); |
588 | gettimeofday (&tv, 0); |
583 | return tv.tv_sec + tv.tv_usec * 1e-6; |
589 | return tv.tv_sec + tv.tv_usec * 1e-6; |
584 | } |
590 | } |
|
|
591 | #endif |
585 | |
592 | |
586 | inline_size ev_tstamp |
593 | inline_size ev_tstamp |
587 | get_clock (void) |
594 | get_clock (void) |
588 | { |
595 | { |
589 | #if EV_USE_MONOTONIC |
596 | #if EV_USE_MONOTONIC |
… | |
… | |
625 | |
632 | |
626 | tv.tv_sec = (time_t)delay; |
633 | tv.tv_sec = (time_t)delay; |
627 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
634 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
628 | |
635 | |
629 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
636 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
630 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
637 | /* somehting not guaranteed by newer posix versions, but guaranteed */ |
631 | /* by older ones */ |
638 | /* by older ones */ |
632 | select (0, 0, 0, 0, &tv); |
639 | select (0, 0, 0, 0, &tv); |
633 | #endif |
640 | #endif |
634 | } |
641 | } |
635 | } |
642 | } |
… | |
… | |
1356 | ev_loop_count (EV_P) |
1363 | ev_loop_count (EV_P) |
1357 | { |
1364 | { |
1358 | return loop_count; |
1365 | return loop_count; |
1359 | } |
1366 | } |
1360 | |
1367 | |
|
|
1368 | unsigned int |
|
|
1369 | ev_loop_depth (EV_P) |
|
|
1370 | { |
|
|
1371 | return loop_depth; |
|
|
1372 | } |
|
|
1373 | |
1361 | void |
1374 | void |
1362 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
1375 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
1363 | { |
1376 | { |
1364 | io_blocktime = interval; |
1377 | io_blocktime = interval; |
1365 | } |
1378 | } |
… | |
… | |
2018 | |
2031 | |
2019 | mn_now = ev_rt_now; |
2032 | mn_now = ev_rt_now; |
2020 | } |
2033 | } |
2021 | } |
2034 | } |
2022 | |
2035 | |
2023 | static int loop_done; |
|
|
2024 | |
|
|
2025 | void |
2036 | void |
2026 | ev_loop (EV_P_ int flags) |
2037 | ev_loop (EV_P_ int flags) |
2027 | { |
2038 | { |
|
|
2039 | ++loop_depth; |
|
|
2040 | |
2028 | loop_done = EVUNLOOP_CANCEL; |
2041 | loop_done = EVUNLOOP_CANCEL; |
2029 | |
2042 | |
2030 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
2043 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
2031 | |
2044 | |
2032 | do |
2045 | do |
… | |
… | |
2073 | ev_tstamp waittime = 0.; |
2086 | ev_tstamp waittime = 0.; |
2074 | ev_tstamp sleeptime = 0.; |
2087 | ev_tstamp sleeptime = 0.; |
2075 | |
2088 | |
2076 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2089 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2077 | { |
2090 | { |
|
|
2091 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2092 | ev_tstamp prev_mn_now = mn_now; |
|
|
2093 | |
2078 | /* update time to cancel out callback processing overhead */ |
2094 | /* update time to cancel out callback processing overhead */ |
2079 | time_update (EV_A_ 1e100); |
2095 | time_update (EV_A_ 1e100); |
2080 | |
2096 | |
2081 | waittime = MAX_BLOCKTIME; |
2097 | waittime = MAX_BLOCKTIME; |
2082 | |
2098 | |
… | |
… | |
2092 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2108 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2093 | if (waittime > to) waittime = to; |
2109 | if (waittime > to) waittime = to; |
2094 | } |
2110 | } |
2095 | #endif |
2111 | #endif |
2096 | |
2112 | |
|
|
2113 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
2097 | if (expect_false (waittime < timeout_blocktime)) |
2114 | if (expect_false (waittime < timeout_blocktime)) |
2098 | waittime = timeout_blocktime; |
2115 | waittime = timeout_blocktime; |
2099 | |
2116 | |
2100 | sleeptime = waittime - backend_fudge; |
2117 | /* extra check because io_blocktime is commonly 0 */ |
2101 | |
|
|
2102 | if (expect_true (sleeptime > io_blocktime)) |
2118 | if (expect_false (io_blocktime)) |
2103 | sleeptime = io_blocktime; |
|
|
2104 | |
|
|
2105 | if (sleeptime) |
|
|
2106 | { |
2119 | { |
|
|
2120 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
|
|
2121 | |
|
|
2122 | if (sleeptime > waittime - backend_fudge) |
|
|
2123 | sleeptime = waittime - backend_fudge; |
|
|
2124 | |
|
|
2125 | if (expect_true (sleeptime > 0.)) |
|
|
2126 | { |
2107 | ev_sleep (sleeptime); |
2127 | ev_sleep (sleeptime); |
2108 | waittime -= sleeptime; |
2128 | waittime -= sleeptime; |
|
|
2129 | } |
2109 | } |
2130 | } |
2110 | } |
2131 | } |
2111 | |
2132 | |
2112 | ++loop_count; |
2133 | ++loop_count; |
2113 | backend_poll (EV_A_ waittime); |
2134 | backend_poll (EV_A_ waittime); |
… | |
… | |
2139 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2160 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2140 | )); |
2161 | )); |
2141 | |
2162 | |
2142 | if (loop_done == EVUNLOOP_ONE) |
2163 | if (loop_done == EVUNLOOP_ONE) |
2143 | loop_done = EVUNLOOP_CANCEL; |
2164 | loop_done = EVUNLOOP_CANCEL; |
|
|
2165 | |
|
|
2166 | --loop_depth; |
2144 | } |
2167 | } |
2145 | |
2168 | |
2146 | void |
2169 | void |
2147 | ev_unloop (EV_P_ int how) |
2170 | ev_unloop (EV_P_ int how) |
2148 | { |
2171 | { |
… | |
… | |
2240 | } |
2263 | } |
2241 | |
2264 | |
2242 | inline_size void |
2265 | inline_size void |
2243 | pri_adjust (EV_P_ W w) |
2266 | pri_adjust (EV_P_ W w) |
2244 | { |
2267 | { |
2245 | int pri = w->priority; |
2268 | int pri = ev_priority (w); |
2246 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
2269 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
2247 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
2270 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
2248 | w->priority = pri; |
2271 | ev_set_priority (w, pri); |
2249 | } |
2272 | } |
2250 | |
2273 | |
2251 | inline_speed void |
2274 | inline_speed void |
2252 | ev_start (EV_P_ W w, int active) |
2275 | ev_start (EV_P_ W w, int active) |
2253 | { |
2276 | { |