summary refs log tree commit diff
path: root/src/libnm-glib-aux/nm-shared-utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-03-23 11:51:40 +0100
committerMichael Biebl <biebl@debian.org>2022-03-23 11:51:40 +0100
commit8c623dddbdebe354cb94bfc559a5371a14865317 (patch)
treeb8c48e415a98834ca1e19c8fa677ac04b9c51d4a /src/libnm-glib-aux/nm-shared-utils.c
parent4f887bccf1cde84106588536584a2d54a5b4e6e5 (diff)
New upstream version 1.36.4 upstream/1.36.4
Diffstat (limited to 'src/libnm-glib-aux/nm-shared-utils.c')
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c
index 6e6fed12..563b7cc2 100644
--- a/src/libnm-glib-aux/nm-shared-utils.c
+++ b/src/libnm-glib-aux/nm-shared-utils.c
@@ -6680,3 +6680,23 @@ nm_g_main_context_iterate_for_msec(GMainContext *context, guint timeout_msec)
     while (source)
         g_main_context_iteration(context, TRUE);
 }
+
+/*****************************************************************************/
+
+gboolean
+nm_g_main_context_can_acquire(GMainContext *context)
+{
+    /* Fast path. Usually we don't pass contexts between threads
+     * and operate while iterating the context. Hence, usually we
+     * already acquired the context. Check that first. */
+    if (g_main_context_is_owner(context))
+        return TRUE;
+
+    /* Either the context is not owned, or owned by somebody else. Only
+     * one way to find out. */
+    if (!g_main_context_acquire(context))
+        return FALSE;
+
+    g_main_context_release(context);
+    return TRUE;
+}