mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-03 20:48:31 +00:00
acquire mutex before pthread_cond_timedwait
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@802 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
90f79edbea
commit
fe7f6b52be
@ -127,6 +127,7 @@ int
|
|||||||
timed_thread_test (timed_thread* p_timed_thread)
|
timed_thread_test (timed_thread* p_timed_thread)
|
||||||
{
|
{
|
||||||
struct timespec abstime, reltime;
|
struct timespec abstime, reltime;
|
||||||
|
int rc;
|
||||||
|
|
||||||
assert (p_timed_thread != NULL);
|
assert (p_timed_thread != NULL);
|
||||||
|
|
||||||
@ -140,16 +141,19 @@ timed_thread_test (timed_thread* p_timed_thread)
|
|||||||
abstime.tv_sec += reltime.tv_sec;
|
abstime.tv_sec += reltime.tv_sec;
|
||||||
abstime.tv_nsec += reltime.tv_nsec;
|
abstime.tv_nsec += reltime.tv_nsec;
|
||||||
|
|
||||||
/* wait until future time for runnable_cond to signal */
|
/* acquire runnable_cond mutex */
|
||||||
if (pthread_cond_timedwait (&p_timed_thread->runnable_cond,
|
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,
|
&p_timed_thread->runnable_mutex,
|
||||||
&abstime) != ETIMEDOUT)
|
&abstime);
|
||||||
{
|
/* mutex re-acquired, so release it */
|
||||||
/* runnable_cond was signalled or some error occured */
|
pthread_mutex_unlock (&p_timed_thread->runnable_mutex);
|
||||||
pthread_mutex_unlock (&p_timed_thread->runnable_mutex);
|
|
||||||
/* tell caller to exit */
|
if (rc==0)
|
||||||
return 1;
|
return 1; /* runnable_cond was signaled, so tell caller to exit thread */
|
||||||
}
|
|
||||||
|
|
||||||
/* tell caller not to exit yet */
|
/* tell caller not to exit yet */
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user