8000 gh-113791: Expose CLOCK_MONOTONIC_RAW_APPROX and CLOCK_UPTIME_RAW_APROX on macOS in the time module by ronaldoussoren · Pull Request #113792 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-113791: Expose CLOCK_MONOTONIC_RAW_APPROX and CLOCK_UPTIME_RAW_APROX on macOS in the time module #113792

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions Doc/library/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,15 @@ These constants are used as parameters for :func:`clock_getres` and

.. versionadded:: 3.3

.. data:: CLOCK_MONOTONIC_RAW_APPROX

Similar to :data:`CLOCK_MONOTONIC_RAW`, but reads a value cached by
the system at context switch and hence has less accuracy.

.. availability:: macOS >= 10.12.

.. versionadded:: 3.13


.. data:: CLOCK_PROCESS_CPUTIME_ID

Expand Down Expand Up @@ -899,6 +908,15 @@ These constants are used as parameters for :func:`clock_getres` and

.. versionadded:: 3.8

.. data:: CLOCK_UPTIME_RAW_APPROX

Like :data:`CLOCK_UPTIME_RAW`, but the value is cached by the system
at context switches and therefore has less accuracy.

.. availability:: macOS >= 10.12.

.. versionadded:: 3.13

The following constant is the only parameter that can be sent to
:func:`clock_settime`.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ``CLOCK_MONOTONIC_RAW_APPROX`` and ``CLOCK_UPTIME_RAW_APPROX`` to
:mod:`time` on macOS. These are clocks available on macOS 10.12 or later.
16 changes: 10 additions & 6 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,20 +1993,16 @@ time_exec(PyObject *module)
return -1;
}
#endif

#ifdef CLOCK_MONOTONIC

if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC) < 0) {
return -1;
}

#endif
#ifdef CLOCK_MONOTONIC_RAW
if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC_RAW) < 0) {
return -1;
}
#endif

#ifdef CLOCK_HIGHRES
if (PyModule_AddIntMacro(module, CLOCK_HIGHRES) < 0) {
return -1;
Expand All @@ -2017,7 +2013,6 @@ time_exec(PyObject *module)
return -1;
}
#endif

#ifdef CLOCK_THREAD_CPUTIME_ID
if (PyModule_AddIntMacro(module, CLOCK_THREAD_CPUTIME_ID) < 0) {
return -1;
Expand All @@ -2044,10 +2039,19 @@ time_exec(PyObject *module)
}
#endif
#ifdef CLOCK_UPTIME_RAW

if (PyModule_AddIntMacro(module, CLOCK_UPTIME_RAW) < 0) {
return -1;
}
#endif
#ifdef CLOCK_MONOTONIC_RAW_APPROX
if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC_RAW_APPROX) < 0) {
return -1;
}
#endif
#ifdef CLOCK_UPTIME_RAW_APPROX
if (PyModule_AddIntMacro(module, CLOCK_UPTIME_RAW_APPROX) < 0) {
return -1;
}
#endif
}

Expand Down
0