summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-08-29 13:41:08 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-08-29 13:41:08 (GMT)
commit7efb83393cbe08924682c6852e94d3c4a4033c34 (patch)
treeb8ac264faa3d2470659df159932d27adcf9cd9ce /Python
parent0dc10e0d1c96c39602ae08403ed758fa72b6d547 (diff)
downloadcpython-7efb83393cbe08924682c6852e94d3c4a4033c34.zip
cpython-7efb83393cbe08924682c6852e94d3c4a4033c34.tar.gz
cpython-7efb83393cbe08924682c6852e94d3c4a4033c34.tar.bz2
Issue #22287: On UNIX, _PyTime_gettimeofday() now uses
clock_gettime(CLOCK_REALTIME) if available. As a side effect, Python now depends on the librt library on Solaris and on Linux (only with glibc older than 2.17).
Diffstat (limited to 'Python')
-rw-r--r--Python/pytime.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index de6a41f..1f3fafb 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -56,8 +56,39 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
fail, so we fall back on ftime() or time().
Note: clock resolution does not imply clock accuracy! */
-#ifdef HAVE_GETTIMEOFDAY
+#if (defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) \
+ || defined(HAVE_FTIME))
int err;
+#endif
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec ts;
+#endif
+#ifdef HAVE_FTIME
+ struct timeb t;
+#endif
+
+ /* test clock_gettime(CLOCK_REALTIME) */
+#ifdef HAVE_CLOCK_GETTIME
+ err = clock_gettime(CLOCK_REALTIME, &ts);
+ if (err == 0) {
+ if (info) {
+ struct timespec res;
+ info->implementation = "clock_gettime(CLOCK_REALTIME)";
+ info->monotonic = 0;
+ info->adjustable = 1;
+ if (clock_getres(CLOCK_REALTIME, &res) == 0)
+ info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
+ else
+ info->resolution = 1e-9;
+ }
+ tp->tv_sec = ts.tv_sec;
+ tp->tv_usec = ts.tv_nsec / 1000;
+ return;
+ }
+#endif
+
+ /* test gettimeofday() */
+#ifdef HAVE_GETTIMEOFDAY
#ifdef GETTIMEOFDAY_NO_TZ
err = gettimeofday(tp);
#else
@@ -74,18 +105,15 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
}
#endif /* HAVE_GETTIMEOFDAY */
-#if defined(HAVE_FTIME)
- {
- struct timeb t;
- ftime(&t);
- tp->tv_sec = t.time;
- tp->tv_usec = t.millitm * 1000;
- if (info) {
- info->implementation = "ftime()";
- info->resolution = 1e-3;
- info->monotonic = 0;
- info->adjustable = 1;
- }
+#ifdef HAVE_FTIME
+ ftime(&t);
+ tp->tv_sec = t.time;
+ tp->tv_usec = t.millitm * 1000;
+ if (info) {
+ info->implementation = "ftime()";
+ info->resolution = 1e-3;
+ info->monotonic = 0;
+ info->adjustable = 1;
}
#else /* !HAVE_FTIME */
tp->tv_sec = time(NULL);