8000 Move autoTSSkey out of _PyRuntimeState.gilstate. · python/cpython@4af2ecb · GitHub
[go: up one dir, main page]

Skip to content

Commit 4af2ecb

Browse files
Move autoTSSkey out of _PyRuntimeState.gilstate.
1 parent 2f8aaec commit 4af2ecb

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Include/internal/pycore_runtime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct _gilstate_runtime_state {
4646
*/
4747
/* TODO: Given interp_main, it may be possible to kill this ref */
4848
PyInterpreterState *autoInterpreterState;
49-
Py_tss_t autoTSSkey;
5049
};
5150

5251
/* Runtime audit hook state */
@@ -124,6 +123,8 @@ typedef struct pyruntimestate {
124123
/* Assuming the current thread holds the GIL, this is the
125124
PyThreadState for the current thread. */
126125
_Py_atomic_address tstate_current;
126+
/* Used for the thread state bound to the current thread. */
127+
Py_tss_t autoTSSkey;
127128

128129
PyWideStringList orig_argv;
129130

Include/internal/pycore_runtime_init.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ extern "C" {
3333
until _PyInterpreterState_Enable() is called. */ \
3434
.next_id = -1, \
3535
}, \
36+
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
37+
in accordance with the specification. */ \
38+
.autoTSSkey = Py_tss_NEEDS_INIT, \
3639
.parser = _parser_runtime_state_INIT, \
3740
.imports = { \
3841
.lock = { \
@@ -49,9 +52,6 @@ extern "C" {
4952
}, \
5053
.gilstate = { \
5154
.check_enabled = 1, \
52-
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
53-
in accordance with the specification. */ \
54-
.autoTSSkey = Py_tss_NEEDS_INIT, \
5555
}, \
5656
.dtoa = _dtoa_runtime_state_INIT(runtime), \
5757
.fileutils = { \

Python/pystate.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ current_fast_clear(_PyRuntimeState *runtime)
7070
static int
7171
current_tss_initialized(_PyRuntimeState *runtime)
7272
{
73-
return PyThread_tss_is_created(&runtime->gilstate.autoTSSkey);
73+
return PyThread_tss_is_created(&runtime->autoTSSkey);
7474
}
7575

7676
static PyStatus
7777
current_tss_init(_PyRuntimeState *runtime)
7878
{
7979
assert(!current_tss_initialized(runtime));
80-
if (PyThread_tss_create(&runtime->gilstate.autoTSSkey) != 0) {
80+
if (PyThread_tss_create(&runtime->autoTSSkey) != 0) {
8181
return _PyStatus_NO_MEMORY();
8282
}
8383
return _PyStatus_OK();
@@ -87,22 +87,22 @@ static void
8787
current_tss_fini(_PyRuntimeState *runtime)
8888
{
8989
assert(current_tss_initialized(runtime));
90-
PyThread_tss_delete(&runtime->gilstate.autoTSSkey);
90+
PyThread_tss_delete(&runtime->autoTSSkey);
9191
}
9292

9393
static inline PyThreadState *
9494
current_tss_get(_PyRuntimeState *runtime)
9595
{
9696
assert(current_tss_initialized(runtime));
97-
return (PyThreadState *)PyThread_tss_get(&runtime->gilstate.autoTSSkey);
97+
return (PyThreadState *)PyThread_tss_get(&runtime->autoTSSkey);
9898
}
9999

100100
static inline int
101101
_current_tss_set(_PyRuntimeState *runtime, PyThreadState *tstate)
102102
{
103103
assert(tstate != NULL);
104104
assert(current_tss_initialized(runtime));
105-
return PyThread_tss_set(&runtime->gilstate.autoTSSkey, (void *)tstate);
105+
return PyThread_tss_set(&runtime->autoTSSkey, (void *)tstate);
106106
}
107107
static inline void
108108
current_tss_set(_PyRuntimeState *runtime, PyThreadState *tstate)
@@ -116,7 +116,7 @@ static inline void
116116
current_tss_clear(_PyRuntimeState *runtime)
117117
{
118118
assert(current_tss_initialized(runtime));
119-
if (PyThread_tss_set(&runtime->gilstate.autoTSSkey, NULL) != 0) {
119+
if (PyThread_tss_set(&runtime->autoTSSkey, NULL) != 0) {
120120
Py_FatalError("failed to clear current tstate (TSS)");
121121
}
122122
}

0 commit comments

Comments
 (0)
0