tests: minor code cleanup of nmtst_main_loop_run()

This commit is contained in:
Thomas Haller 2018-05-07 16:25:33 +02:00
parent 34122c874e
commit 11fedad544

View file

@ -921,33 +921,26 @@ _nmtst_main_loop_run_timeout (gpointer user_data)
{
GMainLoop **p_loop = user_data;
g_assert (p_loop);
g_assert (*p_loop);
g_main_loop_quit (*p_loop);
*p_loop = NULL;
g_assert (p_loop && *p_loop);
g_main_loop_quit (g_steal_pointer (p_loop));
return G_SOURCE_REMOVE;
}
static inline gboolean
nmtst_main_loop_run (GMainLoop *loop, guint timeout_ms)
{
GSource *source = NULL;
guint id = 0;
nm_auto_unref_gsource GSource *source = NULL;
GMainLoop *loopx = loop;
if (timeout_ms > 0) {
source = g_timeout_source_new (timeout_ms);
g_source_set_callback (source, _nmtst_main_loop_run_timeout, &loopx, NULL);
id = g_source_attach (source, g_main_loop_get_context (loop));
g_assert (id);
g_source_unref (source);
g_source_attach (source, g_main_loop_get_context (loop));
}
g_main_loop_run (loop);
if (source && loopx)
if (source)
g_source_destroy (source);
/* if the timeout was reached, return FALSE. */