summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-05-04 07:39:58 (GMT)
committerGitHub <noreply@github.com>2024-05-04 07:39:58 (GMT)
commit0b7814e0b638631fa2f5c81bcbab7b94064948d7 (patch)
tree00dd17c456b2fa165ff4c29cdd948bea481f9da6 /Python
parent42dc5b4ace39a3983cd9853719527f4724693adc (diff)
downloadcpython-0b7814e0b638631fa2f5c81bcbab7b94064948d7.zip
cpython-0b7814e0b638631fa2f5c81bcbab7b94064948d7.tar.gz
cpython-0b7814e0b638631fa2f5c81bcbab7b94064948d7.tar.bz2
gh-110850: Use _PyDeadline_Get() in EnterNonRecursiveMutex() (#118556)
Use _PyDeadline_Init() and _PyDeadline_Get() in EnterNonRecursiveMutex() of thread_nt.h. _PyDeadline_Get() uses the monotonic clock which is now the same as the perf counter clock on all platforms. So this change does not cause any behavior change. It just reuses existing helper functions.
Diffstat (limited to 'Python')
-rw-r--r--Python/thread_nt.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index 9dca833..4256581 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -77,17 +77,18 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
}
} else if (milliseconds != 0) {
/* wait at least until the deadline */
- PyTime_t nanoseconds = (PyTime_t)milliseconds * (1000 * 1000);
- PyTime_t deadline = _PyTime_Add(_PyTime_PerfCounterUnchecked(), nanoseconds);
+ PyTime_t timeout = (PyTime_t)milliseconds * (1000 * 1000);
+ PyTime_t deadline = _PyDeadline_Init(timeout);
while (mutex->locked) {
- PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds,
- _PyTime_ROUND_TIMEOUT);
+ PyTime_t microseconds = _PyTime_AsMicroseconds(timeout,
+ _PyTime_ROUND_TIMEOUT);
if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, microseconds) < 0) {
result = WAIT_FAILED;
break;
}
- nanoseconds = deadline - _PyTime_PerfCounterUnchecked();
- if (nanoseconds <= 0) {
+
+ timeout = _PyDeadline_Get(deadline);
+ if (timeout <= 0) {
break;
}
}