1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

timed thread code

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@952 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2007-09-02 02:22:46 +00:00
parent 578609461f
commit cdbfb7dd53
2 changed files with 21 additions and 3 deletions

View File

@ -234,7 +234,7 @@ void update_stuff()
if (NEED(INFO_MPD)) {
if (!mpd_timed_thread) {
init_mpd_stats(&info);
mpd_timed_thread = timed_thread_create((void*)update_mpd, (void*) NULL, update_interval * 1000000);
mpd_timed_thread = timed_thread_create((void*)update_mpd, (void*) NULL, 500000);
if (!mpd_timed_thread) {
ERR("Failed to create MPD timed thread");
}

View File

@ -25,6 +25,7 @@
#include <pthread.h>
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@ -109,6 +110,10 @@ timed_thread_create (void *(*start_routine)(void*), void *arg, unsigned int inte
/* remaining microseconds convert to nanoseconds */
p_timed_thread->interval_time.tv_nsec = (long)((interval_usecs % 1000000) * 1000);
/*printf ("interval_time.tv_sec = %li, .tv_nsec = %li\n",
p_timed_thread->interval_time.tv_sec,
p_timed_thread->interval_time.tv_nsec);*/
return p_timed_thread;
}
@ -180,9 +185,22 @@ timed_thread_test (timed_thread* p_timed_thread)
assert (p_timed_thread != NULL);
if (now (&wait_time)) return (-1);
/*printf ("PRE:wait_time.tv_secs = %li, .tv_nsecs = %li\n", wait_time.tv_sec, wait_time.tv_nsec);*/
/* now add in the wait interval */
wait_time.tv_sec += p_timed_thread->interval_time.tv_sec;
wait_time.tv_nsec += p_timed_thread->interval_time.tv_nsec;
if (1000000000-wait_time.tv_nsec < p_timed_thread->interval_time.tv_nsec)
{
/* adjust for impending overflow of wait_time.tv_nsec */
wait_time.tv_sec += p_timed_thread->interval_time.tv_sec;
wait_time.tv_sec += (p_timed_thread->interval_time.tv_nsec / 1000000000) + 1;
wait_time.tv_nsec = labs (wait_time.tv_nsec - p_timed_thread->interval_time.tv_nsec);
/*printf ("001:wait_time.tv_secs = %li, .tv_nsecs = %li\n", wait_time.tv_sec, wait_time.tv_nsec);*/
}
else
{
wait_time.tv_sec += p_timed_thread->interval_time.tv_sec;
wait_time.tv_nsec += p_timed_thread->interval_time.tv_nsec;
/*printf ("002:wait_time.tv_secs = %li, .tv_nsecs = %li\n", wait_time.tv_sec, wait_time.tv_nsec);*/
}
/* acquire runnable_cond mutex */
if (pthread_mutex_lock (&p_timed_thread->runnable_mutex))