summaryrefslogtreecommitdiffstats
path: root/Include/cpython
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-10-01 11:29:25 (GMT)
committerGitHub <noreply@github.com>2021-10-01 11:29:25 (GMT)
commit833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd (patch)
tree7e4ed574b7cfb30c0ebb7585061134fee1b1f8ae /Include/cpython
parent54957f16a63ecb6b15f77b01fa7c55ada892604a (diff)
downloadcpython-833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd.zip
cpython-833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd.tar.gz
cpython-833fdf126c8fe77fd17e8a8ffbc5c571b3bf64bd.tar.bz2
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().
Diffstat (limited to 'Include/cpython')
-rw-r--r--Include/cpython/pytime.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/Include/cpython/pytime.h b/Include/cpython/pytime.h
index 5440720..f32148a 100644
--- a/Include/cpython/pytime.h
+++ b/Include/cpython/pytime.h
@@ -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