From 5a4a9a0e8ab62ae653be2ea09e5dfcac6702cc60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Emil=20Sandst=C3=B8?= Date: Mon, 12 Sep 2016 12:19:00 +0200 Subject: [PATCH] [threads] Correct the spin waiting in 'sleep_interruptable' (#3544) After https://github.com/mono/mono/commit/089c47f1c07bf250d76c36e04675569fc6f5b4ba#diff-e7e458b6256eaa730c145f14a666652aR1141 the code started to use nanoseconds instead of milliseconds. The problem was that this caused 'sleep_interruptable' to spin wait the last millisecond before the wait was over, https://bugzilla.xamarin.com/show_bug.cgi?id=44132. Fix https://bugzilla.xamarin.com/show_bug.cgi?id=44132 --- mono/utils/mono-threads.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mono/utils/mono-threads.c b/mono/utils/mono-threads.c index 3ec45d07c89..d0eedf683e9 100644 --- a/mono/utils/mono-threads.c +++ b/mono/utils/mono-threads.c @@ -1284,7 +1284,7 @@ sleep_interruptable (guint32 ms, gboolean *alerted) *alerted = FALSE; if (ms != INFINITE) - end = mono_100ns_ticks () + (ms * 1000 * 10); + end = mono_msec_ticks() + ms; mono_lazy_initialize (&sleep_init, sleep_initialize); @@ -1292,8 +1292,8 @@ sleep_interruptable (guint32 ms, gboolean *alerted) for (;;) { if (ms != INFINITE) { - now = mono_100ns_ticks (); - if (now > end) + now = mono_msec_ticks(); + if (now >= end) break; } @@ -1304,7 +1304,7 @@ sleep_interruptable (guint32 ms, gboolean *alerted) } if (ms != INFINITE) - mono_coop_cond_timedwait (&sleep_cond, &sleep_mutex, (end - now) / 10 / 1000); + mono_coop_cond_timedwait (&sleep_cond, &sleep_mutex, end - now); else mono_coop_cond_wait (&sleep_cond, &sleep_mutex); -- 2.11.4.GIT