diff options
-rw-r--r-- | Include/cpython/pystate.h | 6 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2021-04-17-16-08-00.bpo-43879.zkyJgh.rst | 1 | ||||
-rw-r--r-- | Modules/_threadmodule.c | 5 | ||||
-rw-r--r-- | Python/pystate.c | 5 |
4 files changed, 17 insertions, 0 deletions
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 63ba600..1049eda 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -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 index 0000000..98b5173 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-04-17-16-08-00.bpo-43879.zkyJgh.rst @@ -0,0 +1 @@ +Add native_thread_id to PyThreadState. Patch by Gabriele N. Tornetta. diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 6924d65..d4d5c0a 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -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++; diff --git a/Python/pystate.c b/Python/pystate.c index 64dcd57..4a3cb24a 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -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; |