spring: Avoid excessive calculation loops for the spring values

To handle the case where wall clock time jumps forwards by a large amount or
backwards limit the execution of the spring calculation loop.

We do this by forcing the spring update timestamp to being no older that 1s of
the most current time we've been given. We also present a log message if the
timestamp jumps more than expected.
This commit is contained in:
Rob Bradford 2012-08-09 15:35:49 +01:00 committed by Kristian Høgsberg
parent 5ca1a47e23
commit 84cf541b27

View File

@ -46,12 +46,15 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
{ {
double force, v, current, step; double force, v, current, step;
/* Avoid entering into an infinite loop */ /* Limit the number of executions of the loop below by ensuring that
if (msec - spring->timestamp > UINT32_MAX / 2) { * the timestamp for last update of the spring is no more than 1s ago.
weston_log("timestamps going backwards (from %u to %u)\n", * This handles the case where time moves backwards or forwards in
spring->timestamp, msec); * large jumps.
spring->current = spring->previous = spring->target; */
return; if (msec - spring->timestamp > 1000) {
weston_log("unexpectedly large timestamp jump (from %u to %u)\n",
spring->timestamp, msec);
spring->timestamp = msec - 1000;
} }
step = 0.01; step = 0.01;