[gnome-builder] autotools: log process spawn in main thread



commit 351dd01086ead9c3638338c9824eb992ad014877
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 9 13:24:11 2016 +0300

    autotools: log process spawn in main thread
    
    This was originally intended to ever get called from the main thread, but
    due to simplifying some of the complexity got pushed into a worker thread.
    
    Make sure we log the process spawning via the main thread, so that the
    event dispatched to gtk+ is on the right thread.
    
    We should probably add some helpers to IdeBuildResult to handle running
    from other threads and propagate those log entries to the main thread.
    But that can wait until later, as this fixes the issue.

 plugins/autotools/ide-autotools-build-task.c |   28 ++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/plugins/autotools/ide-autotools-build-task.c b/plugins/autotools/ide-autotools-build-task.c
index c20f056..06957fa 100644
--- a/plugins/autotools/ide-autotools-build-task.c
+++ b/plugins/autotools/ide-autotools-build-task.c
@@ -594,6 +594,23 @@ ide_autotools_build_task_execute_finish (IdeAutotoolsBuildTask  *self,
   return g_task_propagate_boolean (task, error);
 }
 
+static gboolean
+log_in_main (gpointer data)
+{
+  struct {
+    IdeBuildResult *result;
+    gchar *message;
+  } *pair = data;
+
+  ide_build_result_log_stdout (pair->result, "%s", pair->message);
+
+  g_free (pair->message);
+  g_object_unref (pair->result);
+  g_slice_free1 (sizeof *pair, pair);
+
+  return G_SOURCE_REMOVE;
+}
+
 static GSubprocess *
 log_and_spawn (IdeAutotoolsBuildTask  *self,
                IdeSubprocessLauncher  *launcher,
@@ -603,6 +620,10 @@ log_and_spawn (IdeAutotoolsBuildTask  *self,
                ...)
 {
   GSubprocess *ret;
+  struct {
+    IdeBuildResult *result;
+    gchar *message;
+  } *pair;
   GString *log;
   gchar *item;
   va_list args;
@@ -622,9 +643,12 @@ log_and_spawn (IdeAutotoolsBuildTask  *self,
     }
   va_end (args);
 
-  ide_build_result_log_stdout (IDE_BUILD_RESULT (self), "%s", log->str);
+  pair = g_slice_alloc (sizeof *pair);
+  pair->result = g_object_ref (self);
+  pair->message = g_string_free (log, FALSE);
+  g_timeout_add (0, log_in_main, pair);
+
   ret = ide_subprocess_launcher_spawn_sync (launcher, cancellable, error);
-  g_string_free (log, TRUE);
 
   return ret;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]