From b1492aa13005c9148a5b64baff5a3957bb591c65 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 20 Feb 2018 11:18:49 +0100 Subject: [PATCH] thread-loop: ensure the right clock is used Use the right clock for the cond variable. --- src/pipewire/thread-loop.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pipewire/thread-loop.c b/src/pipewire/thread-loop.c index 938f603d6..38511e2ae 100644 --- a/src/pipewire/thread-loop.c +++ b/src/pipewire/thread-loop.c @@ -89,6 +89,7 @@ struct pw_thread_loop *pw_thread_loop_new(struct pw_loop *loop, { struct pw_thread_loop *this; pthread_mutexattr_t attr; + pthread_condattr_t cattr; this = calloc(1, sizeof(struct pw_thread_loop)); if (this == NULL) @@ -106,8 +107,10 @@ struct pw_thread_loop *pw_thread_loop_new(struct pw_loop *loop, pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&this->lock, &attr); - pthread_cond_init(&this->cond, NULL); - pthread_cond_init(&this->accept_cond, NULL); + pthread_condattr_init(&cattr); + pthread_condattr_setclock(&cattr, CLOCK_REALTIME); + pthread_cond_init(&this->cond, &cattr); + pthread_cond_init(&this->accept_cond, &cattr); this->event = pw_loop_add_event(this->loop, do_stop, this); @@ -278,13 +281,13 @@ void pw_thread_loop_wait(struct pw_thread_loop *loop) */ int pw_thread_loop_timed_wait(struct pw_thread_loop *loop, int wait_max_sec) { - struct timeval now; - gettimeofday(&now, NULL); struct timespec timeout; - timeout.tv_sec = now.tv_sec + wait_max_sec; - timeout.tv_nsec = now.tv_usec * 1000; int ret = 0; + clock_gettime(CLOCK_REALTIME, &timeout); + + timeout.tv_sec += wait_max_sec; + loop->n_waiting++; ret = pthread_cond_timedwait(&loop->cond, &loop->lock, &timeout); loop->n_waiting--;