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

Rémi Denis-Courmont git at videolan.org
Sun Nov 29 14:56:01 CET 2020


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
 };
 



More information about the vlc-commits mailing list