summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorpdox <pdox@alum.mit.edu>2017-10-05 07:01:56 (GMT)
committerBenjamin Peterson <benjamin@python.org>2017-10-05 07:01:56 (GMT)
commite14679c78464d1e0e16786c2a0e9bcebe49e842b (patch)
tree066f524eae0f2de963387477482575462393a6c8 /Modules
parent55fd06605b5d4fb6442645f1532aa05953bd93bc (diff)
downloadcpython-e14679c78464d1e0e16786c2a0e9bcebe49e842b.zip
cpython-e14679c78464d1e0e16786c2a0e9bcebe49e842b.tar.gz
cpython-e14679c78464d1e0e16786c2a0e9bcebe49e842b.tar.bz2
closes bpo-31596: Add an interface for pthread_getcpuclockid(3) (#3756)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/timemodule.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 36a95bb..34e057d 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -20,6 +20,10 @@
#include <io.h>
#endif
+#if defined(HAVE_PTHREAD_H)
+# include <pthread.h>
+#endif
+
#if defined(__WATCOMC__) && !defined(__QNX__)
#include <i86.h>
#else
@@ -221,6 +225,31 @@ PyDoc_STRVAR(clock_getres_doc,
Return the resolution (precision) of the specified clock clk_id.");
#endif /* HAVE_CLOCK_GETRES */
+#ifdef HAVE_PTHREAD_GETCPUCLOCKID
+static PyObject *
+time_pthread_getcpuclockid(PyObject *self, PyObject *args)
+{
+ unsigned long thread_id;
+ int err;
+ clockid_t clk_id;
+ if (!PyArg_ParseTuple(args, "k:pthread_getcpuclockid", &thread_id)) {
+ return NULL;
+ }
+ err = pthread_getcpuclockid((pthread_t)thread_id, &clk_id);
+ if (err) {
+ errno = err;
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+ return PyLong_FromLong(clk_id);
+}
+
+PyDoc_STRVAR(pthread_getcpuclockid_doc,
+"pthread_getcpuclockid(thread_id) -> int\n\
+\n\
+Return the clk_id of a thread's CPU time clock.");
+#endif /* HAVE_PTHREAD_GETCPUCLOCKID */
+
static PyObject *
time_sleep(PyObject *self, PyObject *obj)
{
@@ -1288,6 +1317,9 @@ static PyMethodDef time_methods[] = {
#ifdef HAVE_CLOCK_GETRES
{"clock_getres", time_clock_getres, METH_VARARGS, clock_getres_doc},
#endif
+#ifdef HAVE_PTHREAD_GETCPUCLOCKID
+ {"pthread_getcpuclockid", time_pthread_getcpuclockid, METH_VARARGS, pthread_getcpuclockid_doc},
+#endif
{"sleep", time_sleep, METH_O, sleep_doc},
{"gmtime", time_gmtime, METH_VARARGS, gmtime_doc},
{"localtime", time_localtime, METH_VARARGS, localtime_doc},