#include "pycore_lock.h" // PyMutex
#include "pycore_hashtable.h" // _Py_hashtable_t
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
extern int _PyImport_IsInitialized(PyInterpreterState *);
/* diagnostic info in PyImport_ImportModuleLevelObject() */
struct {
int import_level;
- _PyTime_t accumulated;
+ PyTime_t accumulated;
int header;
} find_and_load;
};
# error "this header requires Py_BUILD_CORE define"
#endif
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
// A mutex that occupies one byte. The lock can be zero initialized.
// Lock a mutex with an optional timeout and additional options. See
// _PyLockFlags for details.
extern PyLockStatus
-_PyMutex_LockTimed(PyMutex *m, _PyTime_t timeout_ns, _PyLockFlags flags);
+_PyMutex_LockTimed(PyMutex *m, PyTime_t timeout_ns, _PyLockFlags flags);
// Lock a mutex with aditional options. See _PyLockFlags for details.
static inline void
// Wait for the event to be set, or until the timeout expires. If the event is
// already set, then this returns immediately. Returns 1 if the event was set,
// and 0 if the timeout expired or thread was interrupted.
-PyAPI_FUNC(int) PyEvent_WaitTimed(PyEvent *evt, _PyTime_t timeout_ns);
+PyAPI_FUNC(int) PyEvent_WaitTimed(PyEvent *evt, PyTime_t timeout_ns);
// _PyRawMutex implements a word-sized mutex that that does not depend on the
# error "this header requires Py_BUILD_CORE define"
#endif
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
enum {
// }
PyAPI_FUNC(int)
_PyParkingLot_Park(const void *address, const void *expected,
- size_t address_size, _PyTime_t timeout_ns,
+ size_t address_size, PyTime_t timeout_ns,
void *park_arg, int detach);
// Callback for _PyParkingLot_Unpark:
// unset: -1 seconds, in nanoseconds
-#define PyThread_UNSET_TIMEOUT ((_PyTime_t)(-1 * 1000 * 1000 * 1000))
+#define PyThread_UNSET_TIMEOUT ((PyTime_t)(-1 * 1000 * 1000 * 1000))
// Exported for the _xxinterpchannels module.
PyAPI_FUNC(int) PyThread_ParseTimeoutArg(
#endif
#include "pycore_pythread.h" // _POSIX_SEMAPHORES
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
// If `detach` is true, then the thread will detach/release the GIL while
// sleeping.
PyAPI_FUNC(int)
-_PySemaphore_Wait(_PySemaphore *sema, _PyTime_t timeout_ns, int detach);
+_PySemaphore_Wait(_PySemaphore *sema, PyTime_t timeout_ns, int detach);
// Wakes up a single thread waiting on sema. Note that _PySemaphore_Wakeup()
// can be called before _PySemaphore_Wait().
struct timeval;
#endif
-typedef PyTime_t _PyTime_t;
+typedef PyTime_t PyTime_t;
#define _SIZEOF_PYTIME_T 8
typedef enum {
// Create a timestamp from a number of seconds.
// Export for '_socket' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds);
+PyAPI_FUNC(PyTime_t) _PyTime_FromSeconds(int seconds);
// Create a timestamp from a number of seconds in double.
// Export for '_socket' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round);
+PyAPI_FUNC(PyTime_t) _PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round);
// Macro to create a timestamp from a number of seconds, no integer overflow.
// Only use the macro for small values, prefer _PyTime_FromSeconds().
#define _PYTIME_FROMSECONDS(seconds) \
- ((_PyTime_t)(seconds) * (1000 * 1000 * 1000))
+ ((PyTime_t)(seconds) * (1000 * 1000 * 1000))
// Create a timestamp from a number of nanoseconds.
// Export for '_testinternalcapi' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(_PyTime_t ns);
+PyAPI_FUNC(PyTime_t) _PyTime_FromNanoseconds(PyTime_t ns);
// Create a timestamp from a number of microseconds.
// Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
-extern _PyTime_t _PyTime_FromMicrosecondsClamp(_PyTime_t us);
+extern PyTime_t _PyTime_FromMicrosecondsClamp(PyTime_t us);
// Create a timestamp from nanoseconds (Python int).
// Export for '_lsprof' shared extension.
-PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(_PyTime_t *t,
+PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(PyTime_t *t,
PyObject *obj);
// Convert a number of seconds (Python float or int) to a timestamp.
// Raise an exception and return -1 on error, return 0 on success.
// Export for '_socket' shared extension.
-PyAPI_FUNC(int) _PyTime_FromSecondsObject(_PyTime_t *t,
+PyAPI_FUNC(int) _PyTime_FromSecondsObject(PyTime_t *t,
PyObject *obj,
_PyTime_round_t round);
// Convert a number of milliseconds (Python float or int, 10^-3) to a timestamp.
// Raise an exception and return -1 on error, return 0 on success.
// Export for 'select' shared extension.
-PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(_PyTime_t *t,
+PyAPI_FUNC(int) _PyTime_FromMillisecondsObject(PyTime_t *t,
PyObject *obj,
_PyTime_round_t round);
// Convert timestamp to a number of milliseconds (10^-3 seconds).
// Export for '_ssl' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_AsMilliseconds(_PyTime_t t,
+PyAPI_FUNC(PyTime_t) _PyTime_AsMilliseconds(PyTime_t t,
_PyTime_round_t round);
// Convert timestamp to a number of microseconds (10^-6 seconds).
// Export for '_queue' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_AsMicroseconds(_PyTime_t t,
+PyAPI_FUNC(PyTime_t) _PyTime_AsMicroseconds(PyTime_t t,
_PyTime_round_t round);
#ifdef MS_WINDOWS
// Convert timestamp to a number of 100 nanoseconds (10^-7 seconds).
-extern _PyTime_t _PyTime_As100Nanoseconds(_PyTime_t t,
+extern PyTime_t _PyTime_As100Nanoseconds(PyTime_t t,
_PyTime_round_t round);
#endif
// Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int
// object.
// Export for '_testinternalcapi' shared extension.
-PyAPI_FUNC(PyObject*) _PyTime_AsNanosecondsObject(_PyTime_t t);
+PyAPI_FUNC(PyObject*) _PyTime_AsNanosecondsObject(PyTime_t t);
#ifndef MS_WINDOWS
// Create a timestamp from a timeval structure.
// Raise an exception and return -1 on overflow, return 0 on success.
-extern int _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
+extern int _PyTime_FromTimeval(PyTime_t *tp, struct timeval *tv);
#endif
// Convert a timestamp to a timeval structure (microsecond resolution).
// Raise an exception and return -1 if the conversion overflowed,
// return 0 on success.
// Export for 'select' shared extension.
-PyAPI_FUNC(int) _PyTime_AsTimeval(_PyTime_t t,
+PyAPI_FUNC(int) _PyTime_AsTimeval(PyTime_t t,
struct timeval *tv,
_PyTime_round_t round);
// Similar to _PyTime_AsTimeval() but don't raise an exception on overflow.
-// On overflow, clamp tv_sec to _PyTime_t min/max.
+// On overflow, clamp tv_sec to PyTime_t min/max.
// Export for 'select' shared extension.
-PyAPI_FUNC(void) _PyTime_AsTimeval_clamp(_PyTime_t t,
+PyAPI_FUNC(void) _PyTime_AsTimeval_clamp(PyTime_t t,
struct timeval *tv,
_PyTime_round_t round);
// return 0 on success.
// Export for '_datetime' shared extension.
PyAPI_FUNC(int) _PyTime_AsTimevalTime_t(
- _PyTime_t t,
+ PyTime_t t,
time_t *secs,
int *us,
_PyTime_round_t round);
#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_KQUEUE)
// Create a timestamp from a timespec structure.
// Raise an exception and return -1 on overflow, return 0 on success.
-extern int _PyTime_FromTimespec(_PyTime_t *tp, const struct timespec *ts);
+extern int _PyTime_FromTimespec(PyTime_t *tp, const struct timespec *ts);
// Convert a timestamp to a timespec structure (nanosecond resolution).
// tv_nsec is always positive.
// Raise an exception and return -1 on error, return 0 on success.
// Export for '_testinternalcapi' shared extension.
-PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
+PyAPI_FUNC(int) _PyTime_AsTimespec(PyTime_t t, struct timespec *ts);
// Similar to _PyTime_AsTimespec() but don't raise an exception on overflow.
-// On overflow, clamp tv_sec to _PyTime_t min/max.
+// On overflow, clamp tv_sec to PyTime_t min/max.
// Export for '_testinternalcapi' shared extension.
-PyAPI_FUNC(void) _PyTime_AsTimespec_clamp(_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.
-extern _PyTime_t _PyTime_Add(_PyTime_t t1, _PyTime_t t2);
+extern PyTime_t _PyTime_Add(PyTime_t t1, PyTime_t t2);
// Structure used by time.get_clock_info()
typedef struct {
// Use _PyTime_GetSystemClockWithInfo or the public PyTime_Time() to check
// for failure.
// Export for '_random' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_GetSystemClock(void);
+PyAPI_FUNC(PyTime_t) _PyTime_GetSystemClock(void);
// Get the current time from the system clock.
// On success, set *t and *info (if not NULL), and return 0.
// On error, raise an exception and return -1.
extern int _PyTime_GetSystemClockWithInfo(
- _PyTime_t *t,
+ PyTime_t *t,
_Py_clock_info_t *info);
// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
// Use _PyTime_GetMonotonicClockWithInfo or the public PyTime_Monotonic()
// to check for failure.
// Export for '_random' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_GetMonotonicClock(void);
+PyAPI_FUNC(PyTime_t) _PyTime_GetMonotonicClock(void);
// Get the time of a monotonic clock, i.e. a clock that cannot go backwards.
// The clock is not affected by system clock updates. The reference point of
// Return 0 on success, raise an exception and return -1 on error.
// Export for '_testsinglephase' shared extension.
PyAPI_FUNC(int) _PyTime_GetMonotonicClockWithInfo(
- _PyTime_t *t,
+ PyTime_t *t,
_Py_clock_info_t *info);
// Use _PyTime_GetPerfCounterWithInfo() or the public PyTime_PerfCounter
// to check for failure.
// Export for '_lsprof' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyTime_GetPerfCounter(void);
+PyAPI_FUNC(PyTime_t) _PyTime_GetPerfCounter(void);
// Get the performance counter: clock with the highest available resolution to
//
// Return 0 on success, raise an exception and return -1 on error.
extern int _PyTime_GetPerfCounterWithInfo(
- _PyTime_t *t,
+ PyTime_t *t,
_Py_clock_info_t *info);
// Alias for backward compatibility
// Create a deadline.
// Pseudo code: _PyTime_GetMonotonicClock() + timeout.
// Export for '_ssl' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyDeadline_Init(_PyTime_t timeout);
+PyAPI_FUNC(PyTime_t) _PyDeadline_Init(PyTime_t timeout);
// Get remaining time from a deadline.
// Pseudo code: deadline - _PyTime_GetMonotonicClock().
// Export for '_ssl' shared extension.
-PyAPI_FUNC(_PyTime_t) _PyDeadline_Get(_PyTime_t deadline);
+PyAPI_FUNC(PyTime_t) _PyDeadline_Get(PyTime_t deadline);
// --- _PyTimeFraction -------------------------------------------------------
typedef struct {
- _PyTime_t numer;
- _PyTime_t denom;
+ PyTime_t numer;
+ PyTime_t denom;
} _PyTimeFraction;
// Set a fraction.
// Return -1 if the fraction is invalid.
extern int _PyTimeFraction_Set(
_PyTimeFraction *frac,
- _PyTime_t numer,
- _PyTime_t denom);
+ PyTime_t numer,
+ PyTime_t denom);
// Compute ticks * frac.numer / frac.denom.
// Clamp to [_PyTime_MIN; _PyTime_MAX] on overflow.
-extern _PyTime_t _PyTimeFraction_Mul(
- _PyTime_t ticks,
+extern PyTime_t _PyTimeFraction_Mul(
+ PyTime_t ticks,
const _PyTimeFraction *frac);
// Compute a clock resolution: frac.numer / frac.denom / 1e9.
static PyObject *
datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
{
- _PyTime_t ts = _PyTime_GetSystemClock();
+ PyTime_t ts = _PyTime_GetSystemClock();
time_t secs;
int us;
/* represents a function called from another function */
typedef struct _ProfilerSubEntry {
rotating_node_t header;
- _PyTime_t tt;
- _PyTime_t it;
+ PyTime_t tt;
+ PyTime_t it;
long callcount;
long recursivecallcount;
long recursionLevel;
typedef struct _ProfilerEntry {
rotating_node_t header;
PyObject *userObj; /* PyCodeObject, or a descriptive str for builtins */
- _PyTime_t tt; /* total time in this entry */
- _PyTime_t it; /* inline time in this entry (not in subcalls) */
+ PyTime_t tt; /* total time in this entry */
+ PyTime_t it; /* inline time in this entry (not in subcalls) */
long callcount; /* how many times this was called */
long recursivecallcount; /* how many times called recursively */
long recursionLevel;
} ProfilerEntry;
typedef struct _ProfilerContext {
- _PyTime_t t0;
- _PyTime_t subt;
+ PyTime_t t0;
+ PyTime_t subt;
struct _ProfilerContext *previous;
ProfilerEntry *ctxEntry;
} ProfilerContext;
/*** External Timers ***/
-static _PyTime_t CallExternalTimer(ProfilerObject *pObj)
+static PyTime_t CallExternalTimer(ProfilerObject *pObj)
{
PyObject *o = _PyObject_CallNoArgs(pObj->externalTimer);
if (o == NULL) {
return 0;
}
- _PyTime_t result;
+ PyTime_t result;
int err;
if (pObj->externalTimerUnit > 0.0) {
/* interpret the result as an integer that will be scaled
}
else {
/* interpret the result as a double measured in seconds.
- As the profiler works with _PyTime_t internally
+ As the profiler works with PyTime_t internally
we convert it to a large integer */
err = _PyTime_FromSecondsObject(&result, o, _PyTime_ROUND_FLOOR);
}
return result;
}
-static inline _PyTime_t
+static inline PyTime_t
call_timer(ProfilerObject *pObj)
{
if (pObj->externalTimer != NULL) {
static void
Stop(ProfilerObject *pObj, ProfilerContext *self, ProfilerEntry *entry)
{
- _PyTime_t tt = call_timer(pObj) - self->t0;
- _PyTime_t it = tt - self->subt;
+ PyTime_t tt = call_timer(pObj) - self->t0;
+ PyTime_t it = tt - self->subt;
if (self->previous)
self->previous->subt += tt;
pObj->currentProfilerContext = self->previous;
return NULL;
}
if (!self->externalTimer || self->externalTimerUnit == 0.0) {
- _PyTime_t onesec = _PyTime_FromSeconds(1);
+ PyTime_t onesec = _PyTime_FromSeconds(1);
collect.factor = (double)1 / onesec;
}
else {
#include "pycore_ceval.h" // Py_MakePendingCalls()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_parking_lot.h"
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
#include <stdbool.h>
#include <stddef.h> // offsetof()
int block, PyObject *timeout_obj)
/*[clinic end generated code: output=5c2cca914cd1e55b input=f7836c65e5839c51]*/
{
- _PyTime_t endtime = 0;
+ PyTime_t endtime = 0;
// XXX Use PyThread_ParseTimeoutArg().
if (block != 0 && !Py_IsNone(timeout_obj)) {
/* With timeout */
- _PyTime_t timeout;
+ PyTime_t timeout;
if (_PyTime_FromSecondsObject(&timeout,
timeout_obj, _PyTime_ROUND_CEILING) < 0) {
return NULL;
#include "clinic/_ssl.c.h"
-static int PySSL_select(PySocketSockObject *s, int writing, _PyTime_t timeout);
+static int PySSL_select(PySocketSockObject *s, int writing, PyTime_t timeout);
static int PySSL_set_owner(PySSLSocket *, PyObject *, void *);
static int PySSL_set_session(PySSLSocket *, PyObject *, void *);
_PySSLError err;
int sockstate, nonblocking;
PySocketSockObject *sock = GET_SOCKET(self);
- _PyTime_t timeout, deadline = 0;
+ PyTime_t timeout, deadline = 0;
int has_timeout;
if (sock) {
*/
static int
-PySSL_select(PySocketSockObject *s, int writing, _PyTime_t timeout)
+PySSL_select(PySocketSockObject *s, int writing, PyTime_t timeout)
{
int rc;
#ifdef HAVE_POLL
struct pollfd pollfd;
- _PyTime_t ms;
+ PyTime_t ms;
#else
int nfds;
fd_set fds;
_PySSLError err;
int nonblocking;
PySocketSockObject *sock = GET_SOCKET(self);
- _PyTime_t timeout, deadline = 0;
+ PyTime_t timeout, deadline = 0;
int has_timeout;
if (sock != NULL) {
_PySSLError err;
int nonblocking;
PySocketSockObject *sock = GET_SOCKET(self);
- _PyTime_t timeout, deadline = 0;
+ PyTime_t timeout, deadline = 0;
int has_timeout;
if (!group_right_1 && len < 0) {
int sockstate, nonblocking, ret;
int zeros = 0;
PySocketSockObject *sock = GET_SOCKET(self);
- _PyTime_t timeout, deadline = 0;
+ PyTime_t timeout, deadline = 0;
int has_timeout;
if (sock != NULL) {
if (!PyArg_ParseTuple(args, "i", &seconds)) {
return NULL;
}
- _PyTime_t ts = _PyTime_FromSeconds(seconds);
+ PyTime_t ts = _PyTime_FromSeconds(seconds);
return _PyTime_AsNanosecondsObject(ts);
}
if (check_time_rounding(round) < 0) {
return NULL;
}
- _PyTime_t ts;
+ PyTime_t ts;
if (_PyTime_FromSecondsObject(&ts, obj, round) == -1) {
return NULL;
}
if (check_time_rounding(round) < 0) {
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromNanosecondsObject(&t, obj) < 0) {
return NULL;
}
if (check_time_rounding(round) < 0) {
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromNanosecondsObject(&t, obj) < 0) {
return NULL;
}
if (!PyArg_ParseTuple(args, "O", &obj)) {
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromNanosecondsObject(&t, obj) < 0) {
return NULL;
}
if (!PyArg_ParseTuple(args, "O", &obj)) {
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromNanosecondsObject(&t, obj) < 0) {
return NULL;
}
if (!PyArg_ParseTuple(args, "Oi", &obj, &round)) {
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromNanosecondsObject(&t, obj) < 0) {
return NULL;
}
if (check_time_rounding(round) < 0) {
return NULL;
}
- _PyTime_t ms = _PyTime_AsMilliseconds(t, round);
- _PyTime_t ns = _PyTime_FromNanoseconds(ms);
+ PyTime_t ms = _PyTime_AsMilliseconds(t, round);
+ PyTime_t ns = _PyTime_FromNanoseconds(ms);
return _PyTime_AsNanosecondsObject(ns);
}
if (!PyArg_ParseTuple(args, "Oi", &obj, &round)) {
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromNanosecondsObject(&t, obj) < 0) {
return NULL;
}
if (check_time_rounding(round) < 0) {
return NULL;
}
- _PyTime_t us = _PyTime_AsMicroseconds(t, round);
- _PyTime_t ns = _PyTime_FromNanoseconds(us);
+ PyTime_t us = _PyTime_AsMicroseconds(t, round);
+ PyTime_t ns = _PyTime_FromNanoseconds(us);
return _PyTime_AsNanosecondsObject(ns);
}
goto exit;
}
- _PyTime_t start = _PyTime_GetMonotonicClock();
+ PyTime_t start = _PyTime_GetMonotonicClock();
for (Py_ssize_t i = 0; i < num_threads; i++) {
thread_data[i].bench_data = &bench_data;
}
Py_ssize_t total_iters = bench_data.total_iters;
- _PyTime_t end = _PyTime_GetMonotonicClock();
+ PyTime_t end = _PyTime_GetMonotonicClock();
// Return the total number of acquisitions and the number of acquisitions
// for each thread.
//#include <time.h>
#include "Python.h"
#include "pycore_namespace.h" // _PyNamespace_New()
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
typedef struct {
- _PyTime_t initialized;
+ PyTime_t initialized;
PyObject *error;
PyObject *int_const;
PyObject *str_const;
}
static int
-_set_initialized(_PyTime_t *initialized)
+_set_initialized(PyTime_t *initialized)
{
/* We go strictly monotonic to ensure each time is unique. */
- _PyTime_t prev;
+ PyTime_t prev;
if (_PyTime_GetMonotonicClockWithInfo(&prev, NULL) != 0) {
return -1;
}
/* We do a busy sleep since the interval should be super short. */
- _PyTime_t t;
+ PyTime_t t;
do {
if (_PyTime_GetMonotonicClockWithInfo(&t, NULL) != 0) {
return -1;
}
static inline PyLockStatus
-acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
+acquire_timed(PyThread_type_lock lock, PyTime_t timeout)
{
return PyThread_acquire_lock_timed_with_retries(lock, timeout);
}
static int
lock_acquire_parse_args(PyObject *args, PyObject *kwds,
- _PyTime_t *timeout)
+ PyTime_t *timeout)
{
char *kwlist[] = {"blocking", "timeout", NULL};
int blocking = 1;
// XXX Use PyThread_ParseTimeoutArg().
- const _PyTime_t unset_timeout = _PyTime_FromSeconds(-1);
+ const PyTime_t unset_timeout = _PyTime_FromSeconds(-1);
*timeout = unset_timeout;
if (timeout_obj
if (!blocking)
*timeout = 0;
else if (*timeout != unset_timeout) {
- _PyTime_t microseconds;
+ PyTime_t microseconds;
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_TIMEOUT);
if (microseconds > PY_TIMEOUT_MAX) {
static PyObject *
lock_PyThread_acquire_lock(lockobject *self, PyObject *args, PyObject *kwds)
{
- _PyTime_t timeout;
+ PyTime_t timeout;
if (lock_acquire_parse_args(args, kwds, &timeout) < 0)
return NULL;
static PyObject *
rlock_acquire(rlockobject *self, PyObject *args, PyObject *kwds)
{
- _PyTime_t timeout;
+ PyTime_t timeout;
PyThread_ident_t tid;
PyLockStatus r = PY_LOCK_ACQUIRED;
#define SEC_TO_US (1000 * 1000)
static char*
-format_timeout(_PyTime_t us)
+format_timeout(PyTime_t us)
{
unsigned long sec, min, hour;
char buffer[100];
{
static char *kwlist[] = {"timeout", "repeat", "file", "exit", NULL};
PyObject *timeout_obj;
- _PyTime_t timeout, timeout_us;
+ PyTime_t timeout, timeout_us;
int repeat = 0;
PyObject *file = NULL;
int fd;
static PyObject *
build_itimerspec_ns(const struct itimerspec* curr_value)
{
- _PyTime_t value, interval;
+ PyTime_t value, interval;
if (_PyTime_FromTimespec(&value, &curr_value->it_value) < 0) {
return NULL;
}
#include "Python.h"
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_import.h" // _PyImport_GetModuleAttrString()
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
#include <stdbool.h>
#include <stddef.h> // offsetof()
struct timeval tv, *tvp;
int imax, omax, emax, max;
int n;
- _PyTime_t timeout, deadline = 0;
+ PyTime_t timeout, deadline = 0;
if (timeout_obj == Py_None)
tvp = (struct timeval *)NULL;
PyObject *result_list = NULL;
int poll_result, i, j;
PyObject *value = NULL, *num = NULL;
- _PyTime_t timeout = -1, ms = -1, deadline = 0;
+ PyTime_t timeout = -1, ms = -1, deadline = 0;
int async_err = 0;
if (timeout_obj != Py_None) {
PyObject *result_list = NULL;
int poll_result, i;
PyObject *value, *num1, *num2;
- _PyTime_t timeout, ms, deadline = 0;
+ PyTime_t timeout, ms, deadline = 0;
if (self->fd_devpoll < 0)
return devpoll_err_closed();
int nfds, i;
PyObject *elist = NULL, *etuple = NULL;
struct epoll_event *evs = NULL;
- _PyTime_t timeout = -1, ms = -1, deadline = 0;
+ PyTime_t timeout = -1, ms = -1, deadline = 0;
if (self->epfd < 0)
return pyepoll_err_closed();
struct kevent *chl = NULL;
struct timespec timeoutspec;
struct timespec *ptimeoutspec;
- _PyTime_t timeout, deadline = 0;
+ PyTime_t timeout, deadline = 0;
_selectstate *state = _selectstate_by_type(Py_TYPE(self));
if (self->kqfd < 0)
return 0;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromSecondsObject(&t, obj, _PyTime_ROUND_CEILING) < 0) {
return -1;
}
PyObject *timeout_obj)
/*[clinic end generated code: output=59c8971e8ae18a64 input=87fd39237cf0b7ba]*/
{
- _PyTime_t timeout;
+ PyTime_t timeout;
if (_PyTime_FromSecondsObject(&timeout,
timeout_obj, _PyTime_ROUND_CEILING) < 0)
return NULL;
return NULL;
}
- _PyTime_t deadline = _PyDeadline_Init(timeout);
+ PyTime_t deadline = _PyDeadline_Init(timeout);
siginfo_t si;
do {
PyObject *socket_gaierror;
/* Default timeout for new sockets */
- _PyTime_t defaulttimeout;
+ PyTime_t defaulttimeout;
#if defined(HAVE_ACCEPT) || defined(HAVE_ACCEPT4)
#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
}
static int
-internal_select(PySocketSockObject *s, int writing, _PyTime_t interval,
+internal_select(PySocketSockObject *s, int writing, PyTime_t interval,
int connect)
{
int n;
#ifdef HAVE_POLL
struct pollfd pollfd;
- _PyTime_t ms;
+ PyTime_t ms;
#else
fd_set fds, efds;
struct timeval tv, *tvp;
void *data,
int connect,
int *err,
- _PyTime_t timeout)
+ PyTime_t timeout)
{
int has_timeout = (timeout > 0);
- _PyTime_t deadline = 0;
+ PyTime_t deadline = 0;
int deadline_initialized = 0;
int res;
runs asynchronously. */
if (has_timeout || connect) {
if (has_timeout) {
- _PyTime_t interval;
+ PyTime_t interval;
if (deadline_initialized) {
/* recompute the timeout */
is in non-blocking mode.");
static int
-socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
+socket_parse_timeout(PyTime_t *timeout, PyObject *timeout_obj)
{
#ifdef MS_WINDOWS
struct timeval tv;
#endif
#ifndef HAVE_POLL
- _PyTime_t ms;
+ PyTime_t ms;
#endif
int overflow = 0;
static PyObject *
sock_settimeout(PySocketSockObject *s, PyObject *arg)
{
- _PyTime_t timeout;
+ PyTime_t timeout;
if (socket_parse_timeout(&timeout, arg) < 0)
return NULL;
Py_buffer pbuf;
struct sock_send ctx;
int has_timeout = (s->sock_timeout > 0);
- _PyTime_t timeout = s->sock_timeout;
- _PyTime_t deadline = 0;
+ PyTime_t timeout = s->sock_timeout;
+ PyTime_t deadline = 0;
int deadline_initialized = 0;
PyObject *res = NULL;
static PyObject *
socket_setdefaulttimeout(PyObject *self, PyObject *arg)
{
- _PyTime_t timeout;
+ PyTime_t timeout;
if (socket_parse_timeout(&timeout, arg) < 0)
return NULL;
/* Socket module header file */
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
/* Includes needed for the sockaddr_* symbols below */
#ifndef MS_WINDOWS
PyObject *(*errorhandler)(void); /* Error handler; checks
errno, returns NULL and
sets a Python exception */
- _PyTime_t sock_timeout; /* Operation timeout in seconds;
+ PyTime_t sock_timeout; /* Operation timeout in seconds;
0.0 means non-blocking */
struct _socket_state *state;
} PySocketSockObject;
/* Forward declarations */
-static int pysleep(_PyTime_t timeout);
+static int pysleep(PyTime_t timeout);
typedef struct {
static PyObject*
-_PyFloat_FromPyTime(_PyTime_t t)
+_PyFloat_FromPyTime(PyTime_t t)
{
double d = _PyTime_AsSecondsDouble(t);
return PyFloat_FromDouble(d);
static int
-get_system_time(_PyTime_t *t)
+get_system_time(PyTime_t *t)
{
// Avoid _PyTime_GetSystemClock() which silently ignores errors.
return _PyTime_GetSystemClockWithInfo(t, NULL);
static PyObject *
time_time(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (get_system_time(&t) < 0) {
return NULL;
}
static PyObject *
time_time_ns(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (get_system_time(&t) < 0) {
return NULL;
}
#endif
static int
-py_clock(time_module_state *state, _PyTime_t *tp, _Py_clock_info_t *info)
+py_clock(time_module_state *state, PyTime_t *tp, _Py_clock_info_t *info)
{
_PyTimeFraction *base = &state->clock_base;
"or its value cannot be represented");
return -1;
}
- _PyTime_t ns = _PyTimeFraction_Mul(ticks, base);
+ PyTime_t ns = _PyTimeFraction_Mul(ticks, base);
*tp = _PyTime_FromNanoseconds(ns);
return 0;
}
return NULL;
}
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_FromTimespec(&t, &ts) < 0) {
return NULL;
}
{
int clk_id;
PyObject *obj;
- _PyTime_t t;
+ PyTime_t t;
struct timespec tp;
int ret;
{
int clk_id;
PyObject *obj;
- _PyTime_t t;
+ PyTime_t t;
struct timespec ts;
int ret;
return NULL;
}
- _PyTime_t timeout;
+ PyTime_t timeout;
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_TIMEOUT))
return NULL;
if (timeout < 0) {
static int
-get_monotonic(_PyTime_t *t)
+get_monotonic(PyTime_t *t)
{
// Avoid _PyTime_GetMonotonicClock() which silently ignores errors.
return _PyTime_GetMonotonicClockWithInfo(t, NULL);
static PyObject *
time_monotonic(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (get_monotonic(&t) < 0) {
return NULL;
}
static PyObject *
time_monotonic_ns(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (get_monotonic(&t) < 0) {
return NULL;
}
static int
-get_perf_counter(_PyTime_t *t)
+get_perf_counter(PyTime_t *t)
{
// Avoid _PyTime_GetPerfCounter() which silently ignores errors.
return _PyTime_GetPerfCounterWithInfo(t, NULL);
static PyObject *
time_perf_counter(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (get_perf_counter(&t) < 0) {
return NULL;
}
static PyObject *
time_perf_counter_ns(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (get_perf_counter(&t) < 0) {
return NULL;
}
#ifdef HAVE_TIMES
static int
-process_time_times(time_module_state *state, _PyTime_t *tp,
+process_time_times(time_module_state *state, PyTime_t *tp,
_Py_clock_info_t *info)
{
_PyTimeFraction *base = &state->times_base;
info->adjustable = 0;
}
- _PyTime_t ns;
+ PyTime_t ns;
ns = _PyTimeFraction_Mul(process.tms_utime, base);
ns += _PyTimeFraction_Mul(process.tms_stime, base);
*tp = _PyTime_FromNanoseconds(ns);
static int
-py_process_time(time_module_state *state, _PyTime_t *tp,
+py_process_time(time_module_state *state, PyTime_t *tp,
_Py_clock_info_t *info)
{
#if defined(MS_WINDOWS)
HANDLE process;
FILETIME creation_time, exit_time, kernel_time, user_time;
ULARGE_INTEGER large;
- _PyTime_t ktime, utime, t;
+ PyTime_t ktime, utime, t;
BOOL ok;
process = GetCurrentProcess();
struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru) == 0) {
- _PyTime_t utime, stime;
+ PyTime_t utime, stime;
if (info) {
info->implementation = "getrusage(RUSAGE_SELF)";
return -1;
}
- _PyTime_t total = utime + stime;
+ PyTime_t total = utime + stime;
*tp = total;
return 0;
}
time_process_time(PyObject *module, PyObject *unused)
{
time_module_state *state = get_time_state(module);
- _PyTime_t t;
+ PyTime_t t;
if (py_process_time(state, &t, NULL) < 0) {
return NULL;
}
time_process_time_ns(PyObject *module, PyObject *unused)
{
time_module_state *state = get_time_state(module);
- _PyTime_t t;
+ PyTime_t t;
if (py_process_time(state, &t, NULL) < 0) {
return NULL;
}
#if defined(MS_WINDOWS)
#define HAVE_THREAD_TIME
static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+_PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
{
HANDLE thread;
FILETIME creation_time, exit_time, kernel_time, user_time;
ULARGE_INTEGER large;
- _PyTime_t ktime, utime, t;
+ PyTime_t ktime, utime, t;
BOOL ok;
thread = GetCurrentThread();
#elif defined(_AIX)
#define HAVE_THREAD_TIME
static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+_PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
{
/* bpo-40192: On AIX, thread_cputime() is preferred: it has nanosecond
resolution, whereas clock_gettime(CLOCK_THREAD_CPUTIME_ID)
#elif defined(__sun) && defined(__SVR4)
#define HAVE_THREAD_TIME
static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+_PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
{
/* bpo-35455: On Solaris, CLOCK_THREAD_CPUTIME_ID clock is not always
available; use gethrvtime() to substitute this functionality. */
#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)
static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+_PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
__attribute__((availability(macos, introduced=10.12)))
__attribute__((availability(ios, introduced=10.0)))
__attribute__((availability(tvos, introduced=10.0)))
#endif
static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+_PyTime_GetThreadTimeWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
{
struct timespec ts;
const clockid_t clk_id = CLOCK_THREAD_CPUTIME_ID;
static PyObject *
time_thread_time(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_GetThreadTimeWithInfo(&t, NULL) < 0) {
return NULL;
}
static PyObject *
time_thread_time_ns(PyObject *self, PyObject *unused)
{
- _PyTime_t t;
+ PyTime_t t;
if (_PyTime_GetThreadTimeWithInfo(&t, NULL) < 0) {
return NULL;
}
char *name;
_Py_clock_info_t info;
PyObject *obj = NULL, *dict, *ns;
- _PyTime_t t;
+ PyTime_t t;
if (!PyArg_ParseTuple(args, "s:get_clock_info", &name)) {
return NULL;
// On error, raise an exception and return -1.
// On success, return 0.
static int
-pysleep(_PyTime_t timeout)
+pysleep(PyTime_t timeout)
{
assert(timeout >= 0);
#else
struct timeval timeout_tv;
#endif
- _PyTime_t deadline, monotonic;
+ PyTime_t deadline, monotonic;
int err = 0;
if (get_monotonic(&monotonic) < 0) {
return 0;
#else // MS_WINDOWS
- _PyTime_t timeout_100ns = _PyTime_As100Nanoseconds(timeout,
+ PyTime_t timeout_100ns = _PyTime_As100Nanoseconds(timeout,
_PyTime_ROUND_CEILING);
// Maintain Windows Sleep() semantics for time.sleep(0)
PyGC_Head unreachable; /* non-problematic unreachable trash */
PyGC_Head finalizers; /* objects with, & reachable from, __del__ */
PyGC_Head *gc;
- _PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
+ PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
GCState *gcstate = &tstate->interp->gc;
// gc_collect_main() must not be called before _PyGC_Init
int i;
Py_ssize_t m = 0; /* # objects collected */
Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */
- _PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
+ PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
GCState *gcstate = &tstate->interp->gc;
// gc_collect_main() must not be called before _PyGC_Init
#define import_level FIND_AND_LOAD(interp).import_level
#define accumulated FIND_AND_LOAD(interp).accumulated
- _PyTime_t t1 = 0, accumulated_copy = accumulated;
+ PyTime_t t1 = 0, accumulated_copy = accumulated;
PyObject *sys_path = PySys_GetObject("path");
PyObject *sys_meta_path = PySys_GetObject("meta_path");
mod != NULL);
if (import_time) {
- _PyTime_t cum = _PyTime_GetPerfCounter() - t1;
+ PyTime_t cum = _PyTime_GetPerfCounter() - t1;
import_level--;
fprintf(stderr, "import time: %9ld | %10ld | %*s%s\n",
// If a thread waits on a lock for longer than TIME_TO_BE_FAIR_NS (1 ms), then
// the unlocking thread directly hands off ownership of the lock. This avoids
// starvation.
-static const _PyTime_t TIME_TO_BE_FAIR_NS = 1000*1000;
+static const PyTime_t TIME_TO_BE_FAIR_NS = 1000*1000;
// Spin for a bit before parking the thread. This is only enabled for
// `--disable-gil` builds because it is unlikely to be helpful if the GIL is
struct mutex_entry {
// The time after which the unlocking thread should hand off lock ownership
// directly to the waiting thread. Written by the waiting thread.
- _PyTime_t time_to_be_fair;
+ PyTime_t time_to_be_fair;
// Set to 1 if the lock was handed off. Written by the unlocking thread.
int handed_off;
}
PyLockStatus
-_PyMutex_LockTimed(PyMutex *m, _PyTime_t timeout, _PyLockFlags flags)
+_PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
{
uint8_t v = _Py_atomic_load_uint8_relaxed(&m->v);
if ((v & _Py_LOCKED) == 0) {
return PY_LOCK_FAILURE;
}
- _PyTime_t now = _PyTime_GetMonotonicClock();
- _PyTime_t endtime = 0;
+ PyTime_t now = _PyTime_GetMonotonicClock();
+ PyTime_t endtime = 0;
if (timeout > 0) {
endtime = _PyTime_Add(now, timeout);
}
{
uint8_t v = 0;
if (entry) {
- _PyTime_t now = _PyTime_GetMonotonicClock();
+ PyTime_t now = _PyTime_GetMonotonicClock();
int should_be_fair = now > entry->time_to_be_fair;
entry->handed_off = should_be_fair;
}
int
-PyEvent_WaitTimed(PyEvent *evt, _PyTime_t timeout_ns)
+PyEvent_WaitTimed(PyEvent *evt, PyTime_t timeout_ns)
{
for (;;) {
uint8_t v = _Py_atomic_load_uint8(&evt->v);
}
static int
-_PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout)
+_PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
{
int res;
#if defined(MS_WINDOWS)
struct timespec ts;
#if defined(CLOCK_MONOTONIC) && defined(HAVE_SEM_CLOCKWAIT)
- _PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout);
+ PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout);
_PyTime_AsTimespec_clamp(deadline, &ts);
err = sem_clockwait(&sema->platform_sem, CLOCK_MONOTONIC, &ts);
#else
- _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
+ PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
_PyTime_AsTimespec_clamp(deadline, &ts);
_PyTime_AsTimespec_clamp(timeout, &ts);
err = pthread_cond_timedwait_relative_np(&sema->cond, &sema->mutex, &ts);
#else
- _PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
+ PyTime_t deadline = _PyTime_Add(_PyTime_GetSystemClock(), timeout);
_PyTime_AsTimespec_clamp(deadline, &ts);
err = pthread_cond_timedwait(&sema->cond, &sema->mutex, &ts);
}
int
-_PySemaphore_Wait(_PySemaphore *sema, _PyTime_t timeout, int detach)
+_PySemaphore_Wait(_PySemaphore *sema, PyTime_t timeout, int detach)
{
PyThreadState *tstate = NULL;
if (detach) {
int
_PyParkingLot_Park(const void *addr, const void *expected, size_t size,
- _PyTime_t timeout_ns, void *park_arg, int detach)
+ PyTime_t timeout_ns, void *park_arg, int detach)
{
struct wait_entry wait = {
.park_arg = park_arg,
break;
}
- _PyTime_t wait_ns = 1000*1000; // 1ms (arbitrary, may need tuning)
+ PyTime_t wait_ns = 1000*1000; // 1ms (arbitrary, may need tuning)
if (PyEvent_WaitTimed(&stw->stop_event, wait_ns)) {
assert(stw->thread_countdown == 0);
break;
#include "Python.h"
-#include "pycore_time.h" // _PyTime_t
+#include "pycore_time.h" // PyTime_t
#include <time.h> // gmtime_r()
#ifdef HAVE_SYS_TIME_H
#endif
#if PyTime_MIN + PyTime_MAX != -1
-# error "_PyTime_t is not a two's complement integer type"
+# error "PyTime_t is not a two's complement integer type"
#endif
-static _PyTime_t
-_PyTime_GCD(_PyTime_t x, _PyTime_t y)
+static PyTime_t
+_PyTime_GCD(PyTime_t x, PyTime_t y)
{
// Euclidean algorithm
assert(x >= 1);
assert(y >= 1);
while (y != 0) {
- _PyTime_t tmp = y;
+ PyTime_t tmp = y;
y = x % y;
x = tmp;
}
int
-_PyTimeFraction_Set(_PyTimeFraction *frac, _PyTime_t numer, _PyTime_t denom)
+_PyTimeFraction_Set(_PyTimeFraction *frac, PyTime_t numer, PyTime_t denom)
{
if (numer < 1 || denom < 1) {
return -1;
}
- _PyTime_t gcd = _PyTime_GCD(numer, denom);
+ PyTime_t gcd = _PyTime_GCD(numer, denom);
frac->numer = numer / gcd;
frac->denom = denom / gcd;
return 0;
pytime_overflow(void)
{
PyErr_SetString(PyExc_OverflowError,
- "timestamp too large to convert to C _PyTime_t");
+ "timestamp too large to convert to C PyTime_t");
}
-static inline _PyTime_t
-pytime_from_nanoseconds(_PyTime_t t)
+static inline PyTime_t
+pytime_from_nanoseconds(PyTime_t t)
{
- // _PyTime_t is a number of nanoseconds
+ // PyTime_t is a number of nanoseconds
return t;
}
-static inline _PyTime_t
-pytime_as_nanoseconds(_PyTime_t t)
+static inline PyTime_t
+pytime_as_nanoseconds(PyTime_t t)
{
- // _PyTime_t is a number of nanoseconds: see pytime_from_nanoseconds()
+ // PyTime_t is a number of nanoseconds: see pytime_from_nanoseconds()
return t;
}
// Compute t1 + t2. Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
static inline int
-pytime_add(_PyTime_t *t1, _PyTime_t t2)
+pytime_add(PyTime_t *t1, PyTime_t t2)
{
if (t2 > 0 && *t1 > PyTime_MAX - t2) {
*t1 = PyTime_MAX;
}
-_PyTime_t
-_PyTime_Add(_PyTime_t t1, _PyTime_t t2)
+PyTime_t
+_PyTime_Add(PyTime_t t1, PyTime_t t2)
{
(void)pytime_add(&t1, t2);
return t1;
static inline int
-pytime_mul_check_overflow(_PyTime_t a, _PyTime_t b)
+pytime_mul_check_overflow(PyTime_t a, PyTime_t b)
{
if (b != 0) {
assert(b > 0);
// Compute t * k. Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
static inline int
-pytime_mul(_PyTime_t *t, _PyTime_t k)
+pytime_mul(PyTime_t *t, PyTime_t k)
{
assert(k >= 0);
if (pytime_mul_check_overflow(*t, k)) {
// Compute t * k. Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
-static inline _PyTime_t
-_PyTime_Mul(_PyTime_t t, _PyTime_t k)
+static inline PyTime_t
+_PyTime_Mul(PyTime_t t, PyTime_t k)
{
(void)pytime_mul(&t, k);
return t;
}
-_PyTime_t
-_PyTimeFraction_Mul(_PyTime_t ticks, const _PyTimeFraction *frac)
+PyTime_t
+_PyTimeFraction_Mul(PyTime_t ticks, const _PyTimeFraction *frac)
{
- const _PyTime_t mul = frac->numer;
- const _PyTime_t div = frac->denom;
+ const PyTime_t mul = frac->numer;
+ const PyTime_t div = frac->denom;
if (div == 1) {
// Fast-path taken by mach_absolute_time() with 1/1 time base.
(ticks * mul) / div == (ticks / div) * mul + (ticks % div) * mul / div
*/
- _PyTime_t intpart, remaining;
+ PyTime_t intpart, remaining;
intpart = ticks / div;
ticks %= div;
remaining = _PyTime_Mul(ticks, mul) / div;
}
-// Convert _PyTime_t to time_t.
+// Convert PyTime_t to time_t.
// Return 0 on success. Return -1 and clamp the value on overflow.
static int
-_PyTime_AsTime_t(_PyTime_t t, time_t *t2)
+_PyTime_AsTime_t(PyTime_t t, time_t *t2)
{
#if SIZEOF_TIME_T < _SIZEOF_PYTIME_T
- if ((_PyTime_t)PY_TIME_T_MAX < t) {
+ if ((PyTime_t)PY_TIME_T_MAX < t) {
*t2 = PY_TIME_T_MAX;
return -1;
}
- if (t < (_PyTime_t)PY_TIME_T_MIN) {
+ if (t < (PyTime_t)PY_TIME_T_MIN) {
*t2 = PY_TIME_T_MIN;
return -1;
}
#ifdef MS_WINDOWS
-// Convert _PyTime_t to long.
+// Convert PyTime_t to long.
// Return 0 on success. Return -1 and clamp the value on overflow.
static int
-_PyTime_AsLong(_PyTime_t t, long *t2)
+_PyTime_AsLong(PyTime_t t, long *t2)
{
#if SIZEOF_LONG < _SIZEOF_PYTIME_T
- if ((_PyTime_t)LONG_MAX < t) {
+ if ((PyTime_t)LONG_MAX < t) {
*t2 = LONG_MAX;
return -1;
}
- if (t < (_PyTime_t)LONG_MIN) {
+ if (t < (PyTime_t)LONG_MIN) {
*t2 = LONG_MIN;
return -1;
}
}
-_PyTime_t
+PyTime_t
_PyTime_FromSeconds(int seconds)
{
/* ensure that integer overflow cannot happen, int type should have 32
- bits, whereas _PyTime_t type has at least 64 bits (SEC_TO_NS takes 30
+ bits, whereas PyTime_t type has at least 64 bits (SEC_TO_NS takes 30
bits). */
- static_assert(INT_MAX <= PyTime_MAX / SEC_TO_NS, "_PyTime_t overflow");
- static_assert(INT_MIN >= PyTime_MIN / SEC_TO_NS, "_PyTime_t underflow");
+ static_assert(INT_MAX <= PyTime_MAX / SEC_TO_NS, "PyTime_t overflow");
+ static_assert(INT_MIN >= PyTime_MIN / SEC_TO_NS, "PyTime_t underflow");
- _PyTime_t t = (_PyTime_t)seconds;
+ PyTime_t t = (PyTime_t)seconds;
assert((t >= 0 && t <= PyTime_MAX / SEC_TO_NS)
|| (t < 0 && t >= PyTime_MIN / SEC_TO_NS));
t *= SEC_TO_NS;
}
-_PyTime_t
-_PyTime_FromNanoseconds(_PyTime_t ns)
+PyTime_t
+_PyTime_FromNanoseconds(PyTime_t ns)
{
return pytime_from_nanoseconds(ns);
}
-_PyTime_t
-_PyTime_FromMicrosecondsClamp(_PyTime_t us)
+PyTime_t
+_PyTime_FromMicrosecondsClamp(PyTime_t us)
{
- _PyTime_t ns = _PyTime_Mul(us, US_TO_NS);
+ PyTime_t ns = _PyTime_Mul(us, US_TO_NS);
return pytime_from_nanoseconds(ns);
}
int
-_PyTime_FromNanosecondsObject(_PyTime_t *tp, PyObject *obj)
+_PyTime_FromNanosecondsObject(PyTime_t *tp, PyObject *obj)
{
if (!PyLong_Check(obj)) {
return -1;
}
- static_assert(sizeof(long long) == sizeof(_PyTime_t),
- "_PyTime_t is not long long");
+ static_assert(sizeof(long long) == sizeof(PyTime_t),
+ "PyTime_t is not long long");
long long nsec = PyLong_AsLongLong(obj);
if (nsec == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
return -1;
}
- _PyTime_t t = (_PyTime_t)nsec;
+ PyTime_t t = (PyTime_t)nsec;
*tp = pytime_from_nanoseconds(t);
return 0;
}
#ifdef HAVE_CLOCK_GETTIME
static int
-pytime_fromtimespec(_PyTime_t *tp, const struct timespec *ts, int raise_exc)
+pytime_fromtimespec(PyTime_t *tp, const struct timespec *ts, int raise_exc)
{
- _PyTime_t t, tv_nsec;
+ PyTime_t t, tv_nsec;
- static_assert(sizeof(ts->tv_sec) <= sizeof(_PyTime_t),
- "timespec.tv_sec is larger than _PyTime_t");
- t = (_PyTime_t)ts->tv_sec;
+ static_assert(sizeof(ts->tv_sec) <= sizeof(PyTime_t),
+ "timespec.tv_sec is larger than PyTime_t");
+ t = (PyTime_t)ts->tv_sec;
int res1 = pytime_mul(&t, SEC_TO_NS);
}
int
-_PyTime_FromTimespec(_PyTime_t *tp, const struct timespec *ts)
+_PyTime_FromTimespec(PyTime_t *tp, const struct timespec *ts)
{
return pytime_fromtimespec(tp, ts, 1);
}
#ifndef MS_WINDOWS
static int
-pytime_fromtimeval(_PyTime_t *tp, struct timeval *tv, int raise_exc)
+pytime_fromtimeval(PyTime_t *tp, struct timeval *tv, int raise_exc)
{
- static_assert(sizeof(tv->tv_sec) <= sizeof(_PyTime_t),
- "timeval.tv_sec is larger than _PyTime_t");
- _PyTime_t t = (_PyTime_t)tv->tv_sec;
+ static_assert(sizeof(tv->tv_sec) <= sizeof(PyTime_t),
+ "timeval.tv_sec is larger than PyTime_t");
+ PyTime_t t = (PyTime_t)tv->tv_sec;
int res1 = pytime_mul(&t, SEC_TO_NS);
- _PyTime_t usec = (_PyTime_t)tv->tv_usec * US_TO_NS;
+ PyTime_t usec = (PyTime_t)tv->tv_usec * US_TO_NS;
int res2 = pytime_add(&t, usec);
*tp = pytime_from_nanoseconds(t);
int
-_PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv)
+_PyTime_FromTimeval(PyTime_t *tp, struct timeval *tv)
{
return pytime_fromtimeval(tp, tv, 1);
}
static int
-pytime_from_double(_PyTime_t *tp, double value, _PyTime_round_t round,
+pytime_from_double(PyTime_t *tp, double value, _PyTime_round_t round,
long unit_to_ns)
{
/* volatile avoids optimization changing how numbers are rounded */
pytime_time_t_overflow();
return -1;
}
- _PyTime_t ns = (_PyTime_t)d;
+ PyTime_t ns = (PyTime_t)d;
*tp = pytime_from_nanoseconds(ns);
return 0;
static int
-pytime_from_object(_PyTime_t *tp, PyObject *obj, _PyTime_round_t round,
+pytime_from_object(PyTime_t *tp, PyObject *obj, _PyTime_round_t round,
long unit_to_ns)
{
if (PyFloat_Check(obj)) {
return -1;
}
- static_assert(sizeof(long long) <= sizeof(_PyTime_t),
- "_PyTime_t is smaller than long long");
- _PyTime_t ns = (_PyTime_t)sec;
+ static_assert(sizeof(long long) <= sizeof(PyTime_t),
+ "PyTime_t is smaller than long long");
+ PyTime_t ns = (PyTime_t)sec;
if (pytime_mul(&ns, unit_to_ns) < 0) {
pytime_overflow();
return -1;
int
-_PyTime_FromSecondsObject(_PyTime_t *tp, PyObject *obj, _PyTime_round_t round)
+_PyTime_FromSecondsObject(PyTime_t *tp, PyObject *obj, _PyTime_round_t round)
{
return pytime_from_object(tp, obj, round, SEC_TO_NS);
}
int
-_PyTime_FromMillisecondsObject(_PyTime_t *tp, PyObject *obj, _PyTime_round_t round)
+_PyTime_FromMillisecondsObject(PyTime_t *tp, PyObject *obj, _PyTime_round_t round)
{
return pytime_from_object(tp, obj, round, MS_TO_NS);
}
if (ns % SEC_TO_NS == 0) {
/* Divide using integers to avoid rounding issues on the integer part.
1e-9 cannot be stored exactly in IEEE 64-bit. */
- _PyTime_t secs = ns / SEC_TO_NS;
+ PyTime_t secs = ns / SEC_TO_NS;
d = (double)secs;
}
else {
PyObject *
-_PyTime_AsNanosecondsObject(_PyTime_t t)
+_PyTime_AsNanosecondsObject(PyTime_t t)
{
- _PyTime_t ns = pytime_as_nanoseconds(t);
- static_assert(sizeof(long long) >= sizeof(_PyTime_t),
- "_PyTime_t is larger than long long");
+ PyTime_t ns = pytime_as_nanoseconds(t);
+ static_assert(sizeof(long long) >= sizeof(PyTime_t),
+ "PyTime_t is larger than long long");
return PyLong_FromLongLong((long long)ns);
}
-_PyTime_t
+PyTime_t
_PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round)
{
- _PyTime_t tp;
+ PyTime_t tp;
if(pytime_from_double(&tp, seconds, round, SEC_TO_NS) < 0) {
return -1;
}
}
-static _PyTime_t
-pytime_divide_round_up(const _PyTime_t t, const _PyTime_t k)
+static PyTime_t
+pytime_divide_round_up(const PyTime_t t, const PyTime_t k)
{
assert(k > 1);
if (t >= 0) {
// Don't use (t + k - 1) / k to avoid integer overflow
// if t is equal to PyTime_MAX
- _PyTime_t q = t / k;
+ PyTime_t q = t / k;
if (t % k) {
q += 1;
}
else {
// Don't use (t - (k - 1)) / k to avoid integer overflow
// if t is equals to PyTime_MIN.
- _PyTime_t q = t / k;
+ PyTime_t q = t / k;
if (t % k) {
q -= 1;
}
}
-static _PyTime_t
-pytime_divide(const _PyTime_t t, const _PyTime_t k,
+static PyTime_t
+pytime_divide(const PyTime_t t, const PyTime_t k,
const _PyTime_round_t round)
{
assert(k > 1);
if (round == _PyTime_ROUND_HALF_EVEN) {
- _PyTime_t x = t / k;
- _PyTime_t r = t % k;
- _PyTime_t abs_r = Py_ABS(r);
+ PyTime_t x = t / k;
+ PyTime_t r = t % k;
+ PyTime_t abs_r = Py_ABS(r);
if (abs_r > k / 2 || (abs_r == k / 2 && (Py_ABS(x) & 1))) {
if (t >= 0) {
x++;
// Return 0 on success.
// Return -1 on underflow and store (PyTime_MIN, 0) in (pq, pr).
static int
-pytime_divmod(const _PyTime_t t, const _PyTime_t k,
- _PyTime_t *pq, _PyTime_t *pr)
+pytime_divmod(const PyTime_t t, const PyTime_t k,
+ PyTime_t *pq, PyTime_t *pr)
{
assert(k > 1);
- _PyTime_t q = t / k;
- _PyTime_t r = t % k;
+ PyTime_t q = t / k;
+ PyTime_t r = t % k;
if (r < 0) {
if (q == PyTime_MIN) {
*pq = PyTime_MIN;
#ifdef MS_WINDOWS
-_PyTime_t
-_PyTime_As100Nanoseconds(_PyTime_t t, _PyTime_round_t round)
+PyTime_t
+_PyTime_As100Nanoseconds(PyTime_t t, _PyTime_round_t round)
{
- _PyTime_t ns = pytime_as_nanoseconds(t);
+ PyTime_t ns = pytime_as_nanoseconds(t);
return pytime_divide(ns, NS_TO_100NS, round);
}
#endif
-_PyTime_t
-_PyTime_AsMicroseconds(_PyTime_t t, _PyTime_round_t round)
+PyTime_t
+_PyTime_AsMicroseconds(PyTime_t t, _PyTime_round_t round)
{
- _PyTime_t ns = pytime_as_nanoseconds(t);
+ PyTime_t ns = pytime_as_nanoseconds(t);
return pytime_divide(ns, NS_TO_US, round);
}
-_PyTime_t
-_PyTime_AsMilliseconds(_PyTime_t t, _PyTime_round_t round)
+PyTime_t
+_PyTime_AsMilliseconds(PyTime_t t, _PyTime_round_t round)
{
- _PyTime_t ns = pytime_as_nanoseconds(t);
+ PyTime_t ns = pytime_as_nanoseconds(t);
return pytime_divide(ns, NS_TO_MS, round);
}
static int
-pytime_as_timeval(_PyTime_t t, _PyTime_t *ptv_sec, int *ptv_usec,
+pytime_as_timeval(PyTime_t t, PyTime_t *ptv_sec, int *ptv_usec,
_PyTime_round_t round)
{
- _PyTime_t ns = pytime_as_nanoseconds(t);
- _PyTime_t us = pytime_divide(ns, US_TO_NS, round);
+ PyTime_t ns = pytime_as_nanoseconds(t);
+ PyTime_t us = pytime_divide(ns, US_TO_NS, round);
- _PyTime_t tv_sec, tv_usec;
+ PyTime_t tv_sec, tv_usec;
int res = pytime_divmod(us, SEC_TO_US, &tv_sec, &tv_usec);
*ptv_sec = tv_sec;
*ptv_usec = (int)tv_usec;
static int
-pytime_as_timeval_struct(_PyTime_t t, struct timeval *tv,
+pytime_as_timeval_struct(PyTime_t t, struct timeval *tv,
_PyTime_round_t round, int raise_exc)
{
- _PyTime_t tv_sec;
+ PyTime_t tv_sec;
int tv_usec;
int res = pytime_as_timeval(t, &tv_sec, &tv_usec, round);
int res2;
int
-_PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
+_PyTime_AsTimeval(PyTime_t t, struct timeval *tv, _PyTime_round_t round)
{
return pytime_as_timeval_struct(t, tv, round, 1);
}
void
-_PyTime_AsTimeval_clamp(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
+_PyTime_AsTimeval_clamp(PyTime_t t, struct timeval *tv, _PyTime_round_t round)
{
(void)pytime_as_timeval_struct(t, tv, round, 0);
}
int
-_PyTime_AsTimevalTime_t(_PyTime_t t, time_t *p_secs, int *us,
+_PyTime_AsTimevalTime_t(PyTime_t t, time_t *p_secs, int *us,
_PyTime_round_t round)
{
- _PyTime_t secs;
+ PyTime_t secs;
if (pytime_as_timeval(t, &secs, us, round) < 0) {
pytime_time_t_overflow();
return -1;
#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_KQUEUE)
static int
-pytime_as_timespec(_PyTime_t t, struct timespec *ts, int raise_exc)
+pytime_as_timespec(PyTime_t t, struct timespec *ts, int raise_exc)
{
- _PyTime_t ns = pytime_as_nanoseconds(t);
- _PyTime_t tv_sec, tv_nsec;
+ PyTime_t ns = pytime_as_nanoseconds(t);
+ PyTime_t tv_sec, tv_nsec;
int res = pytime_divmod(ns, SEC_TO_NS, &tv_sec, &tv_nsec);
int res2 = _PyTime_AsTime_t(tv_sec, &ts->tv_sec);
}
void
-_PyTime_AsTimespec_clamp(_PyTime_t t, struct timespec *ts)
+_PyTime_AsTimespec_clamp(PyTime_t t, struct timespec *ts)
{
(void)pytime_as_timespec(t, ts, 0);
}
int
-_PyTime_AsTimespec(_PyTime_t t, struct timespec *ts)
+_PyTime_AsTimespec(PyTime_t t, struct timespec *ts)
{
return pytime_as_timespec(t, ts, 1);
}
// N.B. If raise_exc=0, this may be called without the GIL.
static int
-py_get_system_clock(_PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
+py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
{
assert(info == NULL || raise_exc);
/* 11,644,473,600,000,000,000: number of nanoseconds between
the 1st january 1601 and the 1st january 1970 (369 years + 89 leap
days). */
- _PyTime_t ns = large.QuadPart * 100 - 11644473600000000000;
+ PyTime_t ns = large.QuadPart * 100 - 11644473600000000000;
*tp = pytime_from_nanoseconds(ns);
if (info) {
DWORD timeAdjustment, timeIncrement;
}
-_PyTime_t
+PyTime_t
_PyTime_GetSystemClock(void)
{
- _PyTime_t t;
+ PyTime_t t;
if (py_get_system_clock(&t, NULL, 0) < 0) {
// If clock_gettime(CLOCK_REALTIME) or gettimeofday() fails:
// silently ignore the failure and return 0.
}
int
-_PyTime_GetSystemClockWithInfo(_PyTime_t *t, _Py_clock_info_t *info)
+_PyTime_GetSystemClockWithInfo(PyTime_t *t, _Py_clock_info_t *info)
{
return py_get_system_clock(t, info, 1);
}
(void)mach_timebase_info(&timebase);
// Check that timebase.numer and timebase.denom can be casted to
- // _PyTime_t. In practice, timebase uses uint32_t, so casting cannot
+ // PyTime_t. In practice, timebase uses uint32_t, so casting cannot
// overflow. At the end, only make sure that the type is uint32_t
- // (_PyTime_t is 64-bit long).
- Py_BUILD_ASSERT(sizeof(timebase.numer) <= sizeof(_PyTime_t));
- Py_BUILD_ASSERT(sizeof(timebase.denom) <= sizeof(_PyTime_t));
- _PyTime_t numer = (_PyTime_t)timebase.numer;
- _PyTime_t denom = (_PyTime_t)timebase.denom;
+ // (PyTime_t is 64-bit long).
+ Py_BUILD_ASSERT(sizeof(timebase.numer) <= sizeof(PyTime_t));
+ Py_BUILD_ASSERT(sizeof(timebase.denom) <= sizeof(PyTime_t));
+ PyTime_t numer = (PyTime_t)timebase.numer;
+ PyTime_t denom = (PyTime_t)timebase.denom;
// Known time bases:
//
// N.B. If raise_exc=0, this may be called without the GIL.
static int
-py_get_monotonic_clock(_PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
+py_get_monotonic_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
{
assert(info == NULL || raise_exc);
#if defined(MS_WINDOWS)
ULONGLONG ticks = GetTickCount64();
- static_assert(sizeof(ticks) <= sizeof(_PyTime_t),
- "ULONGLONG is larger than _PyTime_t");
- _PyTime_t t;
+ static_assert(sizeof(ticks) <= sizeof(PyTime_t),
+ "ULONGLONG is larger than PyTime_t");
+ PyTime_t t;
if (ticks <= (ULONGLONG)PyTime_MAX) {
- t = (_PyTime_t)ticks;
+ t = (PyTime_t)ticks;
}
else {
- // GetTickCount64() maximum is larger than _PyTime_t maximum:
- // ULONGLONG is unsigned, whereas _PyTime_t is signed.
+ // GetTickCount64() maximum is larger than PyTime_t maximum:
+ // ULONGLONG is unsigned, whereas PyTime_t is signed.
t = PyTime_MAX;
}
uint64_t uticks = mach_absolute_time();
// unsigned => signed
assert(uticks <= (uint64_t)PyTime_MAX);
- _PyTime_t ticks = (_PyTime_t)uticks;
+ PyTime_t ticks = (PyTime_t)uticks;
- _PyTime_t ns = _PyTimeFraction_Mul(ticks, &base);
+ PyTime_t ns = _PyTimeFraction_Mul(ticks, &base);
*tp = pytime_from_nanoseconds(ns);
#elif defined(__hpux)
}
-_PyTime_t
+PyTime_t
_PyTime_GetMonotonicClock(void)
{
- _PyTime_t t;
+ PyTime_t t;
if (py_get_monotonic_clock(&t, NULL, 0) < 0) {
// If mach_timebase_info(), clock_gettime() or gethrtime() fails:
// silently ignore the failure and return 0.
int
-_PyTime_GetMonotonicClockWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+_PyTime_GetMonotonicClockWithInfo(PyTime_t *tp, _Py_clock_info_t *info)
{
return py_get_monotonic_clock(tp, info, 1);
}
// Since Windows XP, frequency cannot be zero.
assert(frequency >= 1);
- Py_BUILD_ASSERT(sizeof(_PyTime_t) == sizeof(frequency));
- _PyTime_t denom = (_PyTime_t)frequency;
+ Py_BUILD_ASSERT(sizeof(PyTime_t) == sizeof(frequency));
+ PyTime_t denom = (PyTime_t)frequency;
// Known QueryPerformanceFrequency() values:
//
// N.B. If raise_exc=0, this may be called without the GIL.
static int
-py_get_win_perf_counter(_PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
+py_get_win_perf_counter(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
{
assert(info == NULL || raise_exc);
QueryPerformanceCounter(&now);
LONGLONG ticksll = now.QuadPart;
- /* Make sure that casting LONGLONG to _PyTime_t cannot overflow,
+ /* Make sure that casting LONGLONG to PyTime_t cannot overflow,
both types are signed */
- _PyTime_t ticks;
+ PyTime_t ticks;
static_assert(sizeof(ticksll) <= sizeof(ticks),
- "LONGLONG is larger than _PyTime_t");
- ticks = (_PyTime_t)ticksll;
+ "LONGLONG is larger than PyTime_t");
+ ticks = (PyTime_t)ticksll;
- _PyTime_t ns = _PyTimeFraction_Mul(ticks, &base);
+ PyTime_t ns = _PyTimeFraction_Mul(ticks, &base);
*tp = pytime_from_nanoseconds(ns);
return 0;
}
int
-_PyTime_GetPerfCounterWithInfo(_PyTime_t *t, _Py_clock_info_t *info)
+_PyTime_GetPerfCounterWithInfo(PyTime_t *t, _Py_clock_info_t *info)
{
#ifdef MS_WINDOWS
return py_get_win_perf_counter(t, info, 1);
}
-_PyTime_t
+PyTime_t
_PyTime_GetPerfCounter(void)
{
- _PyTime_t t;
+ PyTime_t t;
int res;
#ifdef MS_WINDOWS
res = py_get_win_perf_counter(&t, NULL, 0);
}
-_PyTime_t
-_PyDeadline_Init(_PyTime_t timeout)
+PyTime_t
+_PyDeadline_Init(PyTime_t timeout)
{
- _PyTime_t now = _PyTime_GetMonotonicClock();
+ PyTime_t now = _PyTime_GetMonotonicClock();
return _PyTime_Add(now, timeout);
}
-_PyTime_t
-_PyDeadline_Get(_PyTime_t deadline)
+PyTime_t
+_PyDeadline_Get(PyTime_t deadline)
{
- _PyTime_t now = _PyTime_GetMonotonicClock();
+ PyTime_t now = _PyTime_GetMonotonicClock();
return deadline - now;
}
return -1;
}
- _PyTime_t timeout;
+ PyTime_t timeout;
if (_PyTime_FromSecondsObject(&timeout, arg, _PyTime_ROUND_TIMEOUT) < 0) {
return -1;
}
PY_TIMEOUT_T timeout)
{
PyThreadState *tstate = _PyThreadState_GET();
- _PyTime_t endtime = 0;
+ PyTime_t endtime = 0;
if (timeout > 0) {
endtime = _PyDeadline_Init(timeout);
}
PyLockStatus r;
do {
- _PyTime_t microseconds;
+ PyTime_t microseconds;
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_CEILING);
/* first a simple non-blocking try without releasing the GIL */
}
} else if (milliseconds != 0) {
/* wait at least until the deadline */
- _PyTime_t nanoseconds = _PyTime_FromNanoseconds((_PyTime_t)milliseconds * 1000000);
- _PyTime_t deadline = _PyTime_Add(_PyTime_GetPerfCounter(), nanoseconds);
+ PyTime_t nanoseconds = _PyTime_FromNanoseconds((PyTime_t)milliseconds * 1000000);
+ PyTime_t deadline = _PyTime_Add(_PyTime_GetPerfCounter(), nanoseconds);
while (mutex->locked) {
- _PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds,
+ PyTime_t microseconds = _PyTime_AsMicroseconds(nanoseconds,
_PyTime_ROUND_TIMEOUT);
if (PyCOND_TIMEDWAIT(&mutex->cv, &mutex->cs, microseconds) < 0) {
result = WAIT_FAILED;
void
_PyThread_cond_after(long long us, struct timespec *abs)
{
- _PyTime_t timeout = _PyTime_FromMicrosecondsClamp(us);
- _PyTime_t t;
+ PyTime_t timeout = _PyTime_FromMicrosecondsClamp(us);
+ PyTime_t t;
#ifdef CONDATTR_MONOTONIC
if (condattr_monotonic) {
t = _PyTime_GetMonotonicClock();
(void) error; /* silence unused-but-set-variable warning */
- _PyTime_t timeout; // relative timeout
+ PyTime_t timeout; // relative timeout
if (microseconds >= 0) {
// bpo-41710: PyThread_acquire_lock_timed() cannot report timeout
// overflow to the caller, so clamp the timeout to
struct timespec abs_timeout;
// Local scope for deadline
{
- _PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout);
+ PyTime_t deadline = _PyTime_Add(_PyTime_GetMonotonicClock(), timeout);
_PyTime_AsTimespec_clamp(deadline, &abs_timeout);
}
#else
- _PyTime_t deadline = 0;
+ PyTime_t deadline = 0;
if (timeout > 0 && !intr_flag) {
deadline = _PyDeadline_Init(timeout);
}
status = fix_status(sem_clockwait(thelock, CLOCK_MONOTONIC,
&abs_timeout));
#else
- _PyTime_t abs_time = _PyTime_Add(_PyTime_GetSystemClock(),
+ PyTime_t abs_time = _PyTime_Add(_PyTime_GetSystemClock(),
timeout);
struct timespec ts;
_PyTime_AsTimespec_clamp(abs_time, &ts);