@@ -61,38 +61,55 @@ extern "C" {
61
61
*/
62
62
63
63
64
- thread_local PyThreadState * _Py_tss_tstate = NULL ;
65
-
66
- PyThreadState *
67
- _PyThreadState_GetCurrent (void )
68
- {
69
- return _Py_tss_tstate ;
70
- }
64
+ #ifdef HAVE_THREAD_LOCAL
65
+ _Py_thread_local PyThreadState * _Py_tss_tstate = NULL ;
66
+ #endif
71
67
72
68
static inline PyThreadState *
73
69
current_fast_get (_PyRuntimeState * Py_UNUSED (runtime ))
74
70
{
71
+ #ifdef HAVE_THREAD_LOCAL
75
72
return _Py_tss_tstate ;
73
+ #else
74
+ // XXX Fall back to the PyThread_tss_*() API.
75
+ # error "no supported thread-local variable storage classifier"
76
+ #endif
76
77
}
77
78
78
79
static inline void
79
80
current_fast_set (_PyRuntimeState * Py_UNUSED (runtime ), PyThreadState * tstate )
80
81
{
81
82
assert (tstate != NULL );
83
+ #ifdef HAVE_THREAD_LOCAL
82
84
_Py_tss_tstate = tstate ;
85
+ #else
86
+ // XXX Fall back to the PyThread_tss_*() API.
87
+ # error "no supported thread-local variable storage classifier"
88
+ #endif
83
89
}
84
90
85
91
static inline void
86
92
current_fast_clear (_PyRuntimeState * Py_UNUSED (runtime ))
87
93
{
94
+ #ifdef HAVE_THREAD_LOCAL
88
95
_Py_tss_tstate = NULL ;
96
+ #else
97
+ // XXX Fall back to the PyThread_tss_*() API.
98
+ # error "no supported thread-local variable storage classifier"
99
+ #endif
89
100
}
90
101
91
102
#define tstate_verify_not_active (tstate ) \
92
103
if (tstate == current_fast_get((tstate)->interp->runtime)) { \
93
104
_Py_FatalErrorFormat(__func__, "tstate %p is still current", tstate); \
94
105
}
95
106
107
+ PyThreadState *
108
+ _PyThreadState_GetCurrent (void )
109
+ {
110
+ return current_fast_get (& _PyRuntime );
111
+ }
112
+
96
113
97
114
//------------------------------------------------
98
115
// the thread state bound to the current OS thread
0 commit comments