diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-13 17:42:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 17:42:56 (GMT) |
commit | c3a2cbb54d19e86f1ff402f7783d51610c2ff646 (patch) | |
tree | a79c6dc4c36c5383536224ff2e06fa5f90e1c6bb /Python | |
parent | 9c51ea5d550dbcf5568b57913b1b453d1f92fd5c (diff) | |
download | cpython-c3a2cbb54d19e86f1ff402f7783d51610c2ff646.zip cpython-c3a2cbb54d19e86f1ff402f7783d51610c2ff646.tar.gz cpython-c3a2cbb54d19e86f1ff402f7783d51610c2ff646.tar.bz2 |
[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 b97e14a806477af4225777d215ac38c0d9b845f0)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 95b39f4..c4e6b69 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; } |