Skip to content

Commit

Permalink
pythongh-110850: Use _PyDeadline_Get() in EnterNonRecursiveMutex() (p…
Browse files Browse the repository at this point in the history
…ython#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.
  • Loading branch information
vstinner authored and SonicField committed May 8, 2024
1 parent 44ef1ef commit 018b9cc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Python/thread_nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 018b9cc

Please sign in to comment.