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.
This commit is contained in:
Eric Snow 2023-06-13 11:08:32 -06:00 committed by GitHub
parent abfbab6415
commit b97e14a806
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 16 deletions

View file

@ -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;
}