From ff4028f3bf0c241c835d527ddc7cb8aa779f849c Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 23 Apr 2014 20:38:10 +0200 Subject: dispatch: wakeup target thread when locking/suspending Without this, it could happen that both the caller thread and the target thread sleep. --- misc/dispatch.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/dispatch.c b/misc/dispatch.c index 69192e8514..07f8995628 100644 --- a/misc/dispatch.c +++ b/misc/dispatch.c @@ -202,8 +202,15 @@ void mp_dispatch_suspend(struct mp_dispatch_queue *queue) { pthread_mutex_lock(&queue->lock); queue->suspend_requested++; - while (!queue->suspended) + while (!queue->suspended) { + pthread_mutex_unlock(&queue->lock); + if (queue->wakeup_fn) + queue->wakeup_fn(queue->wakeup_ctx); + pthread_mutex_lock(&queue->lock); + if (queue->suspended) + break; pthread_cond_wait(&queue->cond, &queue->lock); + } pthread_mutex_unlock(&queue->lock); } @@ -233,6 +240,14 @@ void mp_dispatch_lock(struct mp_dispatch_queue *queue) queue->locked = true; break; } + if (!queue->suspended) { + pthread_mutex_unlock(&queue->lock); + if (queue->wakeup_fn) + queue->wakeup_fn(queue->wakeup_ctx); + pthread_mutex_lock(&queue->lock); + if (queue->suspended) + continue; + } pthread_cond_wait(&queue->cond, &queue->lock); } pthread_mutex_unlock(&queue->lock); -- cgit v1.2.3