Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-86273: On macOS >= 10.12, useclock_gettime(CLOCK_MONOTONIC_RAW) fortime.monotonic#134521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jhohm wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromjhohm:gh-86273
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionDoc/library/time.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -295,7 +295,7 @@ Functions

* On Windows, call ``QueryPerformanceCounter()`` and
``QueryPerformanceFrequency()``.
* On macOS, call ``mach_absolute_time()`` and ``mach_timebase_info()``.
* On macOS, call ``clock_gettime(CLOCK_MONOTONIC_RAW)`` if available, otherwise call ``mach_absolute_time()`` and ``mach_timebase_info()``.
* On HP-UX, call ``gethrtime()``.
* Call ``clock_gettime(CLOCK_HIGHRES)`` if available.
* Otherwise, call ``clock_gettime(CLOCK_MONOTONIC)``.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
On macOS >= 10.12, use ``clock_gettime(CLOCK_MONOTONIC_RAW)`` for
:func:`time.monotonic`. Patch by John Keith Hohm.
13 changes: 8 additions & 5 deletionsPython/pytime.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@
# include <winsock2.h> // struct timeval
#endif

#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(CLOCK_MONOTONIC_RAW)
# include <mach/mach_time.h> // mach_absolute_time(), mach_timebase_info()

#if defined(__APPLE__) && defined(__has_builtin)
Expand DownExpand Up@@ -933,7 +933,7 @@ py_get_system_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
struct timespec ts;
#endif

#if !defined(HAVE_CLOCK_GETTIME) || defined(__APPLE__)
#if !defined(HAVE_CLOCK_GETTIME) ||(defined(__APPLE__) && !defined(CLOCK_MONOTONIC_RAW))
struct timeval tv;
#endif

Expand DownExpand Up@@ -1090,7 +1090,7 @@ py_get_win_perf_counter(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
#endif // MS_WINDOWS


#ifdef__APPLE__
#if defined(__APPLE__) && !defined(CLOCK_MONOTONIC_RAW)
static PyStatus
py_mach_timebase_info(_PyTimeFraction *base)
{
Expand DownExpand Up@@ -1125,7 +1125,7 @@ _PyTime_Init(struct _Py_time_runtime_state *state)
{
#ifdef MS_WINDOWS
return py_win_perf_counter_frequency(&state->base);
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(CLOCK_MONOTONIC_RAW)
return py_mach_timebase_info(&state->base);
#else
return PyStatus_Ok();
Expand All@@ -1146,7 +1146,7 @@ py_get_monotonic_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
if (py_get_win_perf_counter(tp, info, raise_exc) < 0) {
return -1;
}
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(CLOCK_MONOTONIC_RAW)
if (info) {
info->implementation = "mach_absolute_time()";
info->resolution = _PyTimeFraction_Resolution(&_PyRuntime.time.base);
Expand DownExpand Up@@ -1185,6 +1185,9 @@ py_get_monotonic_clock(PyTime_t *tp, _Py_clock_info_t *info, int raise_exc)
#ifdef CLOCK_HIGHRES
const clockid_t clk_id = CLOCK_HIGHRES;
const char *implementation = "clock_gettime(CLOCK_HIGHRES)";
#elif defined(__APPLE__) && defined(CLOCK_MONOTONIC_RAW)
const clockid_t clk_id = CLOCK_MONOTONIC_RAW;
const char *implementation = "clock_gettime(CLOCK_MONOTONIC_RAW)";
#else
const clockid_t clk_id = CLOCK_MONOTONIC;
const char *implementation = "clock_gettime(CLOCK_MONOTONIC)";
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp