summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-02 12:45:54 +0100
committerThomas Haller <thaller@redhat.com>2020-01-28 10:54:14 +0100
commit6e7e18c86f711d79a02dde032c334e2005e8aec1 (patch)
tree2b27e41261bc6475694c7bf9ffab40bf4696b3d8
parent24b50625bd1d7f0210703089016817b8ead04682 (diff)
downloadNetworkManager-6e7e18c86f711d79a02dde032c334e2005e8aec1.tar.gz
shared: add nm_g_main_context_is_thread_default() util
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 0b550ad051..e7934cf163 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -1026,6 +1026,25 @@ nm_g_main_context_push_thread_default (GMainContext *context)
return context;
}
+static inline gboolean
+nm_g_main_context_is_thread_default (GMainContext *context)
+{
+ GMainContext *cur_context;
+
+ cur_context = g_main_context_get_thread_default ();
+ if (cur_context == context)
+ return TRUE;
+
+ if (G_UNLIKELY (!cur_context))
+ cur_context = g_main_context_default ();
+ else if (G_UNLIKELY (!context))
+ context = g_main_context_default ();
+ else
+ return FALSE;
+
+ return (cur_context == context);
+}
+
static inline GMainContext *
nm_g_main_context_push_thread_default_if_necessary (GMainContext *context)
{