[vlc-devel] [vlc-commits] cli: run each client in dedicated thread

Thomas Guillem thomas at gllm.fr
Mon Nov 30 09:35:01 CET 2020


Hello,

Why do you need a thread per client? Player and playlist controls are fully asynchronous. Why not using poll() with STDIN and sockets?

On Sun, Nov 29, 2020, at 14:56, Rémi Denis-Courmont wrote:
> vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 
> 29 12:26:18 2020 +0200| [2a91ccf4374aa357398d203d03ed1099c6bb3810] | 
> committer: Rémi Denis-Courmont
> 
> cli: run each client in dedicated thread
> 
> This adds support for multiple concurrent client, albeit only on the same
> listener.
> 
> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2a91ccf4374aa357398d203d03ed1099c6bb3810
> ---
> 
>  modules/control/cli/cli.c | 27 ++++++++++-----------------
>  modules/control/cli/cli.h |  1 +
>  2 files changed, 11 insertions(+), 17 deletions(-)
> 
> diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
> index 6ed8df0ce3..e112f68d85 100644
> --- a/modules/control/cli/cli.c
> +++ b/modules/control/cli/cli.c
> @@ -456,6 +456,12 @@ static struct cli_client 
> *cli_client_new(intf_thread_t *intf, int fd,
>      cl->fd = fd;
>      cl->intf = intf;
>      vlc_mutex_init(&cl->output_lock);
> +
> +    if (vlc_clone(&cl->thread, cli_client_thread, cl, 
> VLC_THREAD_PRIORITY_LOW))
> +    {
> +        free(cl);
> +        cl = NULL;
> +    }
>      return cl;
>  }
>  
> @@ -491,6 +497,9 @@ static struct cli_client 
> *cli_client_new_std(intf_thread_t *intf)
>  
>  static void cli_client_delete(struct cli_client *cl)
>  {
> +    vlc_cancel(cl->thread);
> +    vlc_join(cl->thread, NULL);
> +
>      if (cl->stream != stdin)
>          fclose(cl->stream);
>      free(cl);
> @@ -501,10 +510,8 @@ static void *Run(void *data)
>      intf_thread_t *intf = data;
>      intf_sys_t *sys = intf->p_sys;
>  
> -    for (;;)
> +    while (sys->pi_socket_listen != NULL)
>      {
> -        while (vlc_list_is_empty(&sys->clients))
> -        {
>              assert(sys->pi_socket_listen != NULL);
>  
>              int fd = net_Accept(intf, sys->pi_socket_listen);
> @@ -521,20 +528,6 @@ static void *Run(void *data)
>                  vlc_list_append(&cl->node, &sys->clients);
>                  vlc_mutex_unlock(&sys->clients_lock);
>              }
> -        }
> -
> -        struct cli_client *cl = vlc_list_first_entry_or_null(&sys->clients,
> -                                                             struct cli_client,
> -                                                             node);
> -
> -        cli_client_thread(cl);
> -        vlc_mutex_lock(&sys->clients_lock);
> -        vlc_list_remove(&cl->node);
> -        vlc_mutex_unlock(&sys->clients_lock);
> -        cli_client_delete(cl);
> -
> -        if (sys->pi_socket_listen == NULL)
> -            break;
>      }
>  
>      return NULL;
> diff --git a/modules/control/cli/cli.h b/modules/control/cli/cli.h
> index 6b6ae12e7e..162c8c23cd 100644
> --- a/modules/control/cli/cli.h
> +++ b/modules/control/cli/cli.h
> @@ -33,6 +33,7 @@ struct cli_client
>      int fd;
>      vlc_mutex_t output_lock;
>      struct vlc_list node;
> +    vlc_thread_t thread;
>  #endif
>  };
>  
> 
> _______________________________________________
> vlc-commits mailing list
> vlc-commits at videolan.org
> https://mailman.videolan.org/listinfo/vlc-commits
>


More information about the vlc-devel mailing list