From f47a4fc3d900e14653bc059717e2805ad4964a67 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 18 May 2014 16:36:08 +0200 Subject: threads: use mpv time for mpthread_cond_timedwait wrapper Use the time as returned by mp_time_us() for mpthread_cond_timedwait(), instead of calculating the struct timespec value based on a timeout. This (probably) makes it easier to wait for a specific deadline. --- misc/dispatch.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'misc') diff --git a/misc/dispatch.c b/misc/dispatch.c index 74576ff469..04def9a24c 100644 --- a/misc/dispatch.c +++ b/misc/dispatch.c @@ -20,6 +20,7 @@ #include "common/common.h" #include "osdep/threads.h" +#include "osdep/timer.h" #include "dispatch.h" @@ -175,11 +176,12 @@ void mp_dispatch_run(struct mp_dispatch_queue *queue, // still process the remaining queue items, and wait for unsuspend.) void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout) { + int64_t wait = timeout > 0 ? mp_add_timeout(mp_time_us(), timeout) : 0; pthread_mutex_lock(&queue->lock); queue->suspended = true; // Wake up thread which called mp_dispatch_suspend(). pthread_cond_broadcast(&queue->cond); - while (queue->head || queue->suspend_requested || timeout > 0) { + while (queue->head || queue->suspend_requested || wait > 0) { if (queue->head) { struct mp_dispatch_item *item = queue->head; queue->head = item->next; @@ -203,13 +205,13 @@ void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout) pthread_cond_broadcast(&queue->cond); } } else { - if (timeout > 0) { - mpthread_cond_timedwait(&queue->cond, &queue->lock, timeout); + if (wait > 0) { + mpthread_cond_timedwait(&queue->cond, &queue->lock, wait); } else { pthread_cond_wait(&queue->cond, &queue->lock); } } - timeout = 0; + wait = 0; } queue->suspended = false; pthread_mutex_unlock(&queue->lock); -- cgit v1.2.3