File tree 2 files changed +19
-1
lines changed
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);
239
239
#define Py_Is (x , y ) ((x) == (y))
240
240
241
241
#if defined(Py_GIL_DISABLED ) && !defined(Py_LIMITED_API )
242
+ PyAPI_FUNC (uintptr_t ) _Py_GetThreadLocal_Addr (void );
243
+
242
244
static inline uintptr_t
243
245
_Py_ThreadId (void )
244
246
{
@@ -291,7 +293,9 @@ _Py_ThreadId(void)
291
293
__asm__ ("mv %0, tp" : "=r" (tid ));
292
294
#endif
293
295
#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 ();
295
299
#endif
296
300
return tid ;
297
301
}
Original file line number Diff line number Diff line change @@ -1951,6 +1951,20 @@ _PyThreadState_Bind(PyThreadState *tstate)
1951
1951
}
1952
1952
}
1953
1953
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
1954
1968
1955
1969
/***********************************/
1956
1970
/* routines for advanced debuggers */
You can’t perform that action at this time.
0 commit comments