From: Alexander Larsson Date: Thu, 10 Sep 2020 09:00:35 +0000 (+0200) Subject: Add g_autoptr helper for pushing a thread default main context X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~7^2~18^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c7df4317bd965006f7d98186b239b6c0618c6217;p=ostree.git 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. --- 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 #include #include