glib-aux: add nm_g_main_context_iterate_for_msec() helper

This commit is contained in:
Thomas Haller 2021-08-04 16:53:34 +02:00
parent 17dcef41bd
commit 06713e7645
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 32 additions and 0 deletions

View file

@ -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);
}

View file

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