summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2018-05-10 20:30:49 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-05-27 09:23:25 +0200
commit01c02ac08b682de622930b1278c9c14d0ffe6c49 (patch)
treeef6a1be9291b95647cfd1c5dc094496671054418
parentab116c31117a8dd141745db0404b63df04577677 (diff)
downloadglib-01c02ac08b682de622930b1278c9c14d0ffe6c49.tar.gz
g_usleep: round up the next millisecond on Windows. See #1371
The timer tests expect that a small value for sleep does not result in no sleep at all. Round up to the next millisecond to bring it more in line with other platforms. This fixes the glib/timer tests. This makes the 'threadtests' time out since that uses small usleeps a lot and until now didn't wait at all, but now always waits a msec. Reduce the amount of tests done on Windows to get the runtime down to something reasonable again. https://bugzilla.gnome.org/show_bug.cgi?id=795569
-rw-r--r--glib/gtimer.c3
-rw-r--r--gobject/tests/threadtests.c6
2 files changed, 8 insertions, 1 deletions
diff --git a/glib/gtimer.c b/glib/gtimer.c
index de0ef1b93..e95ac0ead 100644
--- a/glib/gtimer.c
+++ b/glib/gtimer.c
@@ -251,7 +251,8 @@ void
g_usleep (gulong microseconds)
{
#ifdef G_OS_WIN32
- Sleep (microseconds / 1000);
+ /* Round up to the next millisecond */
+ Sleep (microseconds ? (1 + (microseconds - 1) / 1000) : 0);
#else
struct timespec request, remaining;
request.tv_sec = microseconds / G_USEC_PER_SEC;
diff --git a/gobject/tests/threadtests.c b/gobject/tests/threadtests.c
index b623e8ba4..bb57bd4a8 100644
--- a/gobject/tests/threadtests.c
+++ b/gobject/tests/threadtests.c
@@ -247,6 +247,12 @@ test_threaded_weak_ref (void)
else
n = NUM_COUNTER_INCREMENTS / 20;
+#ifdef G_OS_WIN32
+ /* On Windows usleep has millisecond resolution and gets rounded up
+ * leading to the test running for a long time. */
+ n /= 10;
+#endif
+
for (i = 0; i < n; i++)
{
UnrefInThreadData data;