From e7dee9296cf29f29065ad8d7650758c0f0914bbd Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Tue, 11 Dec 2018 12:45:56 +0000 Subject: [PATCH 1/4] bpo-35455: Fix thread_time for Solaris OS --- Modules/timemodule.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 8a4d149befb52a..fafa5fef47e28d 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1371,6 +1371,25 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) return 0; } +#elif defined(__sun) && defined(__SVR4) +#define HAVE_THREAD_TIME +static int +_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) +{ + _PyTime_t t; + + if (info) { + info->implementation = "gethrvtime()"; + info->resolution = 1e-9; + info->monotonic = 1; + info->adjustable = 0; + } + + t = _PyTime_FromNanoseconds(gethrvtime()); + *tp = t; + return 0; +} + #elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) #define HAVE_THREAD_TIME static int From 79c58b47280cb53edd18ff45ad26afe5ff476c97 Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Mon, 2 Nov 2020 14:10:24 +0100 Subject: [PATCH 2/4] add comment explaining the change --- Modules/timemodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index fafa5fef47e28d..fdcd6b7c65377a 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1376,6 +1376,8 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) static int _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) { + /* bpo-35455: On Solaris, CLOCK_THREAD_CPUTIME_ID clock is not always + available; use gethrvtime() to substitute this functionality. */ _PyTime_t t; if (info) { From a153a1b6d53d47b94b7a557142f0b4c3f026f0f6 Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Mon, 2 Nov 2020 14:14:33 +0100 Subject: [PATCH 3/4] Add NEWS entry --- .../next/Library/2020-11-02-14-10-48.bpo-35455.Q1xTIo.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-11-02-14-10-48.bpo-35455.Q1xTIo.rst diff --git a/Misc/NEWS.d/next/Library/2020-11-02-14-10-48.bpo-35455.Q1xTIo.rst b/Misc/NEWS.d/next/Library/2020-11-02-14-10-48.bpo-35455.Q1xTIo.rst new file mode 100644 index 00000000000000..e72c7d277a1123 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-11-02-14-10-48.bpo-35455.Q1xTIo.rst @@ -0,0 +1,3 @@ +On Solaris, :func:`~time.thread_time` is now implemented with +``gethrvtime()`` because ``clock_gettime(CLOCK_THREAD_CPUTIME_ID)`` is not +always available. Patch by Jakub Kulik. From 8dbb8956de3e794ca9ee49fda22f93ed21741390 Mon Sep 17 00:00:00 2001 From: Jakub Kulik Date: Mon, 2 Nov 2020 19:28:26 +0100 Subject: [PATCH 4/4] Remove unnecessary auxiliary variable --- Modules/timemodule.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index fdcd6b7c65377a..eb192c5e7fd31e 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1378,17 +1378,13 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info) { /* bpo-35455: On Solaris, CLOCK_THREAD_CPUTIME_ID clock is not always available; use gethrvtime() to substitute this functionality. */ - _PyTime_t t; - if (info) { info->implementation = "gethrvtime()"; info->resolution = 1e-9; info->monotonic = 1; info->adjustable = 0; } - - t = _PyTime_FromNanoseconds(gethrvtime()); - *tp = t; + *tp = _PyTime_FromNanoseconds(gethrvtime()); return 0; }