timer: Warn about negative timer offsets
authorJonas Ådahl <jadahl@gmail.com>
Mon, 27 Jul 2015 09:26:20 +0000 (17:26 +0800)
committerJonas Ådahl <jadahl@gmail.com>
Tue, 28 Jul 2015 08:15:49 +0000 (16:15 +0800)
Even if it may be caused by extreme stalls, warn if the timer was set to
be triggered even before 'now' when it actually is triggered, as it is
more likely a programming error.

Part of the reason for this commit was not to convert the unsigned int
to a signed int (which abs() does).

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
src/timer.c

index 6a343dbfbe841bc221c6cdab6fb6a80b589ef508..a945f788f9c828ccc5be560f06a1b553389c12a9 100644 (file)
@@ -71,7 +71,10 @@ libinput_timer_set(struct libinput_timer *timer, uint64_t expire)
 {
 #ifndef NDEBUG
        uint64_t now = libinput_now(timer->libinput);
-       if (abs(expire - now) > 5000)
+       if (expire < now)
+               log_bug_libinput(timer->libinput,
+                                "timer offset negative\n");
+       else if ((expire - now) > 5000ULL)
                log_bug_libinput(timer->libinput,
                                 "timer offset more than 5s, now %"
                                 PRIu64 " expire %" PRIu64 "\n",