summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-06-13 17:08:32 (GMT)
committerGitHub <noreply@github.com>2023-06-13 17:08:32 (GMT)
commitb97e14a806477af4225777d215ac38c0d9b845f0 (patch)
tree35eb71251371258874274f6eb73ab09fe849b460 /Python
parentabfbab6415fb029e7dca19ecc8d29a13da37bf71 (diff)
downloadcpython-b97e14a806477af4225777d215ac38c0d9b845f0.zip
cpython-b97e14a806477af4225777d215ac38c0d9b845f0.tar.gz
cpython-b97e14a806477af4225777d215ac38c0d9b845f0.tar.bz2
gh-105603: Change the PyInterpreterConfig.own gil Field (gh-105620)
We are changing it to be more flexible that a strict bool can be for possible future expanded used cases.
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 9ac5630..9ae03d4 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -578,12 +578,14 @@ init_interp_settings(PyInterpreterState *interp,
interp->feature_flags |= Py_RTFLAGS_MULTI_INTERP_EXTENSIONS;
}
+ /* We check "gil" in init_interp_create_gil(). */
+
return _PyStatus_OK();
}
static PyStatus
-init_interp_create_gil(PyThreadState *tstate, int own_gil)
+init_interp_create_gil(PyThreadState *tstate, int gil)
{
PyStatus status;
@@ -598,6 +600,15 @@ init_interp_create_gil(PyThreadState *tstate, int own_gil)
return status;
}
+ int own_gil;
+ switch (gil) {
+ case PyInterpreterConfig_DEFAULT_GIL: own_gil = 0; break;
+ case PyInterpreterConfig_SHARED_GIL: own_gil = 0; break;
+ case PyInterpreterConfig_OWN_GIL: own_gil = 1; break;
+ default:
+ return _PyStatus_ERR("invalid interpreter config 'gil' value");
+ }
+
/* Create the GIL and take it */
status = _PyEval_InitGIL(tstate, own_gil);
if (_PyStatus_EXCEPTION(status)) {
@@ -633,7 +644,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
// The main interpreter always has its own GIL.
- config.own_gil = 1;
+ config.gil = PyInterpreterConfig_OWN_GIL;
status = init_interp_settings(interp, &config);
if (_PyStatus_EXCEPTION(status)) {
return status;
@@ -647,7 +658,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
// XXX For now we do this before the GIL is created.
(void) _PyThreadState_SwapNoGIL(tstate);
- status = init_interp_create_gil(tstate, config.own_gil);
+ status = init_interp_create_gil(tstate, config.gil);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
@@ -2057,7 +2068,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
goto error;
}
- status = init_interp_create_gil(tstate, config->own_gil);
+ status = init_interp_create_gil(tstate, config->gil);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}