From c263eb03846c1b1439bf67d1d831255024278adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 12 Nov 2004 21:44:26 +0000 Subject: [PATCH] more wxPostEvent MT fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/app.cpp | 27 ++++++++++++++++----------- src/gtk/evtloop.cpp | 5 +---- src/gtk1/app.cpp | 27 ++++++++++++++++----------- src/gtk1/evtloop.cpp | 5 +---- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 5aa26126a7..e722bcace7 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -133,13 +133,9 @@ bool wxApp::Yield(bool onlyIfNeeded) wxIsInsideYield = TRUE; - if (!g_isIdle) - { - // We need to remove idle callbacks or the loop will - // never finish. - wxTheApp->RemoveIdleTag(); - g_isIdle = TRUE; - } + // We need to remove idle callbacks or the loop will + // never finish. + wxTheApp->RemoveIdleTag(); // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c @@ -184,8 +180,7 @@ void wxApp::WakeUpIdle() #endif // wxUSE_THREADS_ #endif // __WXGTK2__ - if (g_isIdle) - wxapp_install_idle_handler(); + wxapp_install_idle_handler(); #ifndef __WXGTK20__ #if wxUSE_THREADS @@ -386,6 +381,11 @@ void wxapp_install_idle_handler() wxMutexLocker lock(gs_idleTagsMutex); #endif + // Don't install the handler if it's already installed. This test *MUST* + // be done when gs_idleTagsMutex is locked! + if (!g_isIdle) + return; + // GD: this assert is raised when using the thread sample (which works) // so the test is probably not so easy. Can widget callbacks be // triggered from child threads and, if so, for which widgets? @@ -437,6 +437,7 @@ wxApp::wxApp() #endif // __WXDEBUG__ m_idleTag = 0; + g_isIdle = TRUE; wxapp_install_idle_handler(); #if wxUSE_THREADS @@ -702,6 +703,10 @@ void wxApp::RemoveIdleTag() #if wxUSE_THREADS wxMutexLocker lock(gs_idleTagsMutex); #endif - gtk_idle_remove( wxTheApp->m_idleTag ); - wxTheApp->m_idleTag = 0; + if (!g_isIdle) + { + gtk_idle_remove( wxTheApp->m_idleTag ); + wxTheApp->m_idleTag = 0; + g_isIdle = TRUE; + } } diff --git a/src/gtk/evtloop.cpp b/src/gtk/evtloop.cpp index 429de81069..ac59d77edb 100644 --- a/src/gtk/evtloop.cpp +++ b/src/gtk/evtloop.cpp @@ -101,16 +101,13 @@ void wxEventLoop::Exit(int rc) // wxEventLoop message processing dispatching // ---------------------------------------------------------------------------- -extern bool g_isIdle; - bool wxEventLoop::Pending() const { - if (wxTheApp && !g_isIdle) + if (wxTheApp) { // We need to remove idle callbacks or gtk_events_pending will // never return false. wxTheApp->RemoveIdleTag(); - g_isIdle = TRUE; } return gtk_events_pending(); diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index 5aa26126a7..e722bcace7 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -133,13 +133,9 @@ bool wxApp::Yield(bool onlyIfNeeded) wxIsInsideYield = TRUE; - if (!g_isIdle) - { - // We need to remove idle callbacks or the loop will - // never finish. - wxTheApp->RemoveIdleTag(); - g_isIdle = TRUE; - } + // We need to remove idle callbacks or the loop will + // never finish. + wxTheApp->RemoveIdleTag(); // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c @@ -184,8 +180,7 @@ void wxApp::WakeUpIdle() #endif // wxUSE_THREADS_ #endif // __WXGTK2__ - if (g_isIdle) - wxapp_install_idle_handler(); + wxapp_install_idle_handler(); #ifndef __WXGTK20__ #if wxUSE_THREADS @@ -386,6 +381,11 @@ void wxapp_install_idle_handler() wxMutexLocker lock(gs_idleTagsMutex); #endif + // Don't install the handler if it's already installed. This test *MUST* + // be done when gs_idleTagsMutex is locked! + if (!g_isIdle) + return; + // GD: this assert is raised when using the thread sample (which works) // so the test is probably not so easy. Can widget callbacks be // triggered from child threads and, if so, for which widgets? @@ -437,6 +437,7 @@ wxApp::wxApp() #endif // __WXDEBUG__ m_idleTag = 0; + g_isIdle = TRUE; wxapp_install_idle_handler(); #if wxUSE_THREADS @@ -702,6 +703,10 @@ void wxApp::RemoveIdleTag() #if wxUSE_THREADS wxMutexLocker lock(gs_idleTagsMutex); #endif - gtk_idle_remove( wxTheApp->m_idleTag ); - wxTheApp->m_idleTag = 0; + if (!g_isIdle) + { + gtk_idle_remove( wxTheApp->m_idleTag ); + wxTheApp->m_idleTag = 0; + g_isIdle = TRUE; + } } diff --git a/src/gtk1/evtloop.cpp b/src/gtk1/evtloop.cpp index 429de81069..ac59d77edb 100644 --- a/src/gtk1/evtloop.cpp +++ b/src/gtk1/evtloop.cpp @@ -101,16 +101,13 @@ void wxEventLoop::Exit(int rc) // wxEventLoop message processing dispatching // ---------------------------------------------------------------------------- -extern bool g_isIdle; - bool wxEventLoop::Pending() const { - if (wxTheApp && !g_isIdle) + if (wxTheApp) { // We need to remove idle callbacks or gtk_events_pending will // never return false. wxTheApp->RemoveIdleTag(); - g_isIdle = TRUE; } return gtk_events_pending();