diff options
author | Jake Tesler <jake.tesler@gmail.com> | 2019-05-12 17:08:24 (GMT) |
---|---|---|
committer | Antoine Pitrou <antoine@python.org> | 2019-05-12 17:08:24 (GMT) |
commit | 4959c33d2555b89b494c678d99be81a65ee864b0 (patch) | |
tree | 87df7778f170864ef1efe3418ac3cb3c47051c50 /Python/thread_pthread.h | |
parent | 87068ed00927bdeaa2ae556e4241c16cf8a845eb (diff) | |
download | cpython-4959c33d2555b89b494c678d99be81a65ee864b0.zip cpython-4959c33d2555b89b494c678d99be81a65ee864b0.tar.gz cpython-4959c33d2555b89b494c678d99be81a65ee864b0.tar.bz2 |
bpo-36084: Add native thread ID to threading.Thread objects (GH-11993)
Diffstat (limited to 'Python/thread_pthread.h')
-rw-r--r-- | Python/thread_pthread.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 4c106d9..87c98d3 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -12,6 +12,12 @@ #endif #include <signal.h> +#if defined(__linux__) +#include <sys/syscall.h> +#elif defined(__FreeBSD__) +#include <pthread_np.h> +#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,27 @@ PyThread_get_thread_ident(void) return (unsigned long) threadid; } +unsigned long +PyThread_get_thread_native_id(void) +{ + if (!initialized) + PyThread_init_thread(); +#ifdef __APPLE__ + uint64_t native_id; + pthread_threadid_np(NULL, &native_id); +#elif defined(__linux__) + pid_t native_id; + native_id = syscall(__NR_gettid); +#elif defined(__FreeBSD__) + pid_t native_id; + native_id = pthread_getthreadid_np(); +#else + unsigned long native_id; + native_id = 0; +#endif + return (unsigned long) native_id; +} + void _Py_NO_RETURN PyThread_exit_thread(void) { |