File tree 3 files changed +13
-8
lines changed
3 files changed +13
-8
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_TSS_Tstate_Addr (void );
243
+
242
244
static inline uintptr_t
243
245
_Py_ThreadId (void )
244
246
{
@@ -291,18 +293,12 @@ _Py_ThreadId(void)
291
293
__asm__ ("mv %0, tp" : "=r" (tid ));
292
294
#endif
293
295
#elif defined(thread_local ) || defined(__GNUC__ )
294
- #if defined(thread_local )
295
- static thread_local int __tp = 0 ;
296
- #else
297
- // Assume that we only support C11 compilers.
298
- static __thread int __tp = 0 ;
299
- #endif
300
296
// gh-112535: Using characteristics of TLS address mapping.
301
297
// The address of the thread-local variable is not equal with the actual thread pointer,
302
298
// However, it has the property of being determined by loader at runtime, with no duplication of values
303
299
// between different threads. So it can be used as the similar role of __builtin_thread_pointer().
304
300
// But since it requires offset calculation, this hack is more expensive than __builtin_thread_pointer().
305
- tid = ( uintptr_t ) & __tp ;
301
+ tid = _Py_TSS_Tstate_Addr () ;
306
302
#else
307
303
# error "define _Py_ThreadId for this platform"
308
304
#endif
Original file line number Diff line number Diff line change @@ -119,7 +119,6 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
119
119
*/
120
120
PyAPI_FUNC (PyThreadState * ) PyGILState_GetThisThreadState (void );
121
121
122
-
123
122
#ifndef Py_LIMITED_API
124
123
# define Py_CPYTHON_PYSTATE_H
125
124
# include "cpython/pystate.h"
Original file line number Diff line number Diff line change @@ -1951,6 +1951,16 @@ _PyThreadState_Bind(PyThreadState *tstate)
1951
1951
}
1952
1952
}
1953
1953
1954
+ #if defined(Py_GIL_DISABLED )
1955
+ uintptr_t
1956
+ _Py_TSS_Tstate_Addr (void ) {
1957
+ #ifdef HAVE_THREAD_LOCAL
1958
+ return (uintptr_t )& _Py_tss_tstate ;
1959
+ #else
1960
+ # error "no supported thread-local variable storage classifier"
1961
+ #endif
1962
+ }
1963
+ #endif
1954
1964
1955
1965
/***********************************/
1956
1966
/* routines for advanced debuggers */
You can’t perform that action at this time.
0 commit comments