diff options
author | Victor Stinner <vstinner@python.org> | 2021-03-10 19:00:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-10 19:00:46 (GMT) |
commit | 87f649a409da9d99682e78a55a83fc43225a8729 (patch) | |
tree | ecba0910f42f93dd6aa107ce4506a55f66249ec2 /Python/pystate.c | |
parent | 9a9c11ad41d7887f3d6440e0f0e8966156d959b5 (diff) | |
download | cpython-87f649a409da9d99682e78a55a83fc43225a8729.zip cpython-87f649a409da9d99682e78a55a83fc43225a8729.tar.gz cpython-87f649a409da9d99682e78a55a83fc43225a8729.tar.bz2 |
bpo-43311: Create GIL autoTSSkey ealier (GH-24819)
At Python startup, call _PyGILState_Init() before
PyInterpreterState_New() which calls _PyThreadState_GET(). When
Python is built using --with-experimental-isolated-subinterpreters,
_PyThreadState_GET() uses autoTSSkey.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index e7c085d..c8b2530 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1327,7 +1327,21 @@ PyThreadState_IsCurrent(PyThreadState *tstate) Py_Initialize/Py_FinalizeEx */ PyStatus -_PyGILState_Init(PyThreadState *tstate) +_PyGILState_Init(_PyRuntimeState *runtime) +{ + struct _gilstate_runtime_state *gilstate = &runtime->gilstate; + if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) { + return _PyStatus_NO_MEMORY(); + } + // PyThreadState_New() calls _PyGILState_NoteThreadState() which does + // nothing before autoInterpreterState is set. + assert(gilstate->autoInterpreterState == NULL); + return _PyStatus_OK(); +} + + +PyStatus +_PyGILState_SetTstate(PyThreadState *tstate) { if (!_Py_IsMainInterpreter(tstate->interp)) { /* Currently, PyGILState is shared by all interpreters. The main @@ -1341,9 +1355,6 @@ _PyGILState_Init(PyThreadState *tstate) struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate; - if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) { - return _PyStatus_NO_MEMORY(); - } gilstate->autoInterpreterState = tstate->interp; assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL); assert(tstate->gilstate_counter == 0); |