Skip to content

Commit

Permalink
pythongh-81925: Implement the native thread ids for the Hurd and KFre…
Browse files Browse the repository at this point in the history
…eBSD
  • Loading branch information
sthibaul committed Nov 5, 2023
1 parent ba8aa1f commit f76ba6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Include/pythread.h
Expand Up @@ -21,8 +21,9 @@ PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);

#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
|| defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(__DragonFly__) || defined(_AIX))
|| defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|| defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(__DragonFly__) || defined(_AIX)) || defined(__GNU__)
#define PY_HAVE_THREAD_NATIVE_ID
PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
#endif
Expand Down
12 changes: 12 additions & 0 deletions Python/thread_pthread.h
Expand Up @@ -20,6 +20,8 @@
# include <sys/syscall.h> /* syscall(SYS_gettid) */
#elif defined(__FreeBSD__)
# include <pthread_np.h> /* pthread_getthreadid_np() */
#elif defined(__FreeBSD_kernel__)
# include <sys/syscall.h> /* syscall(SYS_thr_self) */
#elif defined(__OpenBSD__)
# include <unistd.h> /* getthrid() */
#elif defined(_AIX)
Expand All @@ -28,6 +30,9 @@
# include <lwp.h> /* _lwp_self() */
#elif defined(__DragonFly__)
# include <sys/lwp.h> /* lwp_gettid() */
#elif defined(__GNU__)
# include <mach.h> /* mach_thread_self(), mach_task_self(),
mach_port_deallocate() */
#endif

/* The POSIX spec requires that use of pthread_attr_setstacksize
Expand Down Expand Up @@ -384,6 +389,9 @@ PyThread_get_thread_native_id(void)
#elif defined(__FreeBSD__)
int native_id;
native_id = pthread_getthreadid_np();
#elif defined(__FreeBSD_kernel__)
long native_id;
syscall(SYS_thr_self, &native_id);
#elif defined(__OpenBSD__)
pid_t native_id;
native_id = getthrid();
Expand All @@ -396,6 +404,10 @@ PyThread_get_thread_native_id(void)
#elif defined(__DragonFly__)
lwpid_t native_id;
native_id = lwp_gettid();
#elif defined(__GNU__)
mach_port_t native_id;
native_id = mach_thread_self();
mach_port_deallocate(mach_task_self(), mach_thread_self());
#endif
return (unsigned long) native_id;
}
Expand Down

0 comments on commit f76ba6b

Please sign in to comment.