summaryrefslogtreecommitdiffstats
path: root/player/client.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-02 17:24:33 +0100
committerwm4 <wm4@nowhere>2015-02-02 18:07:37 +0100
commitef827af06cbf334a497fb0de8c9b75188549d03e (patch)
tree7d745d909fbeeae7a8466fff32166a723aa72871 /player/client.c
parent9d8b00f1d6624779ab0db946018042135ef28017 (diff)
downloadmpv-ef827af06cbf334a497fb0de8c9b75188549d03e.tar.bz2
mpv-ef827af06cbf334a497fb0de8c9b75188549d03e.tar.xz
client API: add mpv_wait_async_requests()
This does what it's documented to do. The implementation reuses the code in mpv_detach_destroy(). Due to the way async requests currently work, just sending a synchronous dummy request (like a "ignore" command) would be enough to ensure synchronization, but this code will continue to work even if this changes. The line "ctx->event_mask = 0;" is removed, but it shouldn't be needed. (If a client is somehow very slow to terminate, this could silence an annoying queue overflow message, but all in all it does nothing.) Calling mpv_wait_async_requests() and mpv_wait_event() concurrently is in theory allowed, so change pthread_cond_signal() to pthread_cond_broadcast() to avoid missed wakeups. As requested in issue #1542.
Diffstat (limited to 'player/client.c')
-rw-r--r--player/client.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/player/client.c b/player/client.c
index ae4f1f3898..1c24d5522e 100644
--- a/player/client.c
+++ b/player/client.c
@@ -269,7 +269,7 @@ static void wakeup_client(struct mpv_handle *ctx)
pthread_mutex_lock(&ctx->wakeup_lock);
if (!ctx->need_wakeup) {
ctx->need_wakeup = true;
- pthread_cond_signal(&ctx->wakeup);
+ pthread_cond_broadcast(&ctx->wakeup);
if (ctx->wakeup_cb)
ctx->wakeup_cb(ctx->wakeup_cb_ctx);
if (ctx->wakeup_pipe[0] != -1)
@@ -360,21 +360,25 @@ static void unlock_core(mpv_handle *ctx)
mp_dispatch_unlock(ctx->mpctx->dispatch);
}
+void mpv_wait_async_requests(mpv_handle *ctx)
+{
+ mp_resume_all(ctx);
+
+ pthread_mutex_lock(&ctx->lock);
+ while (ctx->reserved_events || ctx->properties_updating)
+ wait_wakeup(ctx, INT64_MAX);
+ pthread_mutex_unlock(&ctx->lock);
+}
+
void mpv_detach_destroy(mpv_handle *ctx)
{
if (!ctx)
return;
- mp_resume_all(ctx);
-
- pthread_mutex_lock(&ctx->lock);
// reserved_events equals the number of asynchronous requests that weren't
// yet replied. In order to avoid that trying to reply to a removed client
// causes a crash, block until all asynchronous requests were served.
- ctx->event_mask = 0;
- while (ctx->reserved_events || ctx->properties_updating)
- wait_wakeup(ctx, INT64_MAX);
- pthread_mutex_unlock(&ctx->lock);
+ mpv_wait_async_requests(ctx);
struct mp_client_api *clients = ctx->clients;