[glib] GCond (linux): fix g_cond_wait_until() return value on timeout
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GCond (linux): fix g_cond_wait_until() return value on timeout
- Date: Wed, 9 Jul 2014 14:59:21 +0000 (UTC)
commit 636cd00c213995ffecd302369515bc3b36257589
Author: Tim-Philipp Müller <tim centricular com>
Date: Sat Jul 5 15:03:22 2014 +0100
GCond (linux): fix g_cond_wait_until() return value on timeout
It should return FALSE on timeout (and only on timeout), and
TRUE otherwise.
https://bugzilla.gnome.org/show_bug.cgi?id=731986
glib/gthread-posix.c | 5 +++--
glib/tests/cond.c | 6 ++++++
2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 54ef769..f4703f5 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1415,6 +1415,7 @@ g_cond_wait_until (GCond *cond,
struct timespec now;
struct timespec span;
guint sampled;
+ int res;
if (end_time < 0)
return FALSE;
@@ -1433,10 +1434,10 @@ g_cond_wait_until (GCond *cond,
sampled = cond->i[0];
g_mutex_unlock (mutex);
- syscall (__NR_futex, &cond->i[0], (gsize) FUTEX_WAIT, (gsize) sampled, &span);
+ res = syscall (__NR_futex, &cond->i[0], (gsize) FUTEX_WAIT, (gsize) sampled, &span);
g_mutex_lock (mutex);
- return TRUE;
+ return (res < 0 && errno == ETIMEDOUT) ? FALSE : TRUE;
}
#endif
diff --git a/glib/tests/cond.c b/glib/tests/cond.c
index f5215e5..f9ef3e2 100644
--- a/glib/tests/cond.c
+++ b/glib/tests/cond.c
@@ -260,6 +260,12 @@ test_wait_until (void)
/* Make sure it's after the until time */
g_assert_cmpint (until, <=, g_get_monotonic_time ());
+ /* Make sure it returns FALSE on timeout */
+ until = g_get_monotonic_time () + G_TIME_SPAN_SECOND / 50;
+ g_mutex_lock (&lock);
+ g_assert (g_cond_wait_until (&cond, &lock, until) == FALSE);
+ g_mutex_unlock (&lock);
+
g_mutex_clear (&lock);
g_cond_clear (&cond);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]