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
This commit is contained in:
Paul Cornett 2007-12-17 05:37:00 +00:00
parent 4eccf53dd5
commit d254213eb2
9 changed files with 59 additions and 16 deletions

View 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
// ------------------------------------------------------------------------

View 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();

View 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)

View 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

View 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);

View 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);

View 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);

View 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()
{
}

View File

@ -1800,12 +1800,12 @@ static void DeleteThread(wxThread *This)
}
}
void wxMutexGuiEnter()
void wxMutexGuiEnterImpl()
{
gs_mutexGui->Lock();
}
void wxMutexGuiLeave()
void wxMutexGuiLeaveImpl()
{
gs_mutexGui->Unlock();
}