… | |
… | |
216 | # include <sys/inotify.h> |
216 | # include <sys/inotify.h> |
217 | #endif |
217 | #endif |
218 | |
218 | |
219 | /**/ |
219 | /**/ |
220 | |
220 | |
|
|
221 | /* |
|
|
222 | * This is used to avoid floating point rounding problems. |
|
|
223 | * It is added to ev_rt_now when scheduling periodics |
|
|
224 | * to ensure progress, time-wise, even when rounding |
|
|
225 | * errors are against us. |
|
|
226 | * This value is good at least till the year 4000. |
|
|
227 | * Better solutions welcome. |
|
|
228 | */ |
|
|
229 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
|
|
230 | |
221 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
231 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
222 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
232 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
223 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
233 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ |
224 | |
234 | |
225 | #if __GNUC__ >= 3 |
235 | #if __GNUC__ >= 3 |
226 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
236 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
227 | # define noinline __attribute__ ((noinline)) |
237 | # define noinline __attribute__ ((noinline)) |
228 | #else |
238 | #else |
… | |
… | |
1231 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1241 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1232 | |
1242 | |
1233 | /* first reschedule or stop timer */ |
1243 | /* first reschedule or stop timer */ |
1234 | if (w->reschedule_cb) |
1244 | if (w->reschedule_cb) |
1235 | { |
1245 | { |
1236 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001220703125 /* 1/8192 */); |
1246 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1237 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1247 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1238 | downheap ((WT *)periodics, periodiccnt, 0); |
1248 | downheap ((WT *)periodics, periodiccnt, 0); |
1239 | } |
1249 | } |
1240 | else if (w->interval) |
1250 | else if (w->interval) |
1241 | { |
1251 | { |
1242 | ((WT)w)->at = w->offset + floor ((ev_rt_now - w->offset) / w->interval + 1.) * w->interval; |
1252 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
1253 | if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; |
1243 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1254 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1244 | downheap ((WT *)periodics, periodiccnt, 0); |
1255 | downheap ((WT *)periodics, periodiccnt, 0); |
1245 | } |
1256 | } |
1246 | else |
1257 | else |
1247 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1258 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
… | |
… | |
1360 | if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) |
1371 | if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) |
1361 | { |
1372 | { |
1362 | #if EV_PERIODIC_ENABLE |
1373 | #if EV_PERIODIC_ENABLE |
1363 | periodics_reschedule (EV_A); |
1374 | periodics_reschedule (EV_A); |
1364 | #endif |
1375 | #endif |
1365 | |
|
|
1366 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1376 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1367 | for (i = 0; i < timercnt; ++i) |
1377 | for (i = 0; i < timercnt; ++i) |
1368 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1378 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1369 | } |
1379 | } |
1370 | |
1380 | |