gh-100227: Add a Granular Lock for _PyRuntime.imports.extensions.dict (gh-103460)

The lock is unnecessary as long as there's a GIL, but completely
necessary with a per-interpreter GIL.
This commit is contained in:
Eric Snow 2023-04-24 21:09:35 -06:00 committed by GitHub
parent b934f97850
commit d8627999d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -380,7 +380,7 @@ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
static const _PyRuntimeState initial = _PyRuntimeState_INIT(_PyRuntime);
_Py_COMP_DIAG_POP
#define NUMLOCKS 4
#define NUMLOCKS 5
static int
alloc_for_runtime(PyThread_type_lock locks[NUMLOCKS])
@ -434,6 +434,7 @@ init_runtime(_PyRuntimeState *runtime,
&runtime->xidregistry.mutex,
&runtime->getargs.mutex,
&runtime->unicode_state.ids.lock,
&runtime->imports.extensions.mutex,
};
for (int i = 0; i < NUMLOCKS; i++) {
assert(locks[i] != NULL);
@ -518,6 +519,7 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime)
&runtime->xidregistry.mutex,
&runtime->getargs.mutex,
&runtime->unicode_state.ids.lock,
&runtime->imports.extensions.mutex,
};
for (int i = 0; i < NUMLOCKS; i++) {
FREE_LOCK(*lockptrs[i]);
@ -546,6 +548,7 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
&runtime->xidregistry.mutex,
&runtime->getargs.mutex,
&runtime->unicode_state.ids.lock,
&runtime->imports.extensions.mutex,
};
int reinit_err = 0;
for (int i = 0; i < NUMLOCKS; i++) {