gh-137884: Added threading.get_native_id() on Illumos/Solaris (GH-137927)

This commit is contained in:
Yüce Tekol 2025-08-20 20:10:44 +03:00 committed by GitHub
parent 3143ceeb1d
commit 7dc42b67a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 3 deletions

View file

@ -120,13 +120,16 @@ This module defines the following constants and functions:
Its value may be used to uniquely identify this particular thread system-wide 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). (until the thread terminates, after which the value may be recycled by the OS).
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD. .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.
.. versionadded:: 3.8 .. versionadded:: 3.8
.. versionchanged:: 3.13 .. versionchanged:: 3.13
Added support for GNU/kFreeBSD. Added support for GNU/kFreeBSD.
.. versionchanged:: next
Added support for Solaris.
.. function:: stack_size([size]) .. function:: stack_size([size])

View file

@ -191,13 +191,16 @@ This module defines the following functions:
Its value may be used to uniquely identify this particular thread system-wide 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). (until the thread terminates, after which the value may be recycled by the OS).
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD. .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.
.. versionadded:: 3.8 .. versionadded:: 3.8
.. versionchanged:: 3.13 .. versionchanged:: 3.13
Added support for GNU/kFreeBSD. Added support for GNU/kFreeBSD.
.. versionchanged:: next
Added support for Solaris.
.. function:: enumerate() .. function:: enumerate()

View file

@ -42,7 +42,8 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \ #if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
|| defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|| defined(__OpenBSD__) || defined(__NetBSD__) \ || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(__DragonFly__) || defined(_AIX)) || defined(__DragonFly__) || defined(_AIX) \
|| (defined(__sun__) && SIZEOF_LONG >= 8))
#define PY_HAVE_THREAD_NATIVE_ID #define PY_HAVE_THREAD_NATIVE_ID
PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void); PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
#endif #endif

View file

@ -0,0 +1,2 @@
Add :func:`threading.get_native_id` support for Illumos/Solaris. Patch by
Yüce Tekol.

View file

@ -30,6 +30,8 @@
# include <lwp.h> /* _lwp_self() */ # include <lwp.h> /* _lwp_self() */
#elif defined(__DragonFly__) #elif defined(__DragonFly__)
# include <sys/lwp.h> /* lwp_gettid() */ # include <sys/lwp.h> /* lwp_gettid() */
#elif defined(__sun__) && SIZEOF_LONG >= 8
# include <thread.h>
#endif #endif
/* The POSIX spec requires that use of pthread_attr_setstacksize /* The POSIX spec requires that use of pthread_attr_setstacksize
@ -399,6 +401,8 @@ PyThread_get_thread_native_id(void)
#elif defined(__DragonFly__) #elif defined(__DragonFly__)
lwpid_t native_id; lwpid_t native_id;
native_id = lwp_gettid(); native_id = lwp_gettid();
#elif defined(__sun__) && SIZEOF_LONG >= 8
unsigned long native_id = (unsigned long)getpid() << 32 | thr_self();
#endif #endif
return (unsigned long) native_id; return (unsigned long) native_id;
} }