[X2Go-Commits] [libx2goclient] 42/44: src/x2goclient-network-ssh.c: make check thread main loop an instance variable.

git-admin at x2go.org git-admin at x2go.org
Fri Sep 18 01:55:40 CEST 2020


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository libx2goclient.

commit 5157e75a20f454eec8927509b8efd146d063520b
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Fri Sep 18 01:42:46 2020 +0200

    src/x2goclient-network-ssh.c: make check thread main loop an instance variable.
    
    This allows us to modify/control it from other places too (like the main
    thread that creates master connection).
    
    This is especially interesting if anything destroys the connection
    object, since we we'll need to terminate the check thread as well in
    this case.
---
 src/x2goclient-network-ssh.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c
index bfdce29..d0e9a95 100644
--- a/src/x2goclient-network-ssh.c
+++ b/src/x2goclient-network-ssh.c
@@ -119,6 +119,7 @@ struct _X2GoClientNetworkSSH {
   GMutex check_thread_mutex;
   GThread *check_thread;
   GMainContext *check_thread_context;
+  GMainLoop *check_thread_loop;
 };
 
 G_DEFINE_TYPE (X2GoClientNetworkSSH, x2goclient_network_ssh, X2GOCLIENT_TYPE_NETWORK);
@@ -207,6 +208,7 @@ static void x2goclient_network_ssh_init (X2GoClientNetworkSSH * const self) {
   g_mutex_init (&(self->check_thread_mutex));
   self->check_thread = NULL;
   self->check_thread_context = NULL;
+  self->check_thread_loop = NULL;
 }
 
 X2GoClientNetworkSSH* x2goclient_network_ssh_new (const char * const session_path) {
@@ -253,6 +255,10 @@ static void x2goclient_network_ssh_finalize (GObject * const object) {
 
   /* Remove timeout source. */
   g_mutex_lock (&(self->check_thread_mutex));
+  if (self->check_thread_loop) {
+    g_main_context_invoke_full (self->check_thread_context, G_PRIORITY_DEFAULT_IDLE, G_SOURCE_FUNC (&g_main_loop_quit), self->check_thread_loop, NULL);
+  }
+
   if (self->check_timeout_source) {
     g_source_destroy (self->check_timeout_source);
     g_source_unref (self->check_timeout_source);
@@ -1454,7 +1460,6 @@ static void x2goclient_network_ssh_check_timeout_data_free (struct x2goclient_ne
 static gpointer x2goclient_network_ssh_check_timeout_thread_main (const gpointer user_data) {
   gpointer ret = NULL;
 
-  GMainLoop *main_loop = NULL;
   X2GoClientNetworkSSH *self = user_data;
 
   g_return_val_if_fail (X2GOCLIENT_IS_NETWORK_SSH (self), ret);
@@ -1464,13 +1469,13 @@ static gpointer x2goclient_network_ssh_check_timeout_thread_main (const gpointer
   g_main_context_push_thread_default (self->check_thread_context);
   g_mutex_unlock (&(self->check_thread_mutex));
 
-  /* Add new main loop and execute it. */
-  main_loop = g_main_loop_new (main_context, FALSE);
-  g_main_loop_run (main_loop);
+  /* Execute main loop. */
+  g_main_loop_run (self->check_thread_loop);
 
   g_mutex_lock (&(self->check_thread_mutex));
   /* Clean up everything after g_main_loop_run () returned. */
-  g_main_loop_unref (main_loop);
+  g_main_loop_unref (self->check_thread_loop);
+  self->check_thread_loop = NULL;
 
   /* Unmap context. */
   g_main_context_pop_thread_default (self->check_thread_context);
@@ -1492,6 +1497,9 @@ static gboolean x2goclient_network_ssh_start_check_timeout (X2GoClientNetworkSSH
   g_mutex_lock (&(self->check_thread_mutex));
   self->check_thread_context = g_main_context_new ();
 
+  /* Create new main loop. */
+  self->check_thread_loop = g_main_loop_new (self->check_thread_context, FALSE);
+
   /* Create and start thread. */
   self->check_thread = g_thread_new ("check_thread", &x2goclient_network_ssh_check_timeout_thread_main, self);
   g_mutex_unlock (&(self->check_thread_mutex));
@@ -1614,6 +1622,9 @@ static gboolean x2goclient_network_ssh_check_timeout (const gpointer data) {
 
     /* Also, mark the master connection as terminated/gone. */
     self->active_master_conn = FALSE;
+
+    /* Finally, stop the main loop. */
+    g_main_loop_quit (self->check_thread_loop);
     g_mutex_unlock (&(self->check_thread_mutex));
   }
 

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git


More information about the x2go-commits mailing list