[gnome-software: 1/2] appstream: Ensure XbBuilders are constructed in the right context
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/2] appstream: Ensure XbBuilders are constructed in the right context
- Date: Tue, 21 Sep 2021 12:24:46 +0000 (UTC)
commit 68b955bb7ff94244793c8ae41e7fe78156b48937
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Sep 20 16:36:17 2021 +0100
appstream: Ensure XbBuilders are constructed in the right context
This is a follow-up to commit 6fb78f853b8183501fb. While that commit was
complete, it will not be sufficient once libxmlb is modified to store
the `GMainContext` at construction time of an `XbSilo`, which is a
long-term solution to the libxmlb side of the threading problem.
Specifically, `xb_builder_new()` constructs a new `XbSilo`, which may
have a long life. Therefore, `xb_builder_new()` needs to be called in
the correct `GMainContext`.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1422
plugins/core/gs-plugin-appstream.c | 13 ++++++++++++-
plugins/flatpak/gs-flatpak.c | 26 ++++++++++++++++++++++++--
2 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 18743c1c8..5d61c5b6a 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -505,7 +505,7 @@ gs_plugin_appstream_check_silo (GsPlugin *plugin,
GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *test_xml;
g_autofree gchar *blobfn = NULL;
- g_autoptr(XbBuilder) builder = xb_builder_new ();
+ g_autoptr(XbBuilder) builder = NULL;
g_autoptr(XbNode) n = NULL;
g_autoptr(GFile) file = NULL;
g_autoptr(GRWLockReaderLocker) reader_locker = NULL;
@@ -525,6 +525,17 @@ gs_plugin_appstream_check_silo (GsPlugin *plugin,
writer_locker = g_rw_lock_writer_locker_new (&priv->silo_lock);
g_clear_object (&priv->silo);
+ /* FIXME: https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1422 */
+ old_thread_default = g_main_context_ref_thread_default ();
+ if (old_thread_default == g_main_context_default ())
+ g_clear_pointer (&old_thread_default, g_main_context_unref);
+ if (old_thread_default != NULL)
+ g_main_context_pop_thread_default (old_thread_default);
+ builder = xb_builder_new ();
+ if (old_thread_default != NULL)
+ g_main_context_push_thread_default (old_thread_default);
+ g_clear_pointer (&old_thread_default, g_main_context_unref);
+
/* verbose profiling */
if (g_getenv ("GS_XMLB_VERBOSE") != NULL) {
xb_builder_set_profile_flags (builder,
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 55a91af2a..af7369be8 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -959,7 +959,7 @@ gs_flatpak_rescan_appstream_store (GsFlatpak *self,
g_autoptr(GPtrArray) xremotes = NULL;
g_autoptr(GRWLockReaderLocker) reader_locker = NULL;
g_autoptr(GRWLockWriterLocker) writer_locker = NULL;
- g_autoptr(XbBuilder) builder = xb_builder_new ();
+ g_autoptr(XbBuilder) builder = NULL;
g_autoptr(GMainContext) old_thread_default = NULL;
reader_locker = g_rw_lock_reader_locker_new (&self->silo_lock);
@@ -972,6 +972,17 @@ gs_flatpak_rescan_appstream_store (GsFlatpak *self,
writer_locker = g_rw_lock_writer_locker_new (&self->silo_lock);
g_clear_object (&self->silo);
+ /* FIXME: https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1422 */
+ old_thread_default = g_main_context_ref_thread_default ();
+ if (old_thread_default == g_main_context_default ())
+ g_clear_pointer (&old_thread_default, g_main_context_unref);
+ if (old_thread_default != NULL)
+ g_main_context_pop_thread_default (old_thread_default);
+ builder = xb_builder_new ();
+ if (old_thread_default != NULL)
+ g_main_context_push_thread_default (old_thread_default);
+ g_clear_pointer (&old_thread_default, g_main_context_unref);
+
/* verbose profiling */
if (g_getenv ("GS_XMLB_VERBOSE") != NULL) {
xb_builder_set_profile_flags (builder,
@@ -2691,7 +2702,7 @@ gs_flatpak_refine_appstream_from_bytes (GsFlatpak *self,
{
const gchar *const *locales = g_get_language_names ();
g_autofree gchar *xpath = NULL;
- g_autoptr(XbBuilder) builder = xb_builder_new ();
+ g_autoptr(XbBuilder) builder = NULL;
g_autoptr(XbBuilderSource) source = xb_builder_source_new ();
g_autoptr(XbNode) component_node = NULL;
g_autoptr(XbNode) n = NULL;
@@ -2703,6 +2714,17 @@ gs_flatpak_refine_appstream_from_bytes (GsFlatpak *self,
g_autoptr(GZlibDecompressor) decompressor = NULL;
g_autoptr(GMainContext) old_thread_default = NULL;
+ /* FIXME: https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1422 */
+ old_thread_default = g_main_context_ref_thread_default ();
+ if (old_thread_default == g_main_context_default ())
+ g_clear_pointer (&old_thread_default, g_main_context_unref);
+ if (old_thread_default != NULL)
+ g_main_context_pop_thread_default (old_thread_default);
+ builder = xb_builder_new ();
+ if (old_thread_default != NULL)
+ g_main_context_push_thread_default (old_thread_default);
+ g_clear_pointer (&old_thread_default, g_main_context_unref);
+
/* add current locales */
for (guint i = 0; locales[i] != NULL; i++)
xb_builder_add_locale (builder, locales[i]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]