X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40f359cafed30dedf8d2dc7ff2c9b16fcc9bebdf..153ecbb81caab1febc1916f5ec76b29ba09d2632:/src/msw/thread.cpp?ds=sidebyside diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 92f34c9ca8..195a2de6c7 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -26,11 +26,12 @@ #endif #ifndef WX_PRECOMP -# include "wx/wx.h" #endif #if wxUSE_THREADS +#include "wx/apptrait.h" + #include "wx/msw/private.h" #include "wx/msw/missing.h" @@ -629,6 +630,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) @@ -674,8 +678,6 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize) SetPriority(m_priority); } - m_state = STATE_NEW; - return TRUE; } @@ -999,10 +1001,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 { @@ -1040,12 +1043,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; @@ -1053,16 +1061,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() ) {