From 27b60fafb8acacab21eda5a759615384d77177cb Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sun, 28 Mar 2004 16:59:56 +0000 Subject: [PATCH] Don't use PyThreadState_Swap to get the current tstate, block threads only if the current tstate is not the one expected. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26426 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/helpers.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index 81c954bc70..6bcefc228d 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -1059,15 +1059,14 @@ bool wxPyBeginBlockThreads() { // This works in for 2.3, maybe a good alternative to find the needed tstate? // PyThreadState *check = PyGILState_GetThisThreadState(); - // get the currect tstate by swapping in NULL and then putting it back. - PyThreadState *current = PyThreadState_Swap(NULL); - PyThreadState_Swap(current); + PyThreadState *current = _PyThreadState_Current; - // Only block if there wasn't alrady a tstate. This cen happen with - // nested calls to wxPyBeginBlockThreads + // Only block if there wasn't already a tstate, or if the current one is + // not the one we are wanting to change to. This should prevent deadlock + // if there are nested calls to wxPyBeginBlockThreads bool blocked = false; - if (current == NULL) { - wxPyThreadState* tstate = wxPyGetThreadState(); + wxPyThreadState* tstate = wxPyGetThreadState(); + if (current != tstate->tstate) { PyEval_RestoreThread(tstate->tstate); blocked = true; } -- 2.45.2