Skip to content

Commit 7dc42b6

Browse files
authored
gh-137884: Added threading.get_native_id() on Illumos/Solaris (GH-137927)
1 parent 3143cee commit 7dc42b6

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

Doc/library/_thread.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,16 @@ This module defines the following constants and functions:
120120
Its value may be used to uniquely identify this particular thread system-wide
121121
(until the thread terminates, after which the value may be recycled by the OS).
122122

123-
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD.
123+
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.
124124

125125
.. versionadded:: 3.8
126126

127127
.. versionchanged:: 3.13
128128
Added support for GNU/kFreeBSD.
129129

130+
.. versionchanged:: next
131+
Added support for Solaris.
132+
130133

131134
.. function:: stack_size([size])
132135

Doc/library/threading.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ This module defines the following functions:
191191
Its value may be used to uniquely identify this particular thread system-wide
192192
(until the thread terminates, after which the value may be recycled by the OS).
193193

194-
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD.
194+
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.
195195

196196
.. versionadded:: 3.8
197197

198198
.. versionchanged:: 3.13
199199
Added support for GNU/kFreeBSD.
200200

201+
.. versionchanged:: next
202+
Added support for Solaris.
203+
201204

202205
.. function:: enumerate()
203206

Include/pythread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
4242
#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
4343
|| defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
4444
|| defined(__OpenBSD__) || defined(__NetBSD__) \
45-
|| defined(__DragonFly__) || defined(_AIX))
45+
|| defined(__DragonFly__) || defined(_AIX) \
46+
|| (defined(__sun__) && SIZEOF_LONG >= 8))
4647
#define PY_HAVE_THREAD_NATIVE_ID
4748
PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
4849
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :func:`threading.get_native_id` support for Illumos/Solaris. Patch by
2+
Yüce Tekol.

Python/thread_pthread.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
# include <lwp.h> /* _lwp_self() */
3131
#elif defined(__DragonFly__)
3232
# include <sys/lwp.h> /* lwp_gettid() */
33+
#elif defined(__sun__) && SIZEOF_LONG >= 8
34+
# include <thread.h>
3335
#endif
3436

3537
/* The POSIX spec requires that use of pthread_attr_setstacksize
@@ -399,6 +401,8 @@ PyThread_get_thread_native_id(void)
399401
#elif defined(__DragonFly__)
400402
lwpid_t native_id;
401403
native_id = lwp_gettid();
404+
#elif defined(__sun__) && SIZEOF_LONG >= 8
405+
unsigned long native_id = (unsigned long)getpid() << 32 | thr_self();
402406
#endif
403407
return (unsigned long) native_id;
404408
}

0 commit comments

Comments
 (0)