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:
wm4
2014-04-23 20:38:10 +02:00
parent 2b26517ef7
commit ff4028f3bf

View File

@@ -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);