]> git.saurik.com Git - wxWidgets.git/commitdiff
don't wake up on Windows messages when waiting for thread termination in a console...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 2 Feb 2007 22:46:48 +0000 (22:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 2 Feb 2007 22:46:48 +0000 (22:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44344 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/apptbase.h
include/wx/msw/apptrait.h
src/msw/app.cpp
src/msw/basemsw.cpp
src/msw/thread.cpp

index e472d53b51d1d7acde31f63ba07b1140db794b5c..40eb25ebada995679e934610e47b7166ef9e209f 100644 (file)
@@ -29,6 +29,9 @@ wxGTK:
 
 - Implemented support for underlined fonts in wxStaticText
 
+wxMSW:
+
+- Fixed infinite loop in wxThread::Wait() in console applications
 
 
 2.8.2
index d9c7e9d8eae909dca7066adc0c1229452352e1cf..f08f50d1484c72f6d4b0dcc66bdc23685b8f5c9b 100644 (file)
@@ -40,6 +40,9 @@ public:
     // process a message while waiting for a(nother) thread, should return
     // false if and only if we have to exit the application
     virtual bool DoMessageFromThreadWait() = 0;
+
+    // wait for the handle to be signaled
+    virtual WXDWORD WaitForThread(WXHANDLE hThread) = 0;
 };
 
 #endif // _WX_MSW_APPTBASE_H_
index 5d3e733ef315a5f624d76d276e581cf30d6533c3..7b7971a57876c45def4ab2179669067c67876470 100644 (file)
@@ -24,6 +24,7 @@ public:
     virtual void AfterChildWaitLoop(void *data);
 
     virtual bool DoMessageFromThreadWait();
+    virtual WXDWORD WaitForThread(WXHANDLE hThread);
 };
 
 #if wxUSE_GUI
@@ -37,6 +38,7 @@ public:
 
     virtual bool DoMessageFromThreadWait();
     virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
+    virtual WXDWORD WaitForThread(WXHANDLE hThread);
 };
 
 #endif // wxUSE_GUI
index d6fc28e3902d0bfb4de93ad708b40f1cc9b48278..1554e8637ed06c0fa29b069fc1cf1aff05ca7617 100644 (file)
@@ -225,6 +225,19 @@ bool wxGUIAppTraits::DoMessageFromThreadWait()
     return evtLoop->Dispatch();
 }
 
+DWORD wxGUIAppTraits::WaitForThread(WXHANDLE hThread)
+{
+    return ::MsgWaitForMultipleObjects
+             (
+               1,                   // number of objects to wait for
+               (HANDLE *)&hThread,  // the objects
+               false,               // wait for any objects, not all
+               INFINITE,            // no timeout
+               QS_ALLINPUT |        // return as soon as there are any events
+               QS_ALLPOSTMESSAGE
+             );
+}
+
 wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const
 {
     OSVERSIONINFO info;
index 033d3a76b2a5051d559f74acbcf214aea7b5a58a..8ec6130a51f488f8ae6de9a3cc62e3faeafc0a74 100644 (file)
@@ -71,3 +71,8 @@ bool wxConsoleAppTraits::DoMessageFromThreadWait()
     return true;
 }
 
+WXDWORD wxConsoleAppTraits::WaitForThread(WXHANDLE hThread)
+{
+    return ::WaitForSingleObject((HANDLE)hThread, INFINITE);
+}
+
index ee7fec670d7dc528a62ed77011bcc87b246122db..1aebef47565dddbf212cdbce532fbf7c45ce9327 100644 (file)
@@ -755,15 +755,16 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs,
 #if !defined(QS_ALLPOSTMESSAGE)
 #define QS_ALLPOSTMESSAGE 0
 #endif
-
-        result = ::MsgWaitForMultipleObjects
-                 (
-                   1,              // number of objects to wait for
-                   &m_hThread,     // the objects
-                   false,          // don't wait for all objects
-                   INFINITE,       // no timeout
-                   QS_ALLINPUT|QS_ALLPOSTMESSAGE   // return as soon as there are any events
-                 );
+        wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
+        if ( traits )
+        {
+            result = traits->WaitForThread(m_hThread);
+        }
+        else // can't wait for the thread
+        {
+            // so kill it below
+            result = 0xFFFFFFFF;
+        }
 
         switch ( result )
         {
@@ -788,9 +789,6 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs,
                 //     the system might dead lock then
                 if ( wxThread::IsMain() )
                 {
-                    wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits()
-                                                   : NULL;
-
                     if ( traits && !traits->DoMessageFromThreadWait() )
                     {
                         // WM_QUIT received: kill the thread