summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-04-23 20:38:10 +0200
committerwm4 <wm4@nowhere>2014-04-23 21:16:52 +0200
commitff4028f3bf0c241c835d527ddc7cb8aa779f849c (patch)
treec492227f3b45249d94dc9bdac5d44f2c939dfee7 /misc
parent2b26517ef705c4043419e2e70dacd7760af1137e (diff)
downloadmpv-ff4028f3bf0c241c835d527ddc7cb8aa779f849c.tar.bz2
mpv-ff4028f3bf0c241c835d527ddc7cb8aa779f849c.tar.xz
dispatch: wakeup target thread when locking/suspending
Without this, it could happen that both the caller thread and the target thread sleep.
Diffstat (limited to 'misc')
-rw-r--r--misc/dispatch.c17
1 files changed, 16 insertions, 1 deletions
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);