]> git.saurik.com Git - wxWidgets.git/commitdiff
add MutexGuiEnter/Leave to wxAppTraits, integrate native GTK+ GUI locking
authorPaul Cornett <paulcor@bullseye.com>
Mon, 17 Dec 2007 05:37:00 +0000 (05:37 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Mon, 17 Dec 2007 05:37:00 +0000 (05:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50757 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/apptrait.h
include/wx/unix/apptrait.h
src/common/appbase.cpp
src/gtk/app.cpp
src/mac/carbon/thread.cpp
src/msw/thread.cpp
src/os2/thread.cpp
src/palmos/thread.cpp
src/unix/threadpsx.cpp

index 7264604bd38a38453a029bfd2d4d486b491d4f2c..82732815819d351e16873029db64b893fcaa32ba 100644 (file)
@@ -133,6 +133,11 @@ public:
     virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0;
 #endif
 
+#if wxUSE_THREADS
+    virtual void MutexGuiEnter();
+    virtual void MutexGuiLeave();
+#endif
+
     // functions returning port-specific information
     // ------------------------------------------------------------------------
 
index 3735243e2bae19f03a45c21daf10e916ee679491..25b0ba9526356ad581ba1d405168a4aaf33bf414 100644 (file)
@@ -44,6 +44,10 @@ public:
 #if wxUSE_TIMER
     virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
 #endif
+#if wxUSE_THREADS && defined(__WXGTK20__)
+    virtual void MutexGuiEnter();
+    virtual void MutexGuiLeave();
+#endif
 
 #if (defined(__WXMAC__) || defined(__WXCOCOA__)) && wxUSE_STDPATHS
     virtual wxStandardPathsBase& GetStandardPaths();
index 68ae29e35821adee26a75bde6657667dfe9d6071..962a5c52cfa16988323a05d47b1543d7eab9e876 100644 (file)
@@ -664,6 +664,31 @@ void wxAppTraitsBase::SetLocale()
 }
 #endif
 
+#if wxUSE_THREADS
+void wxMutexGuiEnterImpl();
+void wxMutexGuiLeaveImpl();
+
+void wxAppTraitsBase::MutexGuiEnter()
+{
+    wxMutexGuiEnterImpl();
+}
+
+void wxAppTraitsBase::MutexGuiLeave()
+{
+    wxMutexGuiLeaveImpl();
+}
+
+void WXDLLIMPEXP_BASE wxMutexGuiEnter()
+{
+    wxAppConsoleBase::GetInstance()->GetTraits()->MutexGuiEnter();
+}
+
+void WXDLLIMPEXP_BASE wxMutexGuiLeave()
+{
+    wxAppConsoleBase::GetInstance()->GetTraits()->MutexGuiLeave();
+}
+#endif // wxUSE_THREADS
+
 #ifdef __WXDEBUG__
 
 bool wxAppTraitsBase::ShowAssertDialog(const wxString& msgOriginal)
index f530f0998c8c34894c98307aeb77bbd6ee6eb82c..a8671dbf3dd391c41741ce886262d3fe92ab4e41 100644 (file)
@@ -225,18 +225,12 @@ static GPollFunc wxgs_poll_func;
 extern "C" {
 static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout )
 {
-    gdk_threads_enter();
-
-    wxMutexGuiLeave();
     g_mainThreadLocked = true;
 
     gint res = (*wxgs_poll_func)(ufds, nfds, timeout);
 
-    wxMutexGuiEnter();
     g_mainThreadLocked = false;
 
-    gdk_threads_leave();
-
     return res;
 }
 }
@@ -356,7 +350,10 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_)
 
 #if wxUSE_THREADS
     if (!g_thread_supported())
+    {
         g_thread_init(NULL);
+        gdk_threads_init();
+    }
 
     wxgs_poll_func = g_main_context_get_poll_func(NULL);
     g_main_context_set_poll_func(NULL, wxapp_poll_func);
@@ -581,3 +578,15 @@ void wxApp::OnAssertFailure(const wxChar *file,
 }
 
 #endif // __WXDEBUG__
