summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2015-07-28 00:14:08 -0700
committerMatthias Clasen <mclasen@redhat.com>2015-12-16 09:15:43 -0500
commita379a0ad59df0b377bd7b047d2e5a56417252992 (patch)
tree4bf4791380ca9314fb1cadc9a4234eadd4c885ab
parent5e73ca974d37ce2cc2204d1fdf0bf13284668963 (diff)
downloadglib-a379a0ad59df0b377bd7b047d2e5a56417252992.tar.gz
gapplication: Acquire the main context before running
Otherwise, we'll acquire it on every loop iteration, which can leave us vulnerable to racing another thread for the acquisition of the main context. This can break methods like g_main_context_invoke, which try to acquire a context to figure out if it can invoke the method synchronously or need to defer to an idle. In these cases, it isn't guaranteed that the invocation function will be invoked in the default main context, e.g. the one that GApplication is holding. This also matches what GMainLoop is doing. https://bugzilla.gnome.org/show_bug.cgi?id=752983
-rw-r--r--gio/gapplication.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/gio/gapplication.c b/gio/gapplication.c
index ef3074b6f..05178e28d 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -2238,6 +2238,9 @@ g_application_open (GApplication *application,
* This function sets the prgname (g_set_prgname()), if not already set,
* to the basename of argv[0].
*
+ * Much like g_main_loop_run(), this function will acquire the main context
+ * for the duration that the application is running.
+ *
* Since 2.40, applications that are not explicitly flagged as services
* or launchers (ie: neither %G_APPLICATION_IS_SERVICE or
* %G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the
@@ -2266,6 +2269,7 @@ g_application_run (GApplication *application,
{
gchar **arguments;
int status;
+ gboolean acquired_context;
g_return_val_if_fail (G_IS_APPLICATION (application), 1);
g_return_val_if_fail (argc == 0 || argv != NULL, 1);
@@ -2293,6 +2297,9 @@ g_application_run (GApplication *application,
g_free (prgname);
}
+ acquired_context = g_main_context_acquire (NULL);
+ g_return_val_if_fail (acquired_context, 0);
+
if (!G_APPLICATION_GET_CLASS (application)
->local_command_line (application, &arguments, &status))
{
@@ -2351,6 +2358,8 @@ g_application_run (GApplication *application,
while (g_main_context_iteration (NULL, FALSE))
;
+ g_main_context_release (NULL);
+
return status;
}