8000 Move tstate_current out of _PyRuntimeState.gilstate. · python/cpython@6281edb · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6281edb

Browse files
Move tstate_current out of _PyRuntimeState.gilstate.
1 parent a5eb3d8 commit 6281edb

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

Include/internal/pycore_pystate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ _Py_ThreadCanHandlePendingCalls(void)
6767
static inline PyThreadState*
6868
_PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
6969
{
70-
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->gilstate.tstate_current);
70+
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->tstate_current);
7171
}
7272

7373
/* Get the current Python thread state.
7474
75-
Efficient macro reading directly the 'gilstate.tstate_current' atomic
75+
Efficient macro reading directly the 'tstate_current' atomic
7676
variable. The macro is unsafe: it does not check for error and it can
7777
return NULL.
7878

Include/internal/pycore_runtime.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ struct _gilstate_runtime_state {
4141
/* bpo-26558: Flag to disable PyGILState_Check().
4242
If set to non-zero, PyGILState_Check() always return 1. */
4343
int check_enabled;
44-
/* Assuming the current thread holds the GIL, this is the
45-
PyThreadState for the current thread. */
46-
_Py_atomic_address tstate_current;
4744
/* The single PyInterpreterState used by this process'
4845
GILState implementation
4946
*/
@@ -124,6 +121,10 @@ typedef struct pyruntimestate {
124121

125122
unsigned long main_thread;
126123

124+
/* Assuming the current thread holds the GIL, this is the
125+
PyThreadState for the current thread. */
126+
_Py_atomic_address tstate_current;
127+
127128
PyWideStringList orig_argv;
128129

129130
struct _parser_runtime_state parser;

Python/pystate.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,22 @@ static inline PyThreadState *
4848
current_fast_get(_PyRuntimeState *runtime)
4949
{
5050
// The GIL must be held by the current thread.
51-
return (PyThreadState*)_Py_atomic_load_relaxed(
52-
&runtime->gilstate.tstate_current);
51+
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->tstate_current);
5352
}
5453

5554
static inline void
5655
current_fast_set(_PyRuntimeState *runtime, PyThreadState *tstate)
5756
{
5857
// The GIL must be held by the current thread.
5958
assert(tstate != NULL);
60-
_Py_atomic_store_relaxed(&runtime->gilstate.tstate_current,
61-
(uintptr_t)tstate);
59+
_Py_atomic_store_relaxed(&runtime->tstate_current, (uintptr_t)tstate);
6260
}
6361

6462
static inline void
6563
current_fast_clear(_PyRuntimeState *runtime)
6664
{
6765
// The GIL must be held by the current thread.
68-
_Py_atomic_store_relaxed(&runtime->gilstate.tstate_current,
69-
(uintptr_t)NULL);
66+
_Py_atomic_store_relaxed(&runtime->tstate_current, (uintptr_t)NULL);
7067
}
7168

7269

0 commit comments

Comments
 (0)
0