summaryrefslogtreecommitdiff
path: root/src/libotutil/otutil.h
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2020-09-10 11:00:35 +0200
committerAlexander Larsson <alexl@redhat.com>2020-09-11 12:03:28 +0200
commitc7df4317bd965006f7d98186b239b6c0618c6217 (patch)
tree08b72b0e84848a7235124ab3273bc1df482ed323 /src/libotutil/otutil.h
parentf74bc8dd3dd099cb92cdf9c828c48848e0b96703 (diff)
downloadostree-c7df4317bd965006f7d98186b239b6c0618c6217.tar.gz
Add g_autoptr helper for pushing a thread default main context
This happens in a bunch of places, and currently each time it does we have to use "goto out" style cleanups, which just isn't looking very nice.
Diffstat (limited to 'src/libotutil/otutil.h')
-rw-r--r--src/libotutil/otutil.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libotutil/otutil.h b/src/libotutil/otutil.h
index cd312365..7db7270d 100644
--- a/src/libotutil/otutil.h
+++ b/src/libotutil/otutil.h
@@ -52,6 +52,31 @@
#define ot_journal_print(...) {}
#endif
+typedef GMainContext GMainContextPopDefault;
+static inline void
+_ostree_main_context_pop_default_destroy (void *p)
+{
+ GMainContext *main_context = p;
+
+ if (main_context)
+ {
+ g_main_context_pop_thread_default (main_context);
+ g_main_context_unref (main_context);
+ }
+}
+
+static inline GMainContextPopDefault *
+_ostree_main_context_new_default (void)
+{
+ GMainContext *main_context = g_main_context_new ();
+
+ g_main_context_push_thread_default (main_context);
+ return main_context;
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GMainContextPopDefault, _ostree_main_context_pop_default_destroy)
+
+
#include <ot-keyfile-utils.h>
#include <ot-gio-utils.h>
#include <ot-fs-utils.h>