Skip to content

Commit 90a6c07

Browse files
authored
bpo-43879: Add native_thread_id field to PyThreadState (pythonGH-25458)
1 parent 4f72526 commit 90a6c07

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

Include/cpython/pystate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ struct _ts {
113113
PyObject *async_exc; /* Asynchronous exception to raise */
114114
unsigned long thread_id; /* Thread id where this tstate was created */
115115

116+
/* Native thread id where this tstate was created. This will be 0 except on
117+
* those platforms that have the notion of native thread id, for which the
118+
* macro PY_HAVE_THREAD_NATIVE_ID is then defined.
119+
*/
120+
unsigned long native_thread_id;
121+
116122
int trash_delete_nesting;
117123
PyObject *trash_delete_later;
118124

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add native_thread_id to PyThreadState. Patch by Gabriele N. Tornetta.

Modules/_threadmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,11 @@ thread_run(void *boot_raw)
10711071

10721072
tstate = boot->tstate;
10731073
tstate->thread_id = PyThread_get_thread_ident();
1074+
#ifdef PY_HAVE_THREAD_NATIVE_ID
1075+
tstate->native_thread_id = PyThread_get_thread_native_id();
1076+
#else
1077+
tstate->native_thread_id = 0;
1078+
#endif
10741079
_PyThreadState_Init(tstate);
10751080
PyEval_AcquireThread(tstate);
10761081
tstate->interp->num_threads++;

Python/pystate.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ new_threadstate(PyInterpreterState *interp, int init)
645645
tstate->gilstate_counter = 0;
646646
tstate->async_exc = NULL;
647647
tstate->thread_id = PyThread_get_thread_ident();
648+
#ifdef PY_HAVE_THREAD_NATIVE_ID
649+
tstate->native_thread_id = PyThread_get_thread_native_id();
650+
#else
651+
tstate->native_thread_id = 0;
652+
#endif
648653

649654
tstate->dict = NULL;
650655

0 commit comments

Comments
 (0)