From: <pk...@us...> - 2007-09-02 00:58:43
|
Revision: 950 http://conky.svn.sourceforge.net/conky/?rev=950&view=rev Author: pkovacs Date: 2007-09-01 17:58:42 -0700 (Sat, 01 Sep 2007) Log Message: ----------- timed thread stuff Modified Paths: -------------- trunk/conky1/src/timed_thread.c Modified: trunk/conky1/src/timed_thread.c =================================================================== --- trunk/conky1/src/timed_thread.c 2007-09-01 21:18:52 UTC (rev 949) +++ trunk/conky1/src/timed_thread.c 2007-09-02 00:58:42 UTC (rev 950) @@ -47,7 +47,6 @@ pthread_cond_t runnable_cond; /* signalled to stop the thread */ void *(*start_routine)(void*); /* thread function to run */ void *arg; /* thread function argument */ - struct timespec absolute_time; /* absolute future time next timed_thread_test will wait until */ struct timespec interval_time; /* interval_usecs as a struct timespec */ }; @@ -105,9 +104,6 @@ p_timed_thread->start_routine = start_routine; p_timed_thread->arg = arg; - p_timed_thread->absolute_time.tv_sec=0; - p_timed_thread->absolute_time.tv_nsec=0; - /* seconds portion of the microseconds interval */ p_timed_thread->interval_time.tv_sec = (time_t)(interval_usecs / 1000000); /* remaining microseconds convert to nanoseconds */ @@ -178,19 +174,17 @@ int timed_thread_test (timed_thread* p_timed_thread) { - struct timespec nowtime; + struct timespec wait_time; int rc; assert (p_timed_thread != NULL); - /* adjust wait time to now if absolute_time drifted behind */ - now (&nowtime); - if ( ((nowtime.tv_sec * 1000000000) + nowtime.tv_nsec) > - ((p_timed_thread->absolute_time.tv_sec * 1000000000) + p_timed_thread->absolute_time.tv_nsec) ) - { - p_timed_thread->absolute_time.tv_sec = nowtime.tv_sec; - p_timed_thread->absolute_time.tv_nsec = nowtime.tv_nsec; - } + if (now (&wait_time)) return (-1); + /* move the clock backward 1 sec to shift sync slightly earlier than UI thread */ + wait_time.tv_sec -= 1; + /* 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; /* acquire runnable_cond mutex */ if (pthread_mutex_lock (&p_timed_thread->runnable_mutex)) @@ -199,14 +193,10 @@ /* release mutex and wait until future time for runnable_cond to signal */ rc = pthread_cond_timedwait (&p_timed_thread->runnable_cond, &p_timed_thread->runnable_mutex, - &p_timed_thread->absolute_time); + &wait_time); /* mutex re-acquired, so release it */ pthread_mutex_unlock (&p_timed_thread->runnable_mutex); - /* absolute future time for next pass */ - p_timed_thread->absolute_time.tv_sec += p_timed_thread->interval_time.tv_sec; - p_timed_thread->absolute_time.tv_nsec += p_timed_thread->interval_time.tv_nsec; - if (rc==0) return 1; /* runnable_cond was signaled, so tell caller to exit thread */ @@ -231,7 +221,6 @@ { timed_thread_node *p_node; - assert (p_timed_thread != NULL); assert ((addr_of_p_timed_thread == NULL) || (*addr_of_p_timed_thread == p_timed_thread)); if ((p_node = calloc (sizeof (timed_thread_node), 1)) == 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |