[PATCH] spring: Avoid excessive calculation loops for the spring values

Kristian Høgsberg hoegsberg at gmail.com
Thu Aug 9 09:53:26 PDT 2012


On Thu, Aug 09, 2012 at 03:35:49PM +0100, Rob Bradford wrote:
> From: Rob Bradford <rob at linux.intel.com>
> 
> 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.

Thanks, hopefully we can avoid those
infinite-for-all-practical-purposes loops with this check.

Kristian


> ---
>  src/util.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/src/util.c b/src/util.c
> index fa360c2..4ff451a 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -46,12 +46,15 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
>  {
>  	double force, v, current, step;
>  
> -	/* Avoid entering into an infinite loop */
> -	if (msec - spring->timestamp > UINT32_MAX / 2) {
> -		weston_log("timestamps going backwards (from %u to %u)\n",
> -				spring->timestamp, msec);
> -		spring->current = spring->previous = spring->target;
> -		return;
> +	/* Limit the number of executions of the loop below by ensuring that
> +	 * the timestamp for last update of the spring is no more than 1s ago.
> +	 * This handles the case where time moves backwards or forwards in
> +	 * large jumps.
> +	 */
> +	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;
> -- 
> 1.7.11.2
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list