From: <pk...@us...> - 2006-12-02 23:16:41
|
Revision: 803 http://svn.sourceforge.net/conky/?rev=803&view=rev Author: pkovacs Date: 2006-12-02 15:07:21 -0800 (Sat, 02 Dec 2006) Log Message: ----------- test_timed_thread: acquire mutex before calculating future time Modified Paths: -------------- trunk/conky1/src/timed_thread.c Modified: trunk/conky1/src/timed_thread.c =================================================================== --- trunk/conky1/src/timed_thread.c 2006-12-02 00:02:25 UTC (rev 802) +++ trunk/conky1/src/timed_thread.c 2006-12-02 23:07:21 UTC (rev 803) @@ -122,7 +122,9 @@ } -/* waits required interval for termination signal and returns 1 if got it, 0 otherwise */ +/* thread waits interval_usecs for runnable_cond to be signaled. returns 1 if signaled, + * -1 on error, and 0 otherwise. caller should call timed_thread_exit() on any non-zero + * return value. */ int timed_thread_test (timed_thread* p_timed_thread) { @@ -131,6 +133,10 @@ assert (p_timed_thread != NULL); + /* acquire runnable_cond mutex */ + if (pthread_mutex_lock (&p_timed_thread->runnable_mutex)) + return (-1); /* could not acquire runnable_cond mutex, so tell caller to exit thread */ + /* get the absolute time in the future we stop waiting for condition to signal */ clock_gettime (CLOCK_REALTIME, &abstime); /* seconds portion of the microseconds interval */ @@ -141,10 +147,6 @@ abstime.tv_sec += reltime.tv_sec; abstime.tv_nsec += reltime.tv_nsec; - /* acquire runnable_cond mutex */ - if (pthread_mutex_lock (&p_timed_thread->runnable_mutex)) - return (-1); /* could not acquire runnable_cond mutex, so tell caller to exit thread */ - /* 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, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |