From 0802fd6c8ee0cacb3ab555dd86e235a5dfab7618 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 9 Nov 2023 21:02:30 +0100 Subject: [PATCH] gh-81925: Implement native thread ids for kFreeBSD (#111761) --------- Co-authored-by: Antoine Pitrou --- Doc/library/_thread.rst | 5 ++++- Doc/library/threading.rst | 5 ++++- Doc/tools/extensions/pyspecific.py | 4 ++-- Include/pythread.h | 3 ++- .../2023-11-05-20-59-10.gh-issue-81925.wKHLSS.rst | 1 + Python/thread_pthread.h | 5 +++++ 6 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-11-05-20-59-10.gh-issue-81925.wKHLSS.rst diff --git a/Doc/library/_thread.rst b/Doc/library/_thread.rst index d7c61c3d7ef..297f50a46e0 100644 --- a/Doc/library/_thread.rst +++ b/Doc/library/_thread.rst @@ -120,10 +120,13 @@ This module defines the following constants and functions: Its value may be used to uniquely identify this particular thread system-wide (until the thread terminates, after which the value may be recycled by the OS). - .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD. + .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD. .. versionadded:: 3.8 + .. versionchanged:: 3.13 + Added support for GNU/kFreeBSD. + .. function:: stack_size([size]) diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst index 23d8cd158ab..b85b7f008d1 100644 --- a/Doc/library/threading.rst +++ b/Doc/library/threading.rst @@ -127,10 +127,13 @@ This module defines the following functions: Its value may be used to uniquely identify this particular thread system-wide (until the thread terminates, after which the value may be recycled by the OS). - .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD. + .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD. .. versionadded:: 3.8 + .. versionchanged:: 3.13 + Added support for GNU/kFreeBSD. + .. function:: enumerate() diff --git a/Doc/tools/extensions/pyspecific.py b/Doc/tools/extensions/pyspecific.py index 11d954adaec..31c2544caf6 100644 --- a/Doc/tools/extensions/pyspecific.py +++ b/Doc/tools/extensions/pyspecific.py @@ -127,8 +127,8 @@ class Availability(SphinxDirective): # known platform, libc, and threading implementations known_platforms = frozenset({ "AIX", "Android", "BSD", "DragonFlyBSD", "Emscripten", "FreeBSD", - "Linux", "NetBSD", "OpenBSD", "POSIX", "Solaris", "Unix", "VxWorks", - "WASI", "Windows", "macOS", + "GNU/kFreeBSD", "Linux", "NetBSD", "OpenBSD", "POSIX", "Solaris", + "Unix", "VxWorks", "WASI", "Windows", "macOS", # libc "BSD libc", "glibc", "musl", # POSIX platforms with pthreads diff --git a/Include/pythread.h b/Include/pythread.h index 0784f6b2e53..a3216c51d66 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -21,7 +21,8 @@ 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(__FreeBSD__) || defined(__FreeBSD_kernel__) \ + || defined(__OpenBSD__) || defined(__NetBSD__) \ || defined(__DragonFly__) || defined(_AIX)) #define PY_HAVE_THREAD_NATIVE_ID PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void); diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-11-05-20-59-10.gh-issue-81925.wKHLSS.rst b/Misc/NEWS.d/next/Core and Builtins/2023-11-05-20-59-10.gh-issue-81925.wKHLSS.rst new file mode 100644 index 00000000000..9caa5cf6abe --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-11-05-20-59-10.gh-issue-81925.wKHLSS.rst @@ -0,0 +1 @@ +Implement native thread ids for GNU KFreeBSD. diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index a8df5449714..fb3b79fc160 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -20,6 +20,8 @@ # include /* syscall(SYS_gettid) */ #elif defined(__FreeBSD__) # include /* pthread_getthreadid_np() */ +#elif defined(__FreeBSD_kernel__) +# include /* syscall(SYS_thr_self) */ #elif defined(__OpenBSD__) # include /* getthrid() */ #elif defined(_AIX) @@ -384,6 +386,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();