From a43723ef17166447800468335f326af366fcf275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 24 Jun 2022 14:07:41 +0400 Subject: [PATCH 1/3] tests/spawn-singlethread: fix test EOL on win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "arg" argument is given in \n-ending form, but the returned result is \r\n-ending. Signed-off-by: Marc-André Lureau --- glib/tests/spawn-singlethread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index e4f15ecab..3ece69dc9 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -295,10 +295,12 @@ test_spawn_async_with_fds (void) if (test_pipe[1][0] >= 0) { + gchar *tmp = g_strdup_printf ("# thread %d" LINEEND, tnum); /* Check for echo on stdout */ g_assert_true (data.stdout_done); - g_assert_cmpstr (data.stdout_buf->str, ==, arg); + g_assert_cmpstr (data.stdout_buf->str, ==, tmp); g_io_channel_unref (channel); + g_free (tmp); } g_string_free (data.stdout_buf, TRUE); From 17ac6642c78aed4fe3a7f7869877cec004aff394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 7 Jul 2022 15:50:10 +0400 Subject: [PATCH 2/3] gmain: do not wakeup the wakeup registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not wakeup immediately for our own context wakeup poll registration. g_main_context_add_poll_unlocked() will call g_wakeup_signal() to wake up the loop waiting in poll(). Doing so during context creation will create an extra wakeup for the first poll(). Skip the wakeup call if it is the wake_up_rec registration. No other sources/caller should ever reach that condition. Signed-off-by: Marc-André Lureau --- glib/gmain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glib/gmain.c b/glib/gmain.c index a0ade8acb..d6a67facb 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -4653,7 +4653,8 @@ g_main_context_add_poll_unlocked (GMainContext *context, context->poll_changed = TRUE; /* Now wake up the main loop if it is waiting in the poll() */ - g_wakeup_signal (context->wakeup); + if (fd != &context->wake_up_rec) + g_wakeup_signal (context->wakeup); } /** From 1a29fd430826fce26ea888de865845c4da255f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 24 Jun 2022 15:08:43 +0400 Subject: [PATCH 3/3] tests/mainloop: iterate for a little while for timeout-once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On win32, WaitForSingleObject may return before the timeout is dispatched, as it doesn't have a resolution higher than the system tick. Wait for ~50ms before checking the callback changes. Signed-off-by: Marc-André Lureau --- glib/tests/mainloop.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c index 105bec87e..c18da94fc 100644 --- a/glib/tests/mainloop.c +++ b/glib/tests/mainloop.c @@ -2349,6 +2349,7 @@ test_maincontext_timeout_once (void) { guint counter = 0, check_counter = 0; guint source_id; + gint64 t; GSource *source; g_test_summary ("Test g_timeout_add_once() works"); @@ -2360,14 +2361,18 @@ test_maincontext_timeout_once (void) /* Iterating the main context should dispatch the source, though we have to block. */ g_assert_cmpuint (counter, ==, 0); - g_main_context_iteration (NULL, TRUE); + t = g_get_monotonic_time (); + while (g_get_monotonic_time () - t < 50 * 1000 && counter == 0) + g_main_context_iteration (NULL, TRUE); g_assert_cmpuint (counter, ==, 1); /* Iterating it again should not dispatch the source again. We add a second * timeout and block until that is dispatched. Given the ordering guarantees, * we should then know whether the first one would have re-dispatched by then. */ g_timeout_add_once (30 /* ms */, once_cb, &check_counter); - g_main_context_iteration (NULL, TRUE); + t = g_get_monotonic_time (); + while (g_get_monotonic_time () - t < 50 * 1000 && check_counter == 0) + g_main_context_iteration (NULL, TRUE); g_assert_cmpuint (check_counter, ==, 1); g_assert_cmpuint (counter, ==, 1); g_assert_true (g_source_is_destroyed (source));