[gnome-software: 12/29] repos: Clarify threading behaviour
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 12/29] repos: Clarify threading behaviour
- Date: Mon, 6 Dec 2021 10:24:18 +0000 (UTC)
commit 6612f0e91d5892c04107b1300b9ea1c38318b744
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Oct 15 13:57:28 2021 +0100
repos: Clarify threading behaviour
Rename the setup method to clarify its functionality, and the fact that
it should only be run with the plugin’s mutex held.
Ensure accesses to `valid` are atomic, since it’s used from multiple
threads.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
plugins/repos/gs-plugin-repos.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/plugins/repos/gs-plugin-repos.c b/plugins/repos/gs-plugin-repos.c
index 0b956bc43..b4babc394 100644
--- a/plugins/repos/gs-plugin-repos.c
+++ b/plugins/repos/gs-plugin-repos.c
@@ -21,7 +21,7 @@ struct _GsPluginRepos {
GFileMonitor *monitor;
GMutex mutex;
gchar *reposdir;
- gboolean valid;
+ gboolean valid; /* (atomic) */
};
G_DEFINE_TYPE (GsPluginRepos, gs_plugin_repos, GS_TYPE_PLUGIN)
@@ -76,17 +76,17 @@ gs_plugin_repos_finalize (GObject *object)
G_OBJECT_CLASS (gs_plugin_repos_parent_class)->finalize (object);
}
-/* mutex must be held */
+/* Run in a worker thread; mutex must be held */
static gboolean
-gs_plugin_repos_setup (GsPluginRepos *self,
- GCancellable *cancellable,
- GError **error)
+gs_plugin_repos_ensure_valid_locked (GsPluginRepos *self,
+ GCancellable *cancellable,
+ GError **error)
{
g_autoptr(GDir) dir = NULL;
const gchar *fn;
/* already valid */
- if (self->valid)
+ if (g_atomic_int_get (&self->valid))
return TRUE;
/* clear existing */
@@ -146,7 +146,8 @@ gs_plugin_repos_setup (GsPluginRepos *self,
}
/* success */
- self->valid = TRUE;
+ g_atomic_int_set (&self->valid, TRUE);
+
return TRUE;
}
@@ -159,7 +160,7 @@ gs_plugin_repos_changed_cb (GFileMonitor *monitor,
{
GsPluginRepos *self = GS_PLUGIN_REPOS (user_data);
- self->valid = FALSE;
+ g_atomic_int_set (&self->valid, FALSE);
}
gboolean
@@ -179,7 +180,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
G_CALLBACK (gs_plugin_repos_changed_cb), self);
/* unconditionally at startup */
- return gs_plugin_repos_setup (self, cancellable, error);
+ return gs_plugin_repos_ensure_valid_locked (self, cancellable, error);
}
static gboolean
@@ -202,7 +203,7 @@ refine_app_locked (GsPluginRepos *self,
return TRUE;
/* ensure valid */
- if (!gs_plugin_repos_setup (self, cancellable, error))
+ if (!gs_plugin_repos_ensure_valid_locked (self, cancellable, error))
return FALSE;
/* find hostname */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]