summaryrefslogtreecommitdiffstats
path: root/Python/ceval_gil.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-01-19 23:04:14 (GMT)
committerGitHub <noreply@github.com>2023-01-19 23:04:14 (GMT)
commit6036c3e856f033bf13e929536e7bf127fdd921c9 (patch)
tree2e0f92c60f4d860826e6e224e6c073e220d76386 /Python/ceval_gil.c
parent8a2d4f4e8eea86352de37d2ce28117e13b3dfaed (diff)
downloadcpython-6036c3e856f033bf13e929536e7bf127fdd921c9.zip
cpython-6036c3e856f033bf13e929536e7bf127fdd921c9.tar.gz
cpython-6036c3e856f033bf13e929536e7bf127fdd921c9.tar.bz2
gh-59956: Clarify GILState-related Code (gh-101161)
The objective of this change is to help make the GILState-related code easier to understand. This mostly involves moving code around and some semantically equivalent refactors. However, there are a also a small number of slight changes in structure and behavior: * tstate_current is moved out of _PyRuntimeState.gilstate * autoTSSkey is moved out of _PyRuntimeState.gilstate * autoTSSkey is initialized earlier * autoTSSkey is re-initialized (after fork) earlier https://github.com/python/cpython/issues/59956
Diffstat (limited to 'Python/ceval_gil.c')
-rw-r--r--Python/ceval_gil.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index 83f4e91..73d412b 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -581,8 +581,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
take_gil(tstate);
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
- if (_PyThreadState_Swap(gilstate, tstate) != NULL) {
+ if (_PyThreadState_Swap(tstate->interp->runtime, tstate) != NULL) {
Py_FatalError("non-NULL old thread state");
}
}
@@ -593,7 +592,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
assert(is_tstate_valid(tstate));
_PyRuntimeState *runtime = tstate->interp->runtime;
- PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
+ PyThreadState *new_tstate = _PyThreadState_Swap(runtime, NULL);
if (new_tstate != tstate) {
Py_FatalError("wrong thread state");
}
@@ -643,7 +642,7 @@ PyThreadState *
PyEval_SaveThread(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
- PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
+ PyThreadState *tstate = _PyThreadState_Swap(runtime, NULL);
_Py_EnsureTstateNotNULL(tstate);
struct _ceval_runtime_state *ceval = &runtime->ceval;
@@ -660,8 +659,7 @@ PyEval_RestoreThread(PyThreadState *tstate)
take_gil(tstate);
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
- _PyThreadState_Swap(gilstate, tstate);
+ _PyThreadState_Swap(tstate->interp->runtime, tstate);
}
@@ -965,7 +963,7 @@ _Py_HandlePending(PyThreadState *tstate)
/* GIL drop request */
if (_Py_atomic_load_relaxed_int32(&interp_ceval_state->gil_drop_request)) {
/* Give another thread a chance */
- if (_PyThreadState_Swap(&runtime->gilstate, NULL) != tstate) {
+ if (_PyThreadState_Swap(runtime, NULL) != tstate) {
Py_FatalError("tstate mix-up");
}
drop_gil(ceval, interp_ceval_state, tstate);
@@ -974,7 +972,7 @@ _Py_HandlePending(PyThreadState *tstate)
take_gil(tstate);
- if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
+ if (_PyThreadState_Swap(runtime, tstate) != NULL) {
Py_FatalError("orphan tstate");
}
}