diff options
author | wm4 <wm4@nowhere> | 2014-05-18 16:36:08 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-05-18 19:20:32 +0200 |
commit | f47a4fc3d900e14653bc059717e2805ad4964a67 (patch) | |
tree | a8ca8944a10c15bbb46239db62a56940a0d3f7b1 /misc/dispatch.c | |
parent | e209e44ca2fef86ec2ec5513bbb63d4d68ff97b5 (diff) | |
download | mpv-f47a4fc3d900e14653bc059717e2805ad4964a67.tar.bz2 mpv-f47a4fc3d900e14653bc059717e2805ad4964a67.tar.xz |
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.
Diffstat (limited to 'misc/dispatch.c')
-rw-r--r-- | misc/dispatch.c | 10 |
1 files changed, 6 insertions, 4 deletions
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); |