[gnome-software: 3/6] gs-utils: Wrap GMainContextPusher if not available
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 3/6] gs-utils: Wrap GMainContextPusher if not available
- Date: Wed, 16 Dec 2020 12:17:35 +0000 (UTC)
commit 2e9f58f37392a57c6025e05ce9dc302aca528cd6
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Nov 26 00:49:52 2020 +0000
gs-utils: Wrap GMainContextPusher if not available
Previously this was backported to `gs-metered.c`. Move the
implementation to `gs-utils.h` so it can be used in other places in
gnome-software in subsequent commits.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1091
lib/gs-metered.c | 25 +++----------------------
lib/gs-utils.h | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/lib/gs-metered.c b/lib/gs-metered.c
index d4afec4d..441b88a3 100644
--- a/lib/gs-metered.c
+++ b/lib/gs-metered.c
@@ -39,30 +39,11 @@
#endif
#include "gs-metered.h"
+#include "gs-utils.h"
#ifdef HAVE_MOGWAI
-/* FIXME: Backported from https://gitlab.gnome.org/GNOME/glib/merge_requests/983.
- * Drop once we can depend on a version of GLib which includes it .*/
-typedef void MainContextPusher;
-
-static inline MainContextPusher *
-main_context_pusher_new (GMainContext *main_context)
-{
- g_main_context_push_thread_default (main_context);
- return (MainContextPusher *) main_context;
-}
-
-static inline void
-main_context_pusher_free (MainContextPusher *pusher)
-{
- g_main_context_pop_thread_default ((GMainContext *) pusher);
-}
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainContextPusher, main_context_pusher_free)
-
-
typedef struct
{
gboolean *out_download_now; /* (unowned) */
@@ -131,14 +112,14 @@ gs_metered_block_on_download_scheduler (GVariant *parameters,
g_autoptr(MwscScheduleEntry) schedule_entry = NULL;
g_autofree gchar *parameters_str = NULL;
g_autoptr(GMainContext) context = NULL;
- g_autoptr(MainContextPusher) pusher = NULL;
+ g_autoptr(GsMainContextPusher) pusher = NULL;
parameters_str = (parameters != NULL) ? g_variant_print (parameters, TRUE) : g_strdup ("(none)");
g_debug ("%s: Waiting with parameters: %s", G_STRFUNC, parameters_str);
/* Push the context early so that the #MwscScheduler is created to run within it. */
context = g_main_context_new ();
- pusher = main_context_pusher_new (context);
+ pusher = gs_main_context_pusher_new (context);
/* Wait until the download can be scheduled.
* FIXME: In future, downloads could be split up by app, so they can all
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index 3964f00b..dc4576ac 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -93,4 +93,27 @@ gboolean gs_utils_parse_evr (const gchar *evr,
gchar **out_release);
void gs_utils_set_online_updates_timestamp (GSettings *settings);
+#if !GLIB_CHECK_VERSION(2, 64, 0)
+typedef void GsMainContextPusher;
+
+static inline GsMainContextPusher *
+gs_main_context_pusher_new (GMainContext *main_context)
+{
+ g_main_context_push_thread_default (main_context);
+ return (GsMainContextPusher *) main_context;
+}
+
+static inline void
+gs_main_context_pusher_free (GsMainContextPusher *pusher)
+{
+ g_main_context_pop_thread_default ((GMainContext *) pusher);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GsMainContextPusher, gs_main_context_pusher_free)
+#else
+#define GsMainContextPusher GMainContextPusher
+#define gs_main_context_pusher_new g_main_context_pusher_new
+#define gs_main_context_pusher_free g_main_context_pusher_free
+#endif
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]