summaryrefslogtreecommitdiffstats
path: root/Python/ceval_gil.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-05 18:27:47 (GMT)
committerGitHub <noreply@github.com>2020-05-05 18:27:47 (GMT)
commit7be4e350aadf93c4be5c97b7291d0db2b6bc1dc4 (patch)
tree7285b6051ef96253ce4ef2ac2a34412fae9ea281 /Python/ceval_gil.h
parent0dd5e7a718997da2026ed64fe054dc36cae4fee7 (diff)
downloadcpython-7be4e350aadf93c4be5c97b7291d0db2b6bc1dc4.zip
cpython-7be4e350aadf93c4be5c97b7291d0db2b6bc1dc4.tar.gz
cpython-7be4e350aadf93c4be5c97b7291d0db2b6bc1dc4.tar.bz2
bpo-40513: Per-interpreter GIL (GH-19943)
In the experimental isolated subinterpreters build mode, the GIL is now per-interpreter. Move gil from _PyRuntimeState.ceval to PyInterpreterState.ceval. new_interpreter() always get the config from the main interpreter.
Diffstat (limited to 'Python/ceval_gil.h')
-rw-r--r--Python/ceval_gil.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h
index f25f810..56944b8 100644
--- a/Python/ceval_gil.h
+++ b/Python/ceval_gil.h
@@ -144,7 +144,11 @@ static void
drop_gil(struct _ceval_runtime_state *ceval, struct _ceval_state *ceval2,
PyThreadState *tstate)
{
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &ceval2->gil;
+#else
struct _gil_runtime_state *gil = &ceval->gil;
+#endif
if (!_Py_atomic_load_relaxed(&gil->locked)) {
Py_FatalError("drop_gil: GIL is not locked");
}
@@ -228,7 +232,11 @@ take_gil(PyThreadState *tstate)
PyInterpreterState *interp = tstate->interp;
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
struct _ceval_state *ceval2 = &interp->ceval;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &ceval2->gil;
+#else
struct _gil_runtime_state *gil = &ceval->gil;
+#endif
/* Check that _PyEval_InitThreads() was called to create the lock */
assert(gil_created(gil));
@@ -320,10 +328,22 @@ _ready:
void _PyEval_SetSwitchInterval(unsigned long microseconds)
{
- _PyRuntime.ceval.gil.interval = microseconds;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ struct _gil_runtime_state *gil = &interp->ceval.gil;
+#else
+ struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
+#endif
+ gil->interval = microseconds;
}
unsigned long _PyEval_GetSwitchInterval()
{
- return _PyRuntime.ceval.gil.interval;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ struct _gil_runtime_state *gil = &interp->ceval.gil;
+#else
+ struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
+#endif
+ return gil->interval;
}