[PATCH] spring: Avoid looping if time appears to be going backwards

Kristian Høgsberg hoegsberg at gmail.com
Fri Aug 3 10:14:07 PDT 2012


On Fri, Aug 03, 2012 at 05:02:04PM +0100, Rob Bradford wrote:
> From: Rob Bradford <rob at linux.intel.com>
> 
> Since the time values are unsigned integers we can check whether the msec is
> smaller than spring->timestamp by checking if the subtraction overflows into a
> value greater than half the maximum unsigned integer range (ie. top bit set)

Thanks Rob, that should make the spring a little easier to work with.
We still need to figure out why the timestamps go backwards though.

Kristian

> ---
>  src/util.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/util.c b/src/util.c
> index cb03dde..fa360c2 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -46,6 +46,14 @@ 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;
> +	}
> +
>  	step = 0.01;
>  	while (4 < msec - spring->timestamp) {
>  		current = spring->current;
> -- 
> 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