]> git.ipfire.org Git - people/ms/mstpd.git/commitdiff
Fix jitter in computing one-second interval
authordv1tas <dv1tas@fbe50366-0c72-4402-a84b-5d246361dba7>
Fri, 14 Jun 2013 08:54:49 +0000 (08:54 +0000)
committerdv1tas <dv1tas@fbe50366-0c72-4402-a84b-5d246361dba7>
Fri, 14 Jun 2013 08:54:49 +0000 (08:54 +0000)
Signed-off-by: Jorge Gastón
Signed-off-by: Vitalii Demianets
git-svn-id: svn://svn.code.sf.net/p/mstpd/code/trunk@45 fbe50366-0c72-4402-a84b-5d246361dba7

epoll_loop.c

index d5b3b019057011f1ef9e9fdc0b6cc8a9db48f4f4..e8c0556cc9051393a9ba9cc878a84c22b614bf77 100644 (file)
@@ -94,7 +94,6 @@ static inline int time_diff(struct timeval *second, struct timeval *first)
 static inline void run_timeouts(void)
 {
     bridge_one_second();
-    gettimeofday(&nexttimeout, NULL);
     ++(nexttimeout.tv_sec);
 }
 
@@ -116,6 +115,22 @@ int epoll_main_loop(void)
         if(timeout < 0 || timeout > 1000)
         {
             run_timeouts();
+            /*
+             * Check if system time has changed.
+             * NOTE: we can not differentiate reliably if system
+             * time has changed or we have spent too much time
+             * inside event handlers and run_timeouts().
+             * Fix: use clock_gettime(CLOCK_MONOTONIC, ) instead of
+             * gettimeofday, if it is available.
+             * If it is not available on given system -
+             * the following is the best we can do.
+             */
+            if(timeout < -4000 || timeout > 1000)
+            {
+                /* Most probably, system time has changed */
+                nexttimeout.tv_usec = tv.tv_usec;
+                nexttimeout.tv_sec = tv.tv_sec + 1;
+            }
             timeout = 0;
         }