diff options
author | wm4 <wm4@nowhere> | 2020-03-26 23:40:25 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-03-26 23:40:25 +0100 |
commit | 9bda301eb4d8aa75d435f24146c3a66ab74cafea (patch) | |
tree | f2d9fc03c108fdfc2ede50f91ac4468b7af88530 /player/client.c | |
parent | ca3492213035ac6299fc54803520ee9427595181 (diff) | |
download | mpv-9bda301eb4d8aa75d435f24146c3a66ab74cafea.tar.bz2 mpv-9bda301eb4d8aa75d435f24146c3a66ab74cafea.tar.xz |
command: use client IDs for hooks
Removes weird potential race conditions when a client is removed and a
new one with the same name is created.
Diffstat (limited to 'player/client.c')
-rw-r--r-- | player/client.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/player/client.c b/player/client.c index 41645b5d95..a72cb0125f 100644 --- a/player/client.c +++ b/player/client.c @@ -262,6 +262,14 @@ bool mp_client_exists(struct MPContext *mpctx, const char *client_name) return r; } +bool mp_client_id_exists(struct MPContext *mpctx, int64_t id) +{ + pthread_mutex_lock(&mpctx->clients->lock); + bool r = find_client_id(mpctx->clients, id); + pthread_mutex_unlock(&mpctx->clients->lock); + return r; +} + struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name) { pthread_mutex_lock(&clients->lock); @@ -1825,7 +1833,7 @@ int mpv_hook_add(mpv_handle *ctx, uint64_t reply_userdata, const char *name, int priority) { lock_core(ctx); - mp_hook_add(ctx->mpctx, ctx->name, name, reply_userdata, priority); + mp_hook_add(ctx->mpctx, ctx->name, ctx->id, name, reply_userdata, priority); unlock_core(ctx); return 0; } @@ -1833,7 +1841,7 @@ int mpv_hook_add(mpv_handle *ctx, uint64_t reply_userdata, int mpv_hook_continue(mpv_handle *ctx, uint64_t id) { lock_core(ctx); - int r = mp_hook_continue(ctx->mpctx, ctx->name, id); + int r = mp_hook_continue(ctx->mpctx, ctx->id, id); unlock_core(ctx); return r; } |