diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-06-11 15:03:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 15:03:10 -0700 |
commit | 57b3ca7f0aef4d180038d475398f809d3fcdd8be (patch) | |
tree | 591e32f39468233c5fe8e611d2498c556e4aeaad /Python | |
parent | bpo-44381: Windows build now allows enabling control flow guard (GH-26645) (diff) | |
download | cpython-57b3ca7f0aef4d180038d475398f809d3fcdd8be.tar.gz cpython-57b3ca7f0aef4d180038d475398f809d3fcdd8be.tar.bz2 cpython-57b3ca7f0aef4d180038d475398f809d3fcdd8be.zip |
bpo-41299: Reduce lag in Windows threading timeouts by using a higher precision time source (GH-26568)
(cherry picked from commit 449e6f0ef395231e3abe467f910b02d7f075c27f)
Co-authored-by: Ryan Hileman <lunixbochs@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/thread_nt.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/thread_nt.h b/Python/thread_nt.h index 05b982d32dc..0ce5e94f89b 100644 --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -76,16 +76,22 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds) } } else if (milliseconds != 0) { /* wait at least until the target */ - ULONGLONG now, target = GetTickCount64() + milliseconds; + _PyTime_t now = _PyTime_GetPerfCounter(); + if (now <= 0) { + Py_FatalError("_PyTime_GetPerfCounter() == 0"); + } + _PyTime_t nanoseconds = _PyTime_FromNanoseconds((_PyTime_t)milliseconds * 1000000); + _PyTime_t target = now + nanoseconds; while (mutex->locked) { - if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, (long long)milliseconds*1000) < 0) { + _PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds, _PyTime_ROUND_TIMEOUT); + if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, microseconds) < 0) { result = WAIT_FAILED; break; } - now = GetTickCount64(); + now = _PyTime_GetPerfCounter(); if (target <= now) break; - milliseconds = (DWORD)(target-now); + nanoseconds = target - now; } } if (!mutex->locked) { |