summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllison Karlitskaya <allison.karlitskaya@redhat.com>2019-06-28 10:15:33 +0200
committerPhilip Withnall <withnall@endlessm.com>2019-07-02 11:48:01 +0100
commite4c9a62173c8859599394529a756bf51398d8244 (patch)
tree85502b7c4258767610173621bc739e99cc10f28e
parent23a6173e4eea20ba1e4c8ff8ebed7afb9980e232 (diff)
downloadglib-e4c9a62173c8859599394529a756bf51398d8244.tar.gz
gthread: fix minor errno problem in GCond
The return value from `g_cond_wait_until()` is calculated, based on the value of `errno` after reacquiring the mutex. This is a problem because `errno` can be overwritten in the case the mutex is contended (in which case the slow-path code will re-enter the kernel). Perform the calculation before reacquiring the mutex. See merge request GNOME/glib!958
-rw-r--r--glib/gthread-posix.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 9c0b032e6..322a89c2e 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1439,6 +1439,7 @@ g_cond_wait_until (GCond *cond,
struct timespec span;
guint sampled;
int res;
+ gboolean success;
if (end_time < 0)
return FALSE;
@@ -1458,9 +1459,10 @@ g_cond_wait_until (GCond *cond,
sampled = cond->i[0];
g_mutex_unlock (mutex);
res = syscall (__NR_futex, &cond->i[0], (gsize) FUTEX_WAIT_PRIVATE, (gsize) sampled, &span);
+ success = (res < 0 && errno == ETIMEDOUT) ? FALSE : TRUE;
g_mutex_lock (mutex);
- return (res < 0 && errno == ETIMEDOUT) ? FALSE : TRUE;
+ return success;
}
#endif