]> granicus.if.org Git - icinga2/commitdiff
Detect local time changes.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 25 Sep 2012 12:03:41 +0000 (14:03 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 25 Sep 2012 12:03:41 +0000 (14:03 +0200)
lib/base/application.cpp
lib/base/timer.cpp
lib/base/timer.h

index fc36f4605ffbb7b514ac50f7ee074de652b097c9..0838ea9182e4010b205f8f2f3b6e3cc2308a5dc7 100644 (file)
@@ -99,6 +99,8 @@ void Application::RunEventLoop(void)
        double nextProfile = 0;
 #endif /* _DEBUG */
 
+       double lastLoop = Utility::GetTime();
+
        while (!m_ShuttingDown) {
                Object::ClearHeldObjects();
 
@@ -123,6 +125,20 @@ void Application::RunEventLoop(void)
                        nextProfile = Utility::GetTime() + 15.0;
                }
 #endif /* _DEBUG */
+
+               double now = Utility::GetTime();
+
+               if (now < lastLoop) {
+                       /* We moved backwards in time - cool. */
+                       double lostTime = lastLoop - now;
+                       stringstream msgbuf;
+                       msgbuf << "We moved backwards in time: " << lostTime
+                              << " seconds";
+                       Logger::Write(LogInformation, "base", msgbuf.str());
+                       Timer::AdjustTimers(-lostTime);
+               }
+
+               lastLoop = now;
        }
 }
 
index ce24369088642fb7c7ed44c66be6e809e1e68a73..faa8cf1ebc64fb4881071cad514ba359876d3826 100644 (file)
@@ -155,3 +155,16 @@ void Timer::Reschedule(double next)
 {
        m_Next = next;
 }
+
+/**
+ * Adjusts all timers by adding the specified amount of time to their
+ * next scheduled timestamp.
+ *
+ * @param adjustment The adjustment.
+ */
+void Timer::AdjustTimers(double adjustment)
+{
+       BOOST_FOREACH(Timer::Ptr timer, m_Timers) {
+               timer->m_Next += adjustment;
+       }
+}
index 2cde7360ed1b1aa1841af393da79ea88f55e08a5..ab32c624cb8cdd84e81294f2f90641b9922d33ba 100644 (file)
@@ -43,6 +43,7 @@ public:
        double GetInterval(void) const;
 
        static double ProcessTimers(void);
+       static void AdjustTimers(double adjustment);
 
        void Start(void);
        void Stop(void);