mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-24 20:00:20 +00:00
dispatch: wakeup target thread when locking/suspending
Without this, it could happen that both the caller thread and the target thread sleep.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user