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.
This commit is contained in:
Alexander Larsson 2020-09-10 11:00:35 +02:00
parent f74bc8dd3d
commit c7df4317bd
1 changed files with 25 additions and 0 deletions

View File

@ -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>