summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2023-10-05 15:46:33 (GMT)
committerGitHub <noreply@github.com>2023-10-05 15:46:33 (GMT)
commit6e97a9647ae028facb392d12fc24973503693bd6 (patch)
treecce40bd0d1b8317652405f04c54541d48b3419e9 /Python/pylifecycle.c
parent9eb2489266c4c1f115b8f72c0728db737cc8a815 (diff)
downloadcpython-6e97a9647ae028facb392d12fc24973503693bd6.zip
cpython-6e97a9647ae028facb392d12fc24973503693bd6.tar.gz
cpython-6e97a9647ae028facb392d12fc24973503693bd6.tar.bz2
gh-109549: Add new states to PyThreadState to support PEP 703 (gh-109915)
This adds a new field 'state' to PyThreadState that can take on one of three values: _Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, or _Py_THREAD_GC. The "attached" and "detached" states correspond closely to acquiring and releasing the GIL. The "gc" state is current unused, but will be used to implement stop-the-world GC for --disable-gil builds in the near future.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index eb10aa3..1403316 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -661,8 +661,6 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return _PyStatus_ERR("can't make first thread");
}
_PyThreadState_Bind(tstate);
- // XXX For now we do this before the GIL is created.
- (void) _PyThreadState_SwapNoGIL(tstate);
status = init_interp_create_gil(tstate, config.gil);
if (_PyStatus_EXCEPTION(status)) {
@@ -2060,8 +2058,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
}
_PyThreadState_Bind(tstate);
- // XXX For now we do this before the GIL is created.
- PyThreadState *save_tstate = _PyThreadState_SwapNoGIL(tstate);
+ PyThreadState *save_tstate = _PyThreadState_GET();
int has_gil = 0;
/* From this point until the init_interp_create_gil() call,
@@ -2073,7 +2070,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
const PyConfig *src_config;
if (save_tstate != NULL) {
// XXX Might new_interpreter() have been called without the GIL held?
- _PyEval_ReleaseLock(save_tstate->interp, save_tstate);
+ _PyThreadState_Detach(save_tstate);
src_config = _PyInterpreterState_GetConfig(save_tstate->interp);
}
else
@@ -2120,12 +2117,11 @@ error:
*tstate_p = NULL;
/* Oops, it didn't work. Undo it all. */
- PyErr_PrintEx(0);
if (has_gil) {
- PyThreadState_Swap(save_tstate);
+ _PyThreadState_Detach(tstate);
}
- else {
- _PyThreadState_SwapNoGIL(save_tstate);
+ if (save_tstate != NULL) {
+ _PyThreadState_Attach(save_tstate);
}
PyThreadState_Clear(tstate);
PyThreadState_Delete(tstate);