mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-16 07:03:34 +02:00
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
This commit is contained in:
@@ -1441,6 +1441,7 @@ g_cond_wait_until (GCond *cond,
|
|||||||
struct timespec span;
|
struct timespec span;
|
||||||
guint sampled;
|
guint sampled;
|
||||||
int res;
|
int res;
|
||||||
|
gboolean success;
|
||||||
|
|
||||||
if (end_time < 0)
|
if (end_time < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -1460,9 +1461,10 @@ g_cond_wait_until (GCond *cond,
|
|||||||
sampled = cond->i[0];
|
sampled = cond->i[0];
|
||||||
g_mutex_unlock (mutex);
|
g_mutex_unlock (mutex);
|
||||||
res = syscall (__NR_futex, &cond->i[0], (gsize) FUTEX_WAIT_PRIVATE, (gsize) sampled, &span);
|
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);
|
g_mutex_lock (mutex);
|
||||||
|
|
||||||
return (res < 0 && errno == ETIMEDOUT) ? FALSE : TRUE;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user