mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Issue #14104: Implement time.monotonic() on Mac OS X,
patch written by Nicholas Riley.
This commit is contained in:
parent
cad1a07bec
commit
a8ec5ea923
2 changed files with 20 additions and 1 deletions
|
@ -24,6 +24,9 @@ Core and Builtins
|
||||||
Library
|
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 #13394: the aifc module now uses warnings.warn() to signal warnings.
|
||||||
|
|
||||||
- Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under
|
- Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under
|
||||||
|
|
|
@ -40,6 +40,10 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <mach/mach_time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int floatsleep(double);
|
static int floatsleep(double);
|
||||||
static double floattime(void);
|
static double floattime(void);
|
||||||
|
@ -816,7 +820,8 @@ of the returned value is undefined so only the difference of consecutive\n\
|
||||||
calls is valid.");
|
calls is valid.");
|
||||||
|
|
||||||
#if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) \
|
#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
|
# define HAVE_PYTIME_MONOTONIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -826,6 +831,17 @@ time_monotonic(PyObject *self, PyObject *unused)
|
||||||
{
|
{
|
||||||
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
|
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
|
||||||
return win32_clock(0);
|
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
|
#else
|
||||||
static int clk_index = 0;
|
static int clk_index = 0;
|
||||||
clockid_t clk_ids[] = {
|
clockid_t clk_ids[] = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue