summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@oracle.com>2016-01-26 09:18:10 +0100
committerJon Olav Hauglid <jon.hauglid@oracle.com>2016-01-26 09:18:10 +0100
commita204ce5b3f42e6bdc95eac87acff58214bac415f (patch)
treead3753b568a1030cd3e172ca0451c4be7e8a5426 /mysys
parent1624c26d429171c33ad33613e73bba23a5a3cbdd (diff)
downloadmariadb-git-a204ce5b3f42e6bdc95eac87acff58214bac415f.tar.gz
Bug#21770366 backport bug#21657078 to 5.5 and 5.6
Post-push fix: The problem was that condition variable timeouts could in some cases (slow machines and/or short timeouts) be infinite. When the number of milliseconds to wait is computed, the end time is computed before the now() time. This can result in the now() time being later than the end time, leading to negative timeout. Which after conversion to unsigned becomes ~infinite. This patch fixes the problem by explicitly checking if we get negative timeout and then using 0 if this is the case.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_wincond.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/mysys/my_wincond.c b/mysys/my_wincond.c
index 567721baf27..cfb05272a6e 100644
--- a/mysys/my_wincond.c
+++ b/mysys/my_wincond.c
@@ -127,8 +127,12 @@ static DWORD get_milliseconds(const struct timespec *abstime)
if (abstime == NULL)
return INFINITE;
- return (DWORD)(abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000 -
- my_getsystime() / 10000);
+ ulonglong future= abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000;
+ ulonglong now= my_getsystime() / 10000;
+ /* Don't allow the timeout to be negative. */
+ if (future < now)
+ return 0;
+ return (DWORD)(future - now);
#endif
}