summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-04-25 03:09:35 (GMT)
committerGitHub <noreply@github.com>2023-04-25 03:09:35 (GMT)
commitd8627999d85cc5b000dbe17180250d919f8510ad (patch)
tree82620a3dd5103dfc93ea8684934a1e0e23f3b3ab /Python/pystate.c
parentb934f97850b7b2db30fa2b26720d58aac4783149 (diff)
downloadcpython-d8627999d85cc5b000dbe17180250d919f8510ad.zip
cpython-d8627999d85cc5b000dbe17180250d919f8510ad.tar.gz
cpython-d8627999d85cc5b000dbe17180250d919f8510ad.tar.bz2
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.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index b2ef7e2..ffab301 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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++) {