[gnome-software/wip/automatic-update-fixes] plugin-loader: Schedule 'updates-changed' signal when received with no job running



commit f08a886068e3f09425ae8ab4a8ea2aae6e60aa76
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 15 17:55:31 2022 +0200

    plugin-loader: Schedule 'updates-changed' signal when received with no job running
    
    This helps to avoid a race condition when a plugin calls
    updates-changed at the end of the job, but the job is
    finished before the callback gets called in the main thread.

 lib/gs-plugin-loader.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 41670e3cd..cfde97e17 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1767,12 +1767,6 @@ gs_plugin_loader_job_actions_changed_delay_cb (gpointer user_data)
        return FALSE;
 }
 
-static void
-gs_plugin_loader_job_actions_changed_cb (GsPlugin *plugin, GsPluginLoader *plugin_loader)
-{
-       plugin_loader->updates_changed_cnt++;
-}
-
 static void
 gs_plugin_loader_updates_changed (GsPluginLoader *plugin_loader)
 {
@@ -1784,6 +1778,20 @@ gs_plugin_loader_updates_changed (GsPluginLoader *plugin_loader)
                                       g_object_ref (plugin_loader));
 }
 
+static void
+gs_plugin_loader_job_updates_changed_cb (GsPlugin *plugin,
+                                        GsPluginLoader *plugin_loader)
+{
+       plugin_loader->updates_changed_cnt++;
+
+       /* Schedule emit of updates changed when no job is active.
+          This helps to avoid a race condition when a plugin calls
+          updates-changed at the end of the job, but the job is
+          finished before the callback gets called in the main thread. */
+       if (!g_atomic_int_get (&plugin_loader->active_jobs))
+               gs_plugin_loader_updates_changed (plugin_loader);
+}
+
 static gboolean
 gs_plugin_loader_reload_delay_cb (gpointer user_data)
 {
@@ -1842,7 +1850,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
                return;
        }
        g_signal_connect (plugin, "updates-changed",
-                         G_CALLBACK (gs_plugin_loader_job_actions_changed_cb),
+                         G_CALLBACK (gs_plugin_loader_job_updates_changed_cb),
                          plugin_loader);
        g_signal_connect (plugin, "reload",
                          G_CALLBACK (gs_plugin_loader_reload_cb),


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