8000 gh-59956: Clarify GILState-related Code by ericsnowcurrently · Pull Request #101161 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-59956: Clarify GILState-related Code #101161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move autoTSSkey out of _PyRuntimeState.gilstate.
  • Loading branch information
ericsnowcurrently committed Jan 19, 2023
commit 4af2ecbe2e2881d003ef59645271850230bc8d75
3 changes: 2 additions & 1 deletion Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct _gilstate_runtime_state {
*/
/* TODO: Given interp_main, it may be possible to kill this ref */
PyInterpreterState *autoInterpreterState;
Py_tss_t autoTSSkey;
};

/* Runtime audit hook state */
Expand Down Expand Up @@ -124,6 +123,8 @@ typedef struct pyruntimestate {
/* Assuming the current thread holds the GIL, this is the
PyThreadState for the current thread. */
_Py_atomic_address tstate_current;
/* Used for the thread state bound to the current thread. */
Py_tss_t autoTSSkey;

PyWideStringList orig_argv;

Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_runtime_init.h
10000
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ extern "C" {
until _PyInterpreterState_Enable() is called. */ \
.next_id = -1, \
}, \
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
in accordance with the specification. */ \
.autoTSSkey = Py_tss_NEEDS_INIT, \
.parser = _parser_runtime_state_INIT, \
.imports = { \
.lock = { \
Expand All @@ -49,9 +52,6 @@ extern "C" {
}, \
.gilstate = { \
.check_enabled = 1, \
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
in accordance with the specification. */ \
.autoTSSkey = Py_tss_NEEDS_INIT, \
}, \
.dtoa = _dtoa_runtime_state_INIT(runtime), \
.fileutils = { \
Expand Down
12 changes: 6 additions & 6 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ current_fast_clear(_PyRuntimeState *runtime)
static int
current_tss_initialized(_PyRuntimeState *runtime)
{
return PyThread_tss_is_created(&runtime->gilstate.autoTSSkey);
return PyThread_tss_is_created(&runtime->autoTSSkey);
}

static PyStatus
current_tss_init(_PyRuntimeState *runtime)
{
assert(!current_tss_initialized(runtime));
if (PyThread_tss_create(&runtime->gilstate.autoTSSkey) != 0) {
if (PyThread_tss_create(&runtime->autoTSSkey) != 0) {
return _PyStatus_NO_MEMORY();
}
return _PyStatus_OK();
Expand All @@ -87,22 +87,22 @@ static void
current_tss_fini(_PyRuntimeState *runtime)
{
assert(current_tss_initialized(runtime));
PyThread_tss_delete(&runtime->gilstate.autoTSSkey);
PyThread_tss_delete(&runtime->autoTSSkey);
}

static inline PyThreadState *
current_tss_get(_PyRuntimeState *runtime)
{
assert(current_tss_initialized(runtime));
return (PyThreadState *)PyThread_tss_get(&runtime->gilstate.autoTSSkey);
return (PyThreadState *)PyThread_tss_get(&runtime->autoTSSkey);
}

static inline int
_current_tss_set(_PyRuntimeState *runtime, PyThreadState *tstate)
{
assert(tstate != NULL);
assert(current_tss_initialized(runtime));
return PyThread_tss_set(&runtime->gilstate.autoTSSkey, (void *)tstate);
return PyThread_tss_set(&runtime->autoTSSkey, (void *)tstate);
}
static inline void
current_tss_set(_PyRuntimeState *runtime, PyThreadState *tstate)
Expand All @@ -116,7 +116,7 @@ static inline void
current_tss_clear(_PyRuntimeState *runtime)
{
assert(current_tss_initialized(runtime));
if (PyThread_tss_set(&runtime->gilstate.autoTSSkey, NULL) != 0) {
if (PyThread_tss_set(&runtime->autoTSSkey, NULL) != 0) {
Py_FatalError("failed to clear current tstate (TSS)");
}
}
Expand Down
0