[gnome-software: 4/6] gs-plugin-loader: Run each job thread with a new GMainContext




commit 5d0a641c3daa2b0c2b5702d27ba37b58c30ea61e
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Nov 26 00:16:53 2020 +0000

    gs-plugin-loader: Run each job thread with a new GMainContext
    
    Otherwise the jobs will run with no thread-default main context, which
    means that any main context iteration will typically iterate the global
    default main context, and is likely to either cause code to execute on
    the wrong thread (not thread safe), or to deadlock.
    
    The general rule with GLib is that there should be exactly one,
    distinct, `GMainContext` per thread.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1091

 lib/gs-plugin-loader.c | 2 ++
 1 file changed, 2 insertions(+)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 1c69deea..908a98ca 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -3215,6 +3215,8 @@ gs_plugin_loader_process_thread_cb (GTask *task,
        gboolean add_to_pending_array = FALSE;
        guint max_results;
        GsAppListSortFunc sort_func;
+       g_autoptr(GMainContext) context = g_main_context_new ();
+       g_autoptr(GsMainContextPusher) pusher = gs_main_context_pusher_new (context);
 #ifdef HAVE_SYSPROF
        gint64 begin_time_nsec G_GNUC_UNUSED = SYSPROF_CAPTURE_CURRENT_TIME;
 #endif


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