diff --git a/ChangeLog b/ChangeLog index e744528f..01ff7baa 100644 --- 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 diff --git a/src/conky.c b/src/conky.c index f30f6ee1..5597e214 100644 --- a/src/conky.c +++ b/src/conky.c @@ -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 diff --git a/src/timed_thread.c b/src/timed_thread.c index 5b45d85f..4819a5e7 100644 --- a/src/timed_thread.c +++ b/src/timed_thread.c @@ -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; }