[Python-checkins] cpython: Issue #14104: Implement time.monotonic() on Mac OS X,
victor.stinner
python-checkins at python.org
Tue Mar 13 00:27:08 CET 2012
http://hg.python.org/cpython/rev/3c875719e46d
changeset: 75564:3c875719e46d
parent: 75562:fa0d86b4a656
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Mar 13 00:25:42 2012 +0100
summary:
Issue #14104: Implement time.monotonic() on Mac OS X,
patch written by Nicholas Riley.
files:
Misc/NEWS | 3 +++
Modules/timemodule.c | 18 +++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@
Library
-------
+- Issue #14104: Implement time.monotonic() on Mac OS X, patch written by
+ Nicholas Riley.
+
- Issue #13394: the aifc module now uses warnings.warn() to signal warnings.
- Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -40,6 +40,10 @@
#include <sys/time.h>
#endif
+#if defined(__APPLE__)
+#include <mach/mach_time.h>
+#endif
+
/* Forward declarations */
static int floatsleep(double);
static double floattime(void);
@@ -816,7 +820,8 @@
calls is valid.");
#if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) \
- || (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC))
+ || (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) \
+ || (defined(__APPLE__))
# define HAVE_PYTIME_MONOTONIC
#endif
@@ -826,6 +831,17 @@
{
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
return win32_clock(0);
+#elif defined(__APPLE__)
+ uint64_t time = mach_absolute_time();
+ double secs;
+
+ static mach_timebase_info_data_t timebase;
+ if (timebase.denom == 0)
+ mach_timebase_info(&timebase);
+
+ secs = (double)time * timebase.numer / timebase.denom * 1e-9;
+
+ return PyFloat_FromDouble(secs);
#else
static int clk_index = 0;
clockid_t clk_ids[] = {
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list