]> git.saurik.com Git - wxWidgets.git/commitdiff
(hopefully) fixed race condition in installing idle handler (calling wxPostEvent...
authorVáclav Slavík <vslavik@fastmail.fm>
Thu, 4 Nov 2004 20:04:59 +0000 (20:04 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Thu, 4 Nov 2004 20:04:59 +0000 (20:04 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30266 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/app.h
include/wx/gtk1/app.h
src/gtk/app.cpp
src/gtk/evtloop.cpp
src/gtk1/app.cpp
src/gtk1/evtloop.cpp

index 33b62e1c154809bf60ee2efb2b8c67733aa5d8de..fd4fa6226bbaadc0d519176a2bd6c41d69105053 100644 (file)
@@ -56,6 +56,8 @@ public:
 #endif // __WXDEBUG__
 
     gint            m_idleTag;
+    void RemoveIdleTag();
+    
     unsigned char  *m_colorCube;
 
     // Used by the the wxGLApp and wxGLCanvas class for GL-based X visual
index 33b62e1c154809bf60ee2efb2b8c67733aa5d8de..fd4fa6226bbaadc0d519176a2bd6c41d69105053 100644 (file)
@@ -56,6 +56,8 @@ public:
 #endif // __WXDEBUG__
 
     gint            m_idleTag;
+    void RemoveIdleTag();
+    
     unsigned char  *m_colorCube;
 
     // Used by the the wxGLApp and wxGLCanvas class for GL-based X visual
index 86822b5abd5be560ca97369162302db3b2b1c615..5aa26126a7bc94c28b957d80d3871e2676eff209 100644 (file)
@@ -34,6 +34,7 @@
 #include "wx/filename.h"
 #include "wx/module.h"
 #include "wx/image.h"
+#include "wx/thread.h"
 
 #ifdef __WXGPE__
 #include <gpe/init.h>
@@ -97,6 +98,10 @@ extern bool g_isIdle;
 
 void wxapp_install_idle_handler();
 
+#if wxUSE_THREADS
+static wxMutex gs_idleTagsMutex;
+#endif
+
 //-----------------------------------------------------------------------------
 // wxYield
 //-----------------------------------------------------------------------------
@@ -132,8 +137,7 @@ bool wxApp::Yield(bool onlyIfNeeded)
     {
         // We need to remove idle callbacks or the loop will
         // never finish.
-        gtk_idle_remove( m_idleTag );
-        m_idleTag = 0;
+        wxTheApp->RemoveIdleTag();
         g_isIdle = TRUE;
     }
 
@@ -211,7 +215,12 @@ static gint wxapp_pending_callback( gpointer WXUNUSED(data) )
     // Sent idle event to all who request them.
     wxTheApp->ProcessPendingEvents();
 
-    g_pendingTag = 0;
+    {
+#if wxUSE_THREADS
+        wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+        g_pendingTag = 0;
+    }
 
     // Flush the logged messages if any.
 #if wxUSE_LOG
@@ -259,8 +268,13 @@ static gint wxapp_idle_callback( gpointer WXUNUSED(data) )
 
     // Indicate that we are now in idle mode and event handlers
     // will have to reinstall the idle handler again.
-    g_isIdle = TRUE;
-    wxTheApp->m_idleTag = 0;
+    {
+#if wxUSE_THREADS
+        wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+        g_isIdle = TRUE;
+        wxTheApp->m_idleTag = 0;
+    }
 
     // Send idle event to all who request them as long as
     // no events have popped up in the event queue.
@@ -368,6 +382,10 @@ static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout )
 
 void wxapp_install_idle_handler()
 {
+#if wxUSE_THREADS
+    wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+
     // 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?
@@ -679,3 +697,11 @@ void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxC
 
 #endif // __WXDEBUG__
 
+void wxApp::RemoveIdleTag()
+{
+#if wxUSE_THREADS
+    wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+    gtk_idle_remove( wxTheApp->m_idleTag );
+    wxTheApp->m_idleTag = 0;
+}
index d89a31d44ff7d807a8086f83fd74090674e83ea9..429de81069e6bd914732d7ca953110be39acd528 100644 (file)
@@ -109,8 +109,7 @@ bool wxEventLoop::Pending() const
     {
         // We need to remove idle callbacks or gtk_events_pending will
         // never return false.
-        gtk_idle_remove( wxTheApp->m_idleTag );
-        wxTheApp->m_idleTag = 0;
+        wxTheApp->RemoveIdleTag();
         g_isIdle = TRUE;
     }
 
index 86822b5abd5be560ca97369162302db3b2b1c615..5aa26126a7bc94c28b957d80d3871e2676eff209 100644 (file)
@@ -34,6 +34,7 @@
 #include "wx/filename.h"
 #include "wx/module.h"
 #include "wx/image.h"
+#include "wx/thread.h"
 
 #ifdef __WXGPE__
 #include <gpe/init.h>
@@ -97,6 +98,10 @@ extern bool g_isIdle;
 
 void wxapp_install_idle_handler();
 
+#if wxUSE_THREADS
+static wxMutex gs_idleTagsMutex;
+#endif
+
 //-----------------------------------------------------------------------------
 // wxYield
 //-----------------------------------------------------------------------------
@@ -132,8 +137,7 @@ bool wxApp::Yield(bool onlyIfNeeded)
     {
         // We need to remove idle callbacks or the loop will
         // never finish.
-        gtk_idle_remove( m_idleTag );
-        m_idleTag = 0;
+        wxTheApp->RemoveIdleTag();
         g_isIdle = TRUE;
     }
 
@@ -211,7 +215,12 @@ static gint wxapp_pending_callback( gpointer WXUNUSED(data) )
     // Sent idle event to all who request them.
     wxTheApp->ProcessPendingEvents();
 
-    g_pendingTag = 0;
+    {
+#if wxUSE_THREADS
+        wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+        g_pendingTag = 0;
+    }
 
     // Flush the logged messages if any.
 #if wxUSE_LOG
@@ -259,8 +268,13 @@ static gint wxapp_idle_callback( gpointer WXUNUSED(data) )
 
     // Indicate that we are now in idle mode and event handlers
     // will have to reinstall the idle handler again.
-    g_isIdle = TRUE;
-    wxTheApp->m_idleTag = 0;
+    {
+#if wxUSE_THREADS
+        wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+        g_isIdle = TRUE;
+        wxTheApp->m_idleTag = 0;
+    }
 
     // Send idle event to all who request them as long as
     // no events have popped up in the event queue.
@@ -368,6 +382,10 @@ static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout )
 
 void wxapp_install_idle_handler()
 {
+#if wxUSE_THREADS
+    wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+
     // 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?
@@ -679,3 +697,11 @@ void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxC
 
 #endif // __WXDEBUG__
 
+void wxApp::RemoveIdleTag()
+{
+#if wxUSE_THREADS
+    wxMutexLocker lock(gs_idleTagsMutex);
+#endif
+    gtk_idle_remove( wxTheApp->m_idleTag );
+    wxTheApp->m_idleTag = 0;
+}
index d89a31d44ff7d807a8086f83fd74090674e83ea9..429de81069e6bd914732d7ca953110be39acd528 100644 (file)
@@ -109,8 +109,7 @@ bool wxEventLoop::Pending() const
     {
         // We need to remove idle callbacks or gtk_events_pending will
         // never return false.
-        gtk_idle_remove( wxTheApp->m_idleTag );
-        wxTheApp->m_idleTag = 0;
+        wxTheApp->RemoveIdleTag();
         g_isIdle = TRUE;
     }