Skip to content

Commit a12f459

Browse files
authored
[3.8] bpo-35455: Fix thread_time for Solaris OS (GH-11118). (GH-23145)
(cherry picked from commit 9568622) Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
1 parent db4932e commit a12f459

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
On Solaris, :func:`~time.thread_time` is now implemented with
2+
``gethrvtime()`` because ``clock_gettime(CLOCK_THREAD_CPUTIME_ID)`` is not
3+
always available. Patch by Jakub Kulik.

Modules/timemodule.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,23 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
13441344
return 0;
13451345
}
13461346

1347+
#elif defined(__sun) && defined(__SVR4)
1348+
#define HAVE_THREAD_TIME
1349+
static int
1350+
_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
1351+
{
1352+
/* bpo-35455: On Solaris, CLOCK_THREAD_CPUTIME_ID clock is not always
1353+
available; use gethrvtime() to substitute this functionality. */
1354+
if (info) {
1355+
info->implementation = "gethrvtime()";
1356+
info->resolution = 1e-9;
1357+
info->monotonic = 1;
1358+
info->adjustable = 0;
1359+
}
1360+
*tp = _PyTime_FromNanoseconds(gethrvtime());
1361+
return 0;
1362+
}
1363+
13471364
#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
13481365
#define HAVE_THREAD_TIME
13491366
static int

0 commit comments

Comments
 (0)