From 686c9555c9f22c3cd3da23ff3163dd7c0d041d6b Mon Sep 17 00:00:00 2001 From: Toby Schneider Date: Tue, 1 Nov 2016 12:14:09 -0400 Subject: [PATCH] Fix overflow in register_timer functionality in GobyMOOSApp; also adjust for time skews in system clock. Fixes #15 --- src/moos/goby_moos_app.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/moos/goby_moos_app.h b/src/moos/goby_moos_app.h index 9129363e..3f90674f 100644 --- a/src/moos/goby_moos_app.h +++ b/src/moos/goby_moos_app.h @@ -293,7 +293,7 @@ template struct SynchronousLoop { - int unix_next; + double unix_next; int period_seconds; boost::function handler; }; @@ -368,7 +368,17 @@ template { loop.handler(); loop.unix_next += loop.period_seconds; + + // fix jumps forward in time + if(loop.unix_next < now) + loop.unix_next = now + loop.period_seconds; + } + + // fix jumps backwards in time + if(loop.unix_next > (now + 2*loop.period_seconds)) + loop.unix_next = now + loop.period_seconds; + } }