]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43879: Add native_thread_id field to PyThreadState (GH-25458)
authorGabriele N. Tornetta <P403n1x87@users.noreply.github.com>
Wed, 26 May 2021 14:40:14 +0000 (15:40 +0100)
committerGitHub <noreply@github.com>
Wed, 26 May 2021 14:40:14 +0000 (16:40 +0200)
Include/cpython/pystate.h
Misc/NEWS.d/next/Core and Builtins/2021-04-17-16-08-00.bpo-43879.zkyJgh.rst [new file with mode: 0644]
Modules/_threadmodule.c
Python/pystate.c

index 63ba60074d56c76858440ec2b806ba0324d12706..1049eda3e51609f261a1efd783e6485a9bdaea9e 100644 (file)
@@ -113,6 +113,12 @@ struct _ts {
     PyObject *async_exc; /* Asynchronous exception to raise */
     unsigned long thread_id; /* Thread id where this tstate was created */
 
+    /* Native thread id where this tstate was created. This will be 0 except on
+     * those platforms that have the notion of native thread id, for which the
+     * macro PY_HAVE_THREAD_NATIVE_ID is then defined.
+     */
+    unsigned long native_thread_id;
+
     int trash_delete_nesting;
     PyObject *trash_delete_later;
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-04-17-16-08-00.bpo-43879.zkyJgh.rst b/Misc/NEWS.d/next/Core and Builtins/2021-04-17-16-08-00.bpo-43879.zkyJgh.rst
new file mode 100644 (file)
index 0000000..98b5173
--- /dev/null
@@ -0,0 +1 @@
+Add native_thread_id to PyThreadState. Patch by Gabriele N. Tornetta.
index 6924d6553a1ff8ffec7ef2e78b1008469d8b9b25..d4d5c0acff867747a43e64ec5ba3e11624edd196 100644 (file)
@@ -1071,6 +1071,11 @@ thread_run(void *boot_raw)
 
     tstate = boot->tstate;
     tstate->thread_id = PyThread_get_thread_ident();
+#ifdef PY_HAVE_THREAD_NATIVE_ID
+    tstate->native_thread_id = PyThread_get_thread_native_id();
+#else
+    tstate->native_thread_id = 0;
+#endif
     _PyThreadState_Init(tstate);
     PyEval_AcquireThread(tstate);
     tstate->interp->num_threads++;
index 64dcd577a0ffdbacec8ca9dd1690105dd5475a26..4a3cb24a199f17199ed721a341af576af45c2c14 100644 (file)
@@ -645,6 +645,11 @@ new_threadstate(PyInterpreterState *interp, int init)
     tstate->gilstate_counter = 0;
     tstate->async_exc = NULL;
     tstate->thread_id = PyThread_get_thread_ident();
+#ifdef PY_HAVE_THREAD_NATIVE_ID
+    tstate->native_thread_id = PyThread_get_thread_native_id();
+#else
+    tstate->native_thread_id = 0;
+#endif
 
     tstate->dict = NULL;