summaryrefslogtreecommitdiffstats
path: root/Modules/timemodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-08-29 14:51:33 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-08-29 14:51:33 (GMT)
commit5488449ba467bb9baa8c759c7f8534cb2e8d0224 (patch)
treea44ed21e7f6b9d8fc5310b5f703f1696fe9499bf /Modules/timemodule.c
parent0011124dc235fb9af1a80acf3df7edd8816c0a9d (diff)
downloadcpython-5488449ba467bb9baa8c759c7f8534cb2e8d0224.zip
cpython-5488449ba467bb9baa8c759c7f8534cb2e8d0224.tar.gz
cpython-5488449ba467bb9baa8c759c7f8534cb2e8d0224.tar.bz2
Issue #22043: Simplify time.perf_counter() on Windows
QueryPerformanceFrequency() cannot fail on Windows XP and later according to its documentation: raise an exception on error and drop the fallback to the system clock.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r--Modules/timemodule.c46
1 files changed, 16 insertions, 30 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 1a13fd0e..abf4b8b 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -96,8 +96,8 @@ floatclock(_Py_clock_info_t *info)
#define WIN32_PERF_COUNTER
/* Win32 has better clock replacement; we have our own version, due to Mark
Hammond and Tim Peters */
-static int
-win_perf_counter(_Py_clock_info_t *info, PyObject **result)
+static PyObject*
+win_perf_counter(_Py_clock_info_t *info)
{
static LONGLONG cpu_frequency = 0;
static LONGLONG ctrStart;
@@ -109,10 +109,8 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result)
QueryPerformanceCounter(&now);
ctrStart = now.QuadPart;
if (!QueryPerformanceFrequency(&freq) || freq.QuadPart == 0) {
- /* Unlikely to happen - this works on all intel
- machines at least! Revert to clock() */
- *result = NULL;
- return -1;
+ PyErr_SetFromWindowsErr(0);
+ return NULL;
}
cpu_frequency = freq.QuadPart;
}
@@ -124,8 +122,7 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result)
info->monotonic = 1;
info->adjustable = 0;
}
- *result = PyFloat_FromDouble(diff / (double)cpu_frequency);
- return 0;
+ return PyFloat_FromDouble(diff / (double)cpu_frequency);
}
#endif
@@ -135,11 +132,10 @@ static PyObject*
pyclock(_Py_clock_info_t *info)
{
#ifdef WIN32_PERF_COUNTER
- PyObject *res;
- if (win_perf_counter(info, &res) == 0)
- return res;
-#endif
+ return win_perf_counter(info);
+#else
return floatclock(info);
+#endif
}
static PyObject *
@@ -1036,35 +1032,25 @@ Monotonic clock, cannot go backward.");
static PyObject*
perf_counter(_Py_clock_info_t *info)
{
-#if defined(WIN32_PERF_COUNTER) || defined(PYMONOTONIC)
- PyObject *res;
-#endif
-#if defined(WIN32_PERF_COUNTER)
- static int use_perf_counter = 1;
-#endif
-#ifdef PYMONOTONIC
- static int use_monotonic = 1;
-#endif
-
#ifdef WIN32_PERF_COUNTER
- if (use_perf_counter) {
- if (win_perf_counter(info, &res) == 0)
- return res;
- use_perf_counter = 0;
- }
-#endif
+ return win_perf_counter(info);
+#else
#ifdef PYMONOTONIC
+ static int use_monotonic = 1;
+
if (use_monotonic) {
- res = pymonotonic(info);
+ PyObject *res = pymonotonic(info);
if (res != NULL)
return res;
use_monotonic = 0;
PyErr_Clear();
}
+#else
+ return floattime(info);
#endif
- return floattime(info);
+#endif
}
static PyObject *