ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.177 by root, Tue Dec 11 15:06:50 2007 UTC vs.
Revision 1.178 by root, Tue Dec 11 18:36:11 2007 UTC

1304 } 1304 }
1305 } 1305 }
1306} 1306}
1307#endif 1307#endif
1308 1308
1309int inline_size 1309void inline_speed
1310time_update_monotonic (EV_P) 1310time_update (EV_P_ ev_tstamp max_block)
1311{ 1311{
1312 int i;
1313
1314#if EV_USE_MONOTONIC
1315 if (expect_true (have_monotonic))
1316 {
1317 ev_tstamp odiff = rtmn_diff;
1318
1312 mn_now = get_clock (); 1319 mn_now = get_clock ();
1313 1320
1321 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */
1322 /* interpolate in the meantime */
1314 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 1323 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
1315 { 1324 {
1316 ev_rt_now = rtmn_diff + mn_now; 1325 ev_rt_now = rtmn_diff + mn_now;
1317 return 0; 1326 return;
1318 } 1327 }
1319 else 1328
1320 {
1321 now_floor = mn_now; 1329 now_floor = mn_now;
1322 ev_rt_now = ev_time (); 1330 ev_rt_now = ev_time ();
1323 return 1;
1324 }
1325}
1326 1331
1327void inline_size 1332 /* loop a few times, before making important decisions.
1328time_update (EV_P) 1333 * on the choice of "4": one iteration isn't enough,
1329{ 1334 * in case we get preempted during the calls to
1330 int i; 1335 * ev_time and get_clock. a second call is almost guaranteed
1331 1336 * to succeed in that case, though. and looping a few more times
1332#if EV_USE_MONOTONIC 1337 * doesn't hurt either as we only do this on time-jumps or
1333 if (expect_true (have_monotonic)) 1338 * in the unlikely event of having been preempted here.
1334 { 1339 */
1335 if (time_update_monotonic (EV_A)) 1340 for (i = 4; --i; )
1336 { 1341 {
1337 ev_tstamp odiff = rtmn_diff;
1338
1339 /* loop a few times, before making important decisions.
1340 * on the choice of "4": one iteration isn't enough,
1341 * in case we get preempted during the calls to
1342 * ev_time and get_clock. a second call is almost guaranteed
1343 * to succeed in that case, though. and looping a few more times
1344 * doesn't hurt either as we only do this on time-jumps or
1345 * in the unlikely event of having been preempted here.
1346 */
1347 for (i = 4; --i; )
1348 {
1349 rtmn_diff = ev_rt_now - mn_now; 1342 rtmn_diff = ev_rt_now - mn_now;
1350 1343
1351 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1344 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)
1352 return; /* all is well */ 1345 return; /* all is well */
1353 1346
1354 ev_rt_now = ev_time (); 1347 ev_rt_now = ev_time ();
1355 mn_now = get_clock (); 1348 mn_now = get_clock ();
1356 now_floor = mn_now; 1349 now_floor = mn_now;
1357 } 1350 }
1358 1351
1359# if EV_PERIODIC_ENABLE 1352# if EV_PERIODIC_ENABLE
1360 periodics_reschedule (EV_A); 1353 periodics_reschedule (EV_A);
1361# endif 1354# endif
1362 /* no timer adjustment, as the monotonic clock doesn't jump */ 1355 /* no timer adjustment, as the monotonic clock doesn't jump */
1363 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ 1356 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
1364 }
1365 } 1357 }
1366 else 1358 else
1367#endif 1359#endif
1368 { 1360 {
1369 ev_rt_now = ev_time (); 1361 ev_rt_now = ev_time ();
1370 1362
1371 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 1363 if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP))
1372 { 1364 {
1373#if EV_PERIODIC_ENABLE 1365#if EV_PERIODIC_ENABLE
1374 periodics_reschedule (EV_A); 1366 periodics_reschedule (EV_A);
1375#endif 1367#endif
1376 /* adjust timers. this is easy, as the offset is the same for all of them */ 1368 /* adjust timers. this is easy, as the offset is the same for all of them */
1450 if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) 1442 if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt))
1451 block = 0.; /* do not block at all */ 1443 block = 0.; /* do not block at all */
1452 else 1444 else
1453 { 1445 {
1454 /* update time to cancel out callback processing overhead */ 1446 /* update time to cancel out callback processing overhead */
1455#if EV_USE_MONOTONIC
1456 if (expect_true (have_monotonic))
1457 time_update_monotonic (EV_A); 1447 time_update (EV_A_ 1e100);
1458 else
1459#endif
1460 {
1461 ev_rt_now = ev_time ();
1462 mn_now = ev_rt_now;
1463 }
1464 1448
1465 block = MAX_BLOCKTIME; 1449 block = MAX_BLOCKTIME;
1466 1450
1467 if (timercnt) 1451 if (timercnt)
1468 { 1452 {
1481 if (expect_false (block < 0.)) block = 0.; 1465 if (expect_false (block < 0.)) block = 0.;
1482 } 1466 }
1483 1467
1484 ++loop_count; 1468 ++loop_count;
1485 backend_poll (EV_A_ block); 1469 backend_poll (EV_A_ block);
1470
1471 /* update ev_rt_now, do magic */
1472 time_update (EV_A_ block);
1486 } 1473 }
1487
1488 /* update ev_rt_now, do magic */
1489 time_update (EV_A);
1490 1474
1491 /* queue pending timers and reschedule them */ 1475 /* queue pending timers and reschedule them */
1492 timers_reify (EV_A); /* relative timers called last */ 1476 timers_reify (EV_A); /* relative timers called last */
1493#if EV_PERIODIC_ENABLE 1477#if EV_PERIODIC_ENABLE
1494 periodics_reify (EV_A); /* absolute timers called first */ 1478 periodics_reify (EV_A); /* absolute timers called first */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines