diff --git a/src/common/evtloopcmn.cpp b/src/common/evtloopcmn.cpp index 711ada6006..ee1244ff4b 100644 --- a/src/common/evtloopcmn.cpp +++ b/src/common/evtloopcmn.cpp @@ -30,6 +30,23 @@ #include "wx/app.h" #endif //WX_PRECOMP +// see the comment near the declaration of wxRunningEventLoopCount in +// src/msw/thread.cpp for the explanation of this hack +#ifdef __WXMSW__ + +extern int wxRunningEventLoopCount; +struct wxRunningEventLoopCounter +{ + wxRunningEventLoopCounter() { wxRunningEventLoopCount++; } + ~wxRunningEventLoopCounter() { wxRunningEventLoopCount--; } +}; + +#else // !__WXMSW__ + +struct wxRunningEventLoopCounter { }; + +#endif // __WXMSW__/!__WXMSW__ + // ---------------------------------------------------------------------------- // globals // ---------------------------------------------------------------------------- @@ -59,6 +76,8 @@ int wxEventLoopManual::Run() // should undo wxEventLoopActivator activate(wx_static_cast(wxEventLoop *, this)); + wxRunningEventLoopCounter evtLoopCounter; + // we must ensure that OnExit() is called even if an exception is thrown // from inside Dispatch() but we must call it from Exit() in normal // situations because it is supposed to be called synchronously, diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 736663b38a..d6115306bb 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -86,6 +86,16 @@ #define THREAD_CALLCONV WINAPI #endif +// this is a hack to allow the code here to know whether wxEventLoop is +// currently running: as wxBase doesn't have event loop at all, we can't simple +// use "wxEventLoop::GetActive() != NULL" test, so instead wxEventLoop uses +// this variable to indicate whether it is active +// +// the proper solution is to use wxAppTraits to abstract the base/GUI-dependent +// operation of waiting for the thread to terminate and is already implemented +// in cvs HEAD, this is just a backwards compatible hack for 2.8 +int wxRunningEventLoopCount = 0; + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -755,7 +765,7 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs, #if !defined(QS_ALLPOSTMESSAGE) #define QS_ALLPOSTMESSAGE 0 #endif - if ( !wxEventLoop::GetActive() ) + if ( !wxRunningEventLoopCount ) { // don't ask for Windows messages if we don't have a running event // loop to process them as otherwise we'd enter an infinite loop