From 93b14e80262d796a9c618842de3456fa07a1357b Mon Sep 17 00:00:00 2001
From: Stefan Csomor <csomor@advancedconcepts.ch>
Date: Thu, 20 May 2004 15:21:52 +0000
Subject: [PATCH] a few corrections

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27364 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 src/mac/carbon/thread.cpp | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp
index fed5af4d81..8aebe3bde2 100644
--- a/src/mac/carbon/thread.cpp
+++ b/src/mac/carbon/thread.cpp
@@ -1121,7 +1121,15 @@ void wxThreadInternal::Wait()
     // if the thread we're waiting for is waiting for the GUI mutex, we will
     // deadlock so make sure we release it temporarily
     if ( wxThread::IsMain() )
-        wxMutexGuiLeave();
+    {
+        // give the thread we're waiting for chance to do the GUI call
+        // it might be in, we don't do this conditionally as the to be waited on 
+        // thread might have to acquire the mutex later but before terminating
+        if ( wxGuiOwnedByMainThread() )
+        {
+            wxMutexGuiLeave();
+        }
+    }
 
     {
         wxCriticalSectionLocker lock(m_csJoinFlag);
@@ -1150,10 +1158,6 @@ void wxThreadInternal::Wait()
             m_shouldBeJoined = FALSE;
         }
     }
-
-    // reacquire GUI mutex
-    if ( wxThread::IsMain() )
-        wxMutexGuiEnter();
 }
 
 void wxThreadInternal::Pause()
@@ -1197,7 +1201,7 @@ wxThread *wxThread::This()
 
 bool wxThread::IsMain()
 {
-	return GetCurrentId() == gs_idMainThread || gs_idMainThread == kNoThreadID;
+	return GetCurrentId() == gs_idMainThread || gs_idMainThread == kInvalidID ;
 }
 
 #ifdef Yield
@@ -1408,7 +1412,6 @@ wxThreadError wxThread::Delete(ExitCode *rc)
                     *rc = m_internal->GetExitCode();
                 }
             }
-            //else: can't wait for detached threads
     }
 
     return wxTHREAD_NO_ERROR;
-- 
2.47.2