bpo-36084: Add native thread ID (TID) to threading.Thread (GH-13463)

Add native thread ID (TID) to threading.Thread objects
(supported platforms: Windows, FreeBSD, Linux, macOS).
This commit is contained in:
Jake Tesler 2019-05-22 08:43:17 -07:00 committed by Victor Stinner
parent b3be407288
commit b121f63155
9 changed files with 154 additions and 0 deletions

View file

@ -12,6 +12,12 @@
#endif
#include <signal.h>
#if defined(__linux__)
# include <sys/syscall.h> /* syscall(SYS_gettid) */
#elif defined(__FreeBSD__)
# include <pthread_np.h> /* pthread_getthreadid_np() */
#endif
/* The POSIX spec requires that use of pthread_attr_setstacksize
be conditional on _POSIX_THREAD_ATTR_STACKSIZE being defined. */
#ifdef _POSIX_THREAD_ATTR_STACKSIZE
@ -302,6 +308,26 @@ PyThread_get_thread_ident(void)
return (unsigned long) threadid;
}
#ifdef PY_HAVE_THREAD_NATIVE_ID
unsigned long
PyThread_get_thread_native_id(void)
{
if (!initialized)
PyThread_init_thread();
#ifdef __APPLE__
uint64_t native_id;
(void) pthread_threadid_np(NULL, &native_id);
#elif defined(__linux__)
pid_t native_id;
native_id = syscall(SYS_gettid);
#elif defined(__FreeBSD__)
int native_id;
native_id = pthread_getthreadid_np();
#endif
return (unsigned long) native_id;
}
#endif
void _Py_NO_RETURN
PyThread_exit_thread(void)
{