mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
[3.12] gh-105603: Change the PyInterpreterConfig.own gil Field (gh-105620) (gh-105731)
We are changing it to be more flexible that a strict bool can be for possible future expanded used cases.
(cherry picked from commit b97e14a806
)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
parent
9c51ea5d55
commit
c3a2cbb54d
6 changed files with 40 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue