]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137884: Added threading.get_native_id() on Illumos/Solaris (GH-137927)
authorYüce Tekol <yucetekol@gmail.com>
Wed, 20 Aug 2025 17:10:44 +0000 (20:10 +0300)
committerGitHub <noreply@github.com>
Wed, 20 Aug 2025 17:10:44 +0000 (17:10 +0000)
Doc/library/_thread.rst
Doc/library/threading.rst
Include/pythread.h
Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst [new file with mode: 0644]
Python/thread_pthread.h

index ed29ac70035597cc6152235688adc2bec20f738e..1d00d05817eb6a31414d02f322b45da6eb0b9572 100644 (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
    (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
 
    .. versionchanged:: 3.13
       Added support for GNU/kFreeBSD.
 
+   .. versionchanged:: next
+      Added support for Solaris.
+
 
 .. function:: stack_size([size])
 
index cabb41442f8419648807bd79d35126045f92903b..9a0aeb7c1287eee09bd1571e80b4f5375234b18b 100644 (file)
@@ -191,13 +191,16 @@ 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, GNU/kFreeBSD.
+   .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.
 
    .. versionadded:: 3.8
 
    .. versionchanged:: 3.13
       Added support for GNU/kFreeBSD.
 
+   .. versionchanged:: next
+      Added support for Solaris.
+
 
 .. function:: enumerate()
 
index 82247daf8e0aa09b2dc8630a351d07357e173821..a8a28b8572acb6e538443b2415da3b9b2ad4a694 100644 (file)
@@ -42,7 +42,8 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
 #if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
      || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
      || defined(__OpenBSD__) || defined(__NetBSD__) \
-     || defined(__DragonFly__) || defined(_AIX))
+     || defined(__DragonFly__) || defined(_AIX) \
+     || (defined(__sun__) && SIZEOF_LONG >= 8))
 #define PY_HAVE_THREAD_NATIVE_ID
 PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
 #endif
diff --git a/Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst b/Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst
new file mode 100644 (file)
index 0000000..c28f62b
--- /dev/null
@@ -0,0 +1,2 @@
+Add :func:`threading.get_native_id` support for Illumos/Solaris. Patch by
+Yüce Tekol.
index 13992f95723866b2ea9b24b4930ceb7766c4fff7..8496f91db2eec2be62216dd87e389642abc9078f 100644 (file)
@@ -30,6 +30,8 @@
 #   include <lwp.h>             /* _lwp_self() */
 #elif defined(__DragonFly__)
 #   include <sys/lwp.h>         /* lwp_gettid() */
+#elif defined(__sun__) && SIZEOF_LONG >= 8
+#   include <thread.h>
 #endif
 
 /* The POSIX spec requires that use of pthread_attr_setstacksize
@@ -399,6 +401,8 @@ PyThread_get_thread_native_id(void)
 #elif defined(__DragonFly__)
     lwpid_t native_id;
     native_id = lwp_gettid();
+#elif defined(__sun__) && SIZEOF_LONG >= 8
+    unsigned long native_id = (unsigned long)getpid() << 32 | thr_self();
 #endif
     return (unsigned long) native_id;
 }