summaryrefslogtreecommitdiff
path: root/Python/pystate.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 75bd9f41e3..f14934361d 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1863,17 +1863,11 @@ PyThreadState_Get(void)
}
-PyThreadState *
-_PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
+static void
+_swap_thread_states(_PyRuntimeState *runtime,
+ PyThreadState *oldts, PyThreadState *newts)
{
-#if defined(Py_DEBUG)
- /* This can be called from PyEval_RestoreThread(). Similar
- to it, we need to ensure errno doesn't change.
- */
- int err = errno;
-#endif
- PyThreadState *oldts = current_fast_get(runtime);
-
+ // XXX Do this only if oldts != NULL?
current_fast_clear(runtime);
if (oldts != NULL) {
@@ -1887,6 +1881,20 @@ _PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
current_fast_set(runtime, newts);
tstate_activate(newts);
}
+}
+
+PyThreadState *
+_PyThreadState_SwapNoGIL(PyThreadState *newts)
+{
+#if defined(Py_DEBUG)
+ /* This can be called from PyEval_RestoreThread(). Similar
+ to it, we need to ensure errno doesn't change.
+ */
+ int err = errno;
+#endif
+
+ PyThreadState *oldts = current_fast_get(&_PyRuntime);
+ _swap_thread_states(&_PyRuntime, oldts, newts);
#if defined(Py_DEBUG)
errno = err;
@@ -1895,6 +1903,20 @@ _PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
}
PyThreadState *
+_PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
+{
+ PyThreadState *oldts = current_fast_get(runtime);
+ if (oldts != NULL) {
+ _PyEval_ReleaseLock(oldts);
+ }
+ _swap_thread_states(runtime, oldts, newts);
+ if (newts != NULL) {
+ _PyEval_AcquireLock(newts);
+ }
+ return oldts;
+}
+
+PyThreadState *
PyThreadState_Swap(PyThreadState *newts)
{
return _PyThreadState_Swap(&_PyRuntime, newts);