… | |
… | |
627 | |
627 | |
628 | tv.tv_sec = (time_t)delay; |
628 | tv.tv_sec = (time_t)delay; |
629 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
629 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
630 | |
630 | |
631 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
631 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
632 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
632 | /* somehting not guaranteed by newer posix versions, but guaranteed */ |
633 | /* by older ones */ |
633 | /* by older ones */ |
634 | select (0, 0, 0, 0, &tv); |
634 | select (0, 0, 0, 0, &tv); |
635 | #endif |
635 | #endif |
636 | } |
636 | } |
637 | } |
637 | } |
… | |
… | |
1358 | ev_loop_count (EV_P) |
1358 | ev_loop_count (EV_P) |
1359 | { |
1359 | { |
1360 | return loop_count; |
1360 | return loop_count; |
1361 | } |
1361 | } |
1362 | |
1362 | |
|
|
1363 | unsigned int |
|
|
1364 | ev_loop_depth (EV_P) |
|
|
1365 | { |
|
|
1366 | return loop_depth; |
|
|
1367 | } |
|
|
1368 | |
1363 | void |
1369 | void |
1364 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
1370 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
1365 | { |
1371 | { |
1366 | io_blocktime = interval; |
1372 | io_blocktime = interval; |
1367 | } |
1373 | } |
… | |
… | |
2020 | |
2026 | |
2021 | mn_now = ev_rt_now; |
2027 | mn_now = ev_rt_now; |
2022 | } |
2028 | } |
2023 | } |
2029 | } |
2024 | |
2030 | |
2025 | static int loop_done; |
|
|
2026 | |
|
|
2027 | void |
2031 | void |
2028 | ev_loop (EV_P_ int flags) |
2032 | ev_loop (EV_P_ int flags) |
2029 | { |
2033 | { |
|
|
2034 | ++loop_depth; |
|
|
2035 | |
2030 | loop_done = EVUNLOOP_CANCEL; |
2036 | loop_done = EVUNLOOP_CANCEL; |
2031 | |
2037 | |
2032 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
2038 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
2033 | |
2039 | |
2034 | do |
2040 | do |
… | |
… | |
2075 | ev_tstamp waittime = 0.; |
2081 | ev_tstamp waittime = 0.; |
2076 | ev_tstamp sleeptime = 0.; |
2082 | ev_tstamp sleeptime = 0.; |
2077 | |
2083 | |
2078 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2084 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2079 | { |
2085 | { |
|
|
2086 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2087 | ev_tstamp prev_mn_now = mn_now; |
|
|
2088 | |
2080 | /* update time to cancel out callback processing overhead */ |
2089 | /* update time to cancel out callback processing overhead */ |
2081 | time_update (EV_A_ 1e100); |
2090 | time_update (EV_A_ 1e100); |
2082 | |
2091 | |
2083 | waittime = MAX_BLOCKTIME; |
2092 | waittime = MAX_BLOCKTIME; |
2084 | |
2093 | |
… | |
… | |
2094 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2103 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2095 | if (waittime > to) waittime = to; |
2104 | if (waittime > to) waittime = to; |
2096 | } |
2105 | } |
2097 | #endif |
2106 | #endif |
2098 | |
2107 | |
|
|
2108 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
2099 | if (expect_false (waittime < timeout_blocktime)) |
2109 | if (expect_false (waittime < timeout_blocktime)) |
2100 | waittime = timeout_blocktime; |
2110 | waittime = timeout_blocktime; |
2101 | |
2111 | |
2102 | sleeptime = waittime - backend_fudge; |
2112 | /* extra check because io_blocktime is commonly 0 */ |
2103 | |
|
|
2104 | if (expect_true (sleeptime > io_blocktime)) |
2113 | if (expect_false (io_blocktime)) |
2105 | sleeptime = io_blocktime; |
|
|
2106 | |
|
|
2107 | if (sleeptime) |
|
|
2108 | { |
2114 | { |
|
|
2115 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
|
|
2116 | |
|
|
2117 | if (sleeptime > waittime - backend_fudge) |
|
|
2118 | sleeptime = waittime - backend_fudge; |
|
|
2119 | |
|
|
2120 | if (expect_true (sleeptime > 0.)) |
|
|
2121 | { |
2109 | ev_sleep (sleeptime); |
2122 | ev_sleep (sleeptime); |
2110 | waittime -= sleeptime; |
2123 | waittime -= sleeptime; |
|
|
2124 | } |
2111 | } |
2125 | } |
2112 | } |
2126 | } |
2113 | |
2127 | |
2114 | ++loop_count; |
2128 | ++loop_count; |
2115 | backend_poll (EV_A_ waittime); |
2129 | backend_poll (EV_A_ waittime); |
… | |
… | |
2141 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2155 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2142 | )); |
2156 | )); |
2143 | |
2157 | |
2144 | if (loop_done == EVUNLOOP_ONE) |
2158 | if (loop_done == EVUNLOOP_ONE) |
2145 | loop_done = EVUNLOOP_CANCEL; |
2159 | loop_done = EVUNLOOP_CANCEL; |
|
|
2160 | |
|
|
2161 | --loop_depth; |
2146 | } |
2162 | } |
2147 | |
2163 | |
2148 | void |
2164 | void |
2149 | ev_unloop (EV_P_ int how) |
2165 | ev_unloop (EV_P_ int how) |
2150 | { |
2166 | { |