From: Paul Cornett Date: Mon, 17 Dec 2007 05:37:00 +0000 (+0000) Subject: add MutexGuiEnter/Leave to wxAppTraits, integrate native GTK+ GUI locking X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d254213eb2b973e826ed3bc84bc681a819eae091 add MutexGuiEnter/Leave to wxAppTraits, integrate native GTK+ GUI locking git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50757 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index 7264604bd3..8273281581 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -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 // ------------------------------------------------------------------------ diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index 3735243e2b..25b0ba9526 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -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(); diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 68ae29e358..962a5c52cf 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -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) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index f530f0998c..a8671dbf3d 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -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 diff --git a/src/mac/carbon/thread.cpp b/src/mac/carbon/thread.cpp index da4c2c1c9c..04383b0f94 100644 --- a/src/mac/carbon/thread.cpp +++ b/src/mac/carbon/thread.cpp @@ -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); diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 6b835a9707..7127bee02b 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -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); diff --git a/src/os2/thread.cpp b/src/os2/thread.cpp index f4234f2d85..253fb2143a 100644 --- a/src/os2/thread.cpp +++ b/src/os2/thread.cpp @@ -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); diff --git a/src/palmos/thread.cpp b/src/palmos/thread.cpp index 5dbbbdcea1..cd2e55d310 100644 --- a/src/palmos/thread.cpp +++ b/src/palmos/thread.cpp @@ -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() { } diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index 0384805c1a..8e7d9bba9f 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -1800,12 +1800,12 @@ static void DeleteThread(wxThread *This) } } -void wxMutexGuiEnter() +void wxMutexGuiEnterImpl() { gs_mutexGui->Lock(); } -void wxMutexGuiLeave() +void wxMutexGuiLeaveImpl() { gs_mutexGui->Unlock(); }