X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/918dc51991e5eaa5608d38cd8b7b3d251244d92b..654070ca23598b8d6d444befcc4c2bbe786586a0:/src/msw/thread.cpp diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 7c5a377d5e..576f756780 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -26,11 +26,14 @@ #endif #ifndef WX_PRECOMP -# include "wx/wx.h" + #include "wx/intl.h" + #include "wx/app.h" #endif #if wxUSE_THREADS +#include "wx/apptrait.h" + #include "wx/msw/private.h" #include "wx/msw/missing.h" @@ -629,6 +632,9 @@ void wxThreadInternal::SetPriority(unsigned int priority) bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) { + wxASSERT_MSG( m_state == STATE_NEW && !m_hThread, + _T("Create()ing thread twice?") ); + // for compilers which have it, we should use C RTL function for thread // creation instead of Win32 API one because otherwise we will have memory // leaks if the thread uses C RTL (and most threads do) @@ -997,10 +1003,11 @@ wxThreadError wxThread::Delete(ExitCode *pRc) m_internal->Cancel(); } -#if wxUSE_GUI // we can't just wait for the thread to terminate because it might be // calling some GUI functions and so it will never terminate before we // process the Windows messages that result from these functions + // (note that even in console applications we might have to process + // messages if we use wxExecute() or timers or ...) DWORD result = 0; // suppress warnings from broken compilers do { @@ -1038,12 +1045,17 @@ wxThreadError wxThread::Delete(ExitCode *pRc) case WAIT_OBJECT_0 + 1: // new message arrived, process it - if ( !wxTheApp->DoMessage() ) { - // WM_QUIT received: kill the thread - Kill(); + wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() + : NULL; + + if ( traits && !traits->DoMessageFromThreadWait() ) + { + // WM_QUIT received: kill the thread + Kill(); - return wxTHREAD_KILLED; + return wxTHREAD_KILLED; + } } break; @@ -1051,16 +1063,6 @@ wxThreadError wxThread::Delete(ExitCode *pRc) wxFAIL_MSG(wxT("unexpected result of MsgWaitForMultipleObject")); } } while ( result != WAIT_OBJECT_0 ); -#else // !wxUSE_GUI - // simply wait for the thread to terminate - // - // OTOH, even console apps create windows (in wxExecute, for WinSock - // &c), so may be use MsgWaitForMultipleObject() too here? - if ( WaitForSingleObject(hThread, INFINITE) != WAIT_OBJECT_0 ) - { - wxFAIL_MSG(wxT("unexpected result of WaitForSingleObject")); - } -#endif // wxUSE_GUI/!wxUSE_GUI if ( IsMain() ) { @@ -1265,7 +1267,7 @@ void wxThreadModule::OnExit() // not a mutex, so the names are a bit confusing // ---------------------------------------------------------------------------- -void WXDLLEXPORT wxMutexGuiEnter() +void WXDLLIMPEXP_BASE wxMutexGuiEnter() { // this would dead lock everything... wxASSERT_MSG( !wxThread::IsMain(), @@ -1287,7 +1289,7 @@ void WXDLLEXPORT wxMutexGuiEnter() gs_critsectGui->Enter(); } -void WXDLLEXPORT wxMutexGuiLeave() +void WXDLLIMPEXP_BASE wxMutexGuiLeave() { wxCriticalSectionLocker enter(*gs_critsectWaitingForGui); @@ -1309,7 +1311,7 @@ void WXDLLEXPORT wxMutexGuiLeave() gs_critsectGui->Leave(); } -void WXDLLEXPORT wxMutexGuiLeaveOrEnter() +void WXDLLIMPEXP_BASE wxMutexGuiLeaveOrEnter() { wxASSERT_MSG( wxThread::IsMain(), wxT("only main thread may call wxMutexGuiLeaveOrEnter()!") ); @@ -1339,13 +1341,13 @@ void WXDLLEXPORT wxMutexGuiLeaveOrEnter() } } -bool WXDLLEXPORT wxGuiOwnedByMainThread() +bool WXDLLIMPEXP_BASE wxGuiOwnedByMainThread() { return gs_bGuiOwnedByMainThread; } // wake up the main thread if it's in ::GetMessage() -void WXDLLEXPORT wxWakeUpMainThread() +void WXDLLIMPEXP_BASE wxWakeUpMainThread() { // sending any message would do - hopefully WM_NULL is harmless enough if ( !::PostThreadMessage(gs_idMainThread, WM_NULL, 0, 0) ) @@ -1355,7 +1357,7 @@ void WXDLLEXPORT wxWakeUpMainThread() } } -bool WXDLLEXPORT wxIsWaitingForThread() +bool WXDLLIMPEXP_BASE wxIsWaitingForThread() { return gs_waitingForThread; }