diff options
author | wm4 <wm4@nowhere> | 2018-05-06 13:32:50 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2018-05-24 19:56:34 +0200 |
commit | a0308d31697c5dd601ee036acbc937c361746cc3 (patch) | |
tree | d3205ff2c5cd61f532c4829a9c981dc37d18014d /player/client.c | |
parent | 22c002138d8b82a021564ddab447fafd90852e75 (diff) | |
download | mpv-a0308d31697c5dd601ee036acbc937c361746cc3.tar.bz2 mpv-a0308d31697c5dd601ee036acbc937c361746cc3.tar.xz |
client: merge can_terminate() function
This has some tricky interactions. In particular, it requires the core
to be locked due to reading outstanding_async, which is documented on
the only caller only. It's probably better to merge it with its only
caller.
The new code should be strictly equivalent, other than the fact that it
doesn't temporarily unlock+lock when entering the loop for the first
time (which doesn't matter here).
Diffstat (limited to 'player/client.c')
-rw-r--r-- | player/client.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/player/client.c b/player/client.c index 2c21dd727c..02a8db2911 100644 --- a/player/client.c +++ b/player/client.c @@ -483,32 +483,29 @@ void mpv_terminate_destroy(mpv_handle *ctx) mp_destroy_client(ctx, true); } -static bool can_terminate(struct MPContext *mpctx) -{ - struct mp_client_api *clients = mpctx->clients; - - pthread_mutex_lock(&clients->lock); - bool ok = clients->num_clients == 0 && mpctx->outstanding_async == 0 && - (mpctx->is_cli || clients->terminate_core_thread); - pthread_mutex_unlock(&clients->lock); - - return ok; -} - // Can be called on the core thread only. Idempotent. void mp_shutdown_clients(struct MPContext *mpctx) { struct mp_client_api *clients = mpctx->clients; - // Prevent that new clients can appear. pthread_mutex_lock(&clients->lock); + + // Prevent that new clients can appear. clients->shutting_down = true; - pthread_mutex_unlock(&clients->lock); - while (!can_terminate(mpctx)) { + // Wait until we can terminate. + while (clients->num_clients || mpctx->outstanding_async || + !(mpctx->is_cli || clients->terminate_core_thread)) + { + pthread_mutex_unlock(&clients->lock); + mp_client_broadcast_event(mpctx, MPV_EVENT_SHUTDOWN, NULL); mp_wait_events(mpctx); + + pthread_mutex_lock(&clients->lock); } + + pthread_mutex_unlock(&clients->lock); } static void *core_thread(void *p) |