summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-08-04 16:53:34 +0200
committerThomas Haller <thaller@redhat.com>2021-08-06 14:31:05 +0200
commit06713e764572e4c2530e64c8d736799256961e9a (patch)
treebe8cc1f5ffd13725c96daae4f7ca54567d00d9d6
parent17dcef41bdf13f83dd7f5a617609c4e65c610ef5 (diff)
downloadNetworkManager-06713e764572e4c2530e64c8d736799256961e9a.tar.gz
glib-aux: add nm_g_main_context_iterate_for_msec() helper
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.c30
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h2
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c
index f2483da1ad..22354d17df 100644
--- a/src/libnm-glib-aux/nm-shared-utils.c
+++ b/src/libnm-glib-aux/nm-shared-utils.c
@@ -6548,3 +6548,33 @@ nm_utils_thread_local_register_destroy(gpointer tls_data, GDestroyNotify destroy
entry->destroy_notify = destroy_notify;
c_list_link_tail(lst_head, &entry->lst);
}
+
+/*****************************************************************************/
+
+static gboolean
+_iterate_for_msec_timeout(gpointer user_data)
+{
+ GSource **p_source = user_data;
+
+ nm_clear_g_source_inst(p_source);
+ return G_SOURCE_CONTINUE;
+}
+
+void
+nm_g_main_context_iterate_for_msec(GMainContext *context, guint timeout_msec)
+{
+ GSource *source;
+
+ /* In production is this function not very useful. It is however useful to
+ * have in the toolbox for printf debugging. */
+
+ source = g_timeout_source_new(timeout_msec);
+ g_source_set_callback(source, _iterate_for_msec_timeout, &source, NULL);
+
+ if (!context)
+ context = g_main_context_default();
+
+ g_source_attach(source, context);
+ while (source)
+ g_main_context_iteration(context, TRUE);
+}
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index fd7f7dc309..975897602d 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -1901,6 +1901,8 @@ nm_g_main_context_iterate_ready(GMainContext *context)
}
}
+void nm_g_main_context_iterate_for_msec(GMainContext *context, guint timeout_msec);
+
/*****************************************************************************/
static inline int