+
+#if wxUSE_THREADS
+void wxGUIAppTraits::MutexGuiEnter()
+{
+    gdk_threads_enter();
+}
+
+void wxGUIAppTraits::MutexGuiLeave()
+{
+    gdk_threads_leave();
+}
+#endif // wxUSE_THREADS
index da4c2c1c9cc173e2e5610bac2ac4ed94a39b116d..04383b0f9478878676167e247fc3df36c570d27f 100644 (file)
@@ -1679,7 +1679,7 @@ void wxThreadModule::OnExit()
 // GUI Serialization copied from MSW implementation
 // ----------------------------------------------------------------------------
 
-void WXDLLIMPEXP_BASE wxMutexGuiEnter()
+void wxMutexGuiEnterImpl()
 {
     // this would dead lock everything...
     wxASSERT_MSG( !wxThread::IsMain(),
@@ -1701,7 +1701,7 @@ void WXDLLIMPEXP_BASE wxMutexGuiEnter()
     gs_critsectGui->Enter();
 }
 
-void WXDLLIMPEXP_BASE wxMutexGuiLeave()
+void wxMutexGuiLeaveImpl()
 {
     wxCriticalSectionLocker enter(*gs_critsectWaitingForGui);
 
index 6b835a97073906ab56c0a5220c3a8def05a8b407..7127bee02bb78f39892ff1740cb639d4b82021d9 100644 (file)
@@ -1292,7 +1292,7 @@ void wxThreadModule::OnExit()
 // not a mutex, so the names are a bit confusing
 // ----------------------------------------------------------------------------
 
-void WXDLLIMPEXP_BASE wxMutexGuiEnter()
+void wxMutexGuiEnterImpl()
 {
     // this would dead lock everything...
     wxASSERT_MSG( !wxThread::IsMain(),
@@ -1314,7 +1314,7 @@ void WXDLLIMPEXP_BASE wxMutexGuiEnter()
     gs_critsectGui->Enter();
 }
 
-void WXDLLIMPEXP_BASE wxMutexGuiLeave()
+void wxMutexGuiLeaveImpl()
 {
     wxCriticalSectionLocker enter(*gs_critsectWaitingForGui);
 
index f4234f2d85a6500b9786c42e263a59fede7e44d6..253fb2143acf8192672efa69af29b135ca0b81bc 100644 (file)
@@ -985,7 +985,7 @@ void WXDLLEXPORT wxWakeUpMainThread()
 #endif
 }
 
-void WXDLLEXPORT wxMutexGuiEnter()
+void wxMutexGuiEnterImpl()
 {
     // this would dead lock everything...
     wxASSERT_MSG( !wxThread::IsMain(),
@@ -1007,7 +1007,7 @@ void WXDLLEXPORT wxMutexGuiEnter()
     gs_pCritsectGui->Enter();
 }
 
-void WXDLLEXPORT wxMutexGuiLeave()
+void wxMutexGuiLeaveImpl()
 {
     wxCriticalSectionLocker enter(*gs_pCritsectWaitingForGui);
 
index 5dbbbdcea1dc295a19a9a64b5e9defc55c7348fe..cd2e55d310dbcaa4e253b252a358c0e45f8f2da0 100644 (file)
@@ -557,11 +557,11 @@ void wxThreadModule::OnExit()
 // not a mutex, so the names are a bit confusing
 // ----------------------------------------------------------------------------
 
-void WXDLLIMPEXP_BASE wxMutexGuiEnter()
+void wxMutexGuiEnterImpl()
 {
 }
 
-void WXDLLIMPEXP_BASE wxMutexGuiLeave()
+void wxMutexGuiLeaveImpl()
 {
 }
 
index 0384805c1ad09e9f98354e583ef09a43b0d2ba5f..8e7d9bba9fd26fe9748bc2dad00a067a2519914a 100644 (file)
@@ -1800,12 +1800,12 @@ static void DeleteThread(wxThread *This)
     }
 }
 
-void wxMutexGuiEnter()
+void wxMutexGuiEnterImpl()
 {
     gs_mutexGui->Lock();
 }
 
-void wxMutexGuiLeave()
+void wxMutexGuiLeaveImpl()
 {
     gs_mutexGui->Unlock();
 }