mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
bpo-41710: Add private _PyDeadline_Get() function (GH-28674)
Add a private C API for deadlines: add _PyDeadline_Init() and _PyDeadline_Get() functions. * Add _PyTime_Add() and _PyTime_Mul() functions which compute t1+t2 and t1*t2 and clamp the result on overflow. * _PyTime_MulDiv() now uses _PyTime_Add() and _PyTime_Mul().
This commit is contained in:
parent
54957f16a6
commit
833fdf126c
11 changed files with 177 additions and 109 deletions
|
|
@ -75,20 +75,20 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, DWORD milliseconds)
|
|||
}
|
||||
}
|
||||
} else if (milliseconds != 0) {
|
||||
/* wait at least until the target */
|
||||
_PyTime_t now = _PyTime_GetPerfCounter();
|
||||
/* wait at least until the deadline */
|
||||
_PyTime_t nanoseconds = _PyTime_FromNanoseconds((_PyTime_t)milliseconds * 1000000);
|
||||
_PyTime_t target = now + nanoseconds;
|
||||
_PyTime_t deadline = _PyTime_Add(_PyTime_GetPerfCounter(), nanoseconds);
|
||||
while (mutex->locked) {
|
||||
_PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds, _PyTime_ROUND_TIMEOUT);
|
||||
_PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds,
|
||||
_PyTime_ROUND_TIMEOUT);
|
||||
if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, microseconds) < 0) {
|
||||
result = WAIT_FAILED;
|
||||
break;
|
||||
}
|
||||
now = _PyTime_GetPerfCounter();
|
||||
if (target <= now)
|
||||
nanoseconds = deadline - _PyTime_GetPerfCounter();
|
||||
if (nanoseconds <= 0) {
|
||||
break;
|
||||
nanoseconds = target - now;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!mutex->locked) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue