Skip to content

Commit 0b7814e

Browse files
authored
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.
1 parent 42dc5b4 commit 0b7814e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Python/thread_nt.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
7777
}
7878
} else if (milliseconds != 0) {
7979
/* wait at least until the deadline */
80-
PyTime_t nanoseconds = (PyTime_t)milliseconds * (1000 * 1000);
81-
PyTime_t deadline = _PyTime_Add(_PyTime_PerfCounterUnchecked(), nanoseconds);
80+
PyTime_t timeout = (PyTime_t)milliseconds * (1000 * 1000);
81+
PyTime_t deadline = _PyDeadline_Init(timeout);
8282
while (mutex->locked) {
83-
PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds,
84-
_PyTime_ROUND_TIMEOUT);
83+
PyTime_t microseconds = _PyTime_AsMicroseconds(timeout,
84+
_PyTime_ROUND_TIMEOUT);
8585
if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, microseconds) < 0) {
8686
result = WAIT_FAILED;
8787
break;
8888
}
89-
nanoseconds = deadline - _PyTime_PerfCounterUnchecked();
90-
if (nanoseconds <= 0) {
89+
90+
timeout = _PyDeadline_Get(deadline);
91+
if (timeout <= 0) {
9192
break;
9293
}
9394
}

0 commit comments

Comments
 (0)