mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Document the fact that mach_timebase_info() cannot fail
And call mach_absolute_time() after mach_timebase_info().
This commit is contained in:
parent
650365b163
commit
74eb6c0e8b
1 changed files with 8 additions and 4 deletions
|
@ -768,13 +768,17 @@ steady_clock(int strict)
|
||||||
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
|
#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
|
||||||
return win32_clock(!strict);
|
return win32_clock(!strict);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
uint64_t time = mach_absolute_time();
|
static mach_timebase_info_data_t timebase;
|
||||||
|
uint64_t time;
|
||||||
double secs;
|
double secs;
|
||||||
|
|
||||||
static mach_timebase_info_data_t timebase;
|
if (timebase.denom == 0) {
|
||||||
if (timebase.denom == 0)
|
/* According to the Technical Q&A QA1398, mach_timebase_info() cannot
|
||||||
mach_timebase_info(&timebase);
|
fail: https://developer.apple.com/library/mac/#qa/qa1398/ */
|
||||||
|
(void)mach_timebase_info(&timebase);
|
||||||
|
}
|
||||||
|
|
||||||
|
time = mach_absolute_time();
|
||||||
secs = (double)time * timebase.numer / timebase.denom * 1e-9;
|
secs = (double)time * timebase.numer / timebase.denom * 1e-9;
|
||||||
|
|
||||||
return PyFloat_FromDouble(secs);
|
return PyFloat_FromDouble(secs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue