mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +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
|
|
@ -27,6 +27,8 @@
|
|||
//
|
||||
// Some functions clamp the result in the range [_PyTime_MIN; _PyTime_MAX], so
|
||||
// the caller doesn't have to handle errors and doesn't need to hold the GIL.
|
||||
// For example, _PyTime_Add(t1, t2) computes t1+t2 and clamp the result on
|
||||
// overflow.
|
||||
//
|
||||
// Clocks:
|
||||
//
|
||||
|
|
@ -215,7 +217,12 @@ PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
|
|||
PyAPI_FUNC(void) _PyTime_AsTimespec_clamp(_PyTime_t t, struct timespec *ts);
|
||||
#endif
|
||||
|
||||
|
||||
// Compute t1 + t2. Clamp to [_PyTime_MIN; _PyTime_MAX] on overflow.
|
||||
PyAPI_FUNC(_PyTime_t) _PyTime_Add(_PyTime_t t1, _PyTime_t t2);
|
||||
|
||||
/* Compute ticks * mul / div.
|
||||
Clamp to [_PyTime_MIN; _PyTime_MAX] on overflow.
|
||||
The caller must ensure that ((div - 1) * mul) cannot overflow. */
|
||||
PyAPI_FUNC(_PyTime_t) _PyTime_MulDiv(_PyTime_t ticks,
|
||||
_PyTime_t mul,
|
||||
|
|
@ -299,6 +306,15 @@ PyAPI_FUNC(int) _PyTime_GetPerfCounterWithInfo(
|
|||
_PyTime_t *t,
|
||||
_Py_clock_info_t *info);
|
||||
|
||||
|
||||
// Create a deadline.
|
||||
// Pseudo code: _PyTime_GetMonotonicClock() + timeout.
|
||||
PyAPI_FUNC(_PyTime_t) _PyDeadline_Init(_PyTime_t timeout);
|
||||
|
||||
// Get remaining time from a deadline.
|
||||
// Pseudo code: deadline - _PyTime_GetMonotonicClock().
|
||||
PyAPI_FUNC(_PyTime_t) _PyDeadline_Get(_PyTime_t deadline);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue