[vlc-commits] cli: don't wait for exit to reap dead clients
Rémi Denis-Courmont
git at videolan.org
Sun Nov 29 14:56:12 CET 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 29 15:33:39 2020 +0200| [9095693cd4640b626cb3d7755a39ea609193fd6d] | committer: Rémi Denis-Courmont
cli: don't wait for exit to reap dead clients
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9095693cd4640b626cb3d7755a39ea609193fd6d
---
modules/control/cli/cli.c | 15 ++++++++++++++-
modules/control/cli/cli.h | 2 ++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index b71ff46a02..9c93a26f9a 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -442,6 +442,7 @@ static void *cli_client_thread(void *data)
vlc_restorecancel(canc);
}
+ atomic_store_explicit(&cl->zombie, true, memory_order_release);
return NULL;
}
@@ -454,6 +455,7 @@ static struct cli_client *cli_client_new(intf_thread_t *intf, int fd,
cl->stream = stream;
cl->fd = fd;
+ atomic_init(&cl->zombie, false);
cl->intf = intf;
vlc_mutex_init(&cl->output_lock);
@@ -520,7 +522,6 @@ static void *Run(void *data)
int canc = vlc_savecancel();
struct cli_client *cl = cli_client_new_fd(intf, fd);
- vlc_restorecancel(canc);
if (cl != NULL)
{
@@ -528,6 +529,18 @@ static void *Run(void *data)
vlc_list_append(&cl->node, &sys->clients);
vlc_mutex_unlock(&sys->clients_lock);
}
+
+ /* Reap any dead client */
+ vlc_list_foreach (cl, &sys->clients, node)
+ if (atomic_load_explicit(&cl->zombie, memory_order_acquire))
+ {
+ vlc_mutex_lock(&sys->clients_lock);
+ vlc_list_remove(&cl->node);
+ vlc_mutex_unlock(&sys->clients_lock);
+ cli_client_delete(cl);
+ }
+
+ vlc_restorecancel(canc);
}
}
diff --git a/modules/control/cli/cli.h b/modules/control/cli/cli.h
index 162c8c23cd..d1dde7b9c1 100644
--- a/modules/control/cli/cli.h
+++ b/modules/control/cli/cli.h
@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#include <stdatomic.h>
#include <stdio.h>
#include <vlc_common.h>
#include <vlc_list.h>
@@ -31,6 +32,7 @@ struct cli_client
#ifndef _WIN32
FILE *stream;
int fd;
+ atomic_bool zombie;
vlc_mutex_t output_lock;
struct vlc_list node;
vlc_thread_t thread;
More information about the vlc-commits
mailing list