File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,8 @@ PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
239239#define Py_Is (x , y ) ((x) == (y))
240240
241241#if defined(Py_GIL_DISABLED ) && !defined(Py_LIMITED_API )
242+ PyAPI_FUNC (uintptr_t ) _Py_GetThreadLocal_Addr (void );
243+
242244static inline uintptr_t
243245_Py_ThreadId (void )
244246{
@@ -291,7 +293,9 @@ _Py_ThreadId(void)
291293 __asm__ ("mv %0, tp" : "=r" (tid ));
292294 #endif
293295#else
294- # error "define _Py_ThreadId for this platform"
296+ // Fallback to a portable implementation if we do not have a faster
297+ // platform-specific implementation.
298+ tid = _Py_GetThreadLocal_Addr ();
295299#endif
296300 return tid ;
297301}
Original file line number Diff line number Diff line change @@ -1951,6 +1951,20 @@ _PyThreadState_Bind(PyThreadState *tstate)
19511951 }
19521952}
19531953
1954+ #if defined(Py_GIL_DISABLED ) && !defined(Py_LIMITED_API )
1955+ uintptr_t
1956+ _Py_GetThreadLocal_Addr (void )
1957+ {
1958+ #ifdef HAVE_THREAD_LOCAL
1959+ // gh-112535: Use the address of the thread-local PyThreadState variable as
1960+ // a unique identifier for the current thread. Each thread has a unique
1961+ // _Py_tss_tstate variable with a unique address.
1962+ return (uintptr_t )& _Py_tss_tstate ;
1963+ #else
1964+ # error "no supported thread-local variable storage classifier"
1965+ #endif
1966+ }
1967+ #endif
19541968
19551969/***********************************/
19561970/* routines for advanced debuggers */
You can’t perform that action at this time.
0 commit comments