* Improve Conky's overall interval timing
authorBrenden Matthews <brenden1@rty.ca>
Fri, 12 Sep 2008 03:01:33 +0000 (03:01 +0000)
committerBrenden Matthews <brenden1@rty.ca>
Fri, 12 Sep 2008 03:01:33 +0000 (03:01 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1250 7f574dfc-610e-0410-a909-a81674777703

ChangeLog
src/conky.c
src/timed_thread.c

index e744528..01ff7ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,7 +3,8 @@
 2008-09-11
        * Maybe fix missing include bug
        (http://bugs.gentoo.org/show_bug.cgi?id=235233)
-       * Improve timed_thread timing
+       * Improve timed_thread interval timing
+       * Improve Conky's overall interval timing
 
 2008-09-10
        * Improved hddtemp support
index f30f6ee..5597e21 100644 (file)
@@ -6379,7 +6379,7 @@ head:
        }
 }
 
-double current_update_time, last_update_time;
+double current_update_time, next_update_time, last_update_time;
 
 static void generate_text(void)
 {
@@ -6416,6 +6416,12 @@ static void generate_text(void)
                }
        }
 
+       next_update_time += update_interval;
+       if (next_update_time < get_time()) {
+               next_update_time = get_time() + update_interval;
+       } else if (next_update_time > get_time() + update_interval) {
+               next_update_time = get_time() + update_interval;
+       }
        last_update_time = current_update_time;
        total_updates++;
        // free(p);
@@ -7355,6 +7361,7 @@ static void main_loop(void)
 #ifdef SIGNAL_BLOCKING
        sigset_t newmask, oldmask;
 #endif
+       double t;
 #ifdef X11
        Region region = XCreateRegion();
 
@@ -7379,6 +7386,7 @@ static void main_loop(void)
        sigaddset(&newmask, SIGUSR1);
 #endif
 
+       next_update_time = last_update_time = get_time();
        info.looped = 0;
        while (total_run_times == 0 || info.looped < total_run_times) {
                info.looped++;
@@ -7399,10 +7407,12 @@ static void main_loop(void)
                        fd_set fdsr;
                        struct timeval tv;
                        int s;
-                       double t = update_interval - (get_time() - last_update_time);
+                       t = next_update_time - get_time();
 
                        if (t < 0) {
                                t = 0;
+                       } else if (t > update_interval) {
+                               t = update_interval;
                        }
 
                        tv.tv_sec = (long) t;
@@ -7419,8 +7429,8 @@ static void main_loop(void)
                                /* timeout */
                                if (s == 0) {
 #else
-               /* FIXME just sleep for the interval time if no X11 */
-               usleep(update_interval * 1000000);
+               t = (next_update_time - get_time()) * 1000000;
+               usleep((useconds_t)t);
 #endif /* X11 */
                                        update_text();
 #ifdef X11
index 5b45d85..4819a5e 100644 (file)
@@ -208,6 +208,11 @@ int timed_thread_test(timed_thread *p_timed_thread)
                return -1;
        }
 
+       if (rc == 0) {
+               /* runnable_cond was signaled, so tell caller to exit thread */
+               return 1;
+       }
+
        /* absolute future time for next pass */
        p_timed_thread->wait_time.tv_sec += p_timed_thread->interval_time.tv_sec;
        p_timed_thread->wait_time.tv_nsec += p_timed_thread->interval_time.tv_nsec;
@@ -222,11 +227,6 @@ int timed_thread_test(timed_thread *p_timed_thread)
                p_timed_thread->wait_time.tv_nsec = p_timed_thread->wait_time.tv_nsec % 1000000000;
        }
 
-       if (rc == 0) {
-               /* runnable_cond was signaled, so tell caller to exit thread */
-               return 1;
-       }
-
        /* tell caller not to exit yet */
        return 0;
 }