From 8ebec7dcd8b0b7294dbc86340d52a10b45bc80db Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Jan 2008 19:07:52 +0000 Subject: [PATCH] clean up wxEvtHandler::m_eventsLocker weirdness: there is no need to allocate it dynamically (as it's always done anyhow), this removes the need for ClearEventLocker() and OS/2 #ifdefs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51027 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/event.h | 23 ++++------------------- src/common/appcmn.cpp | 7 ------- src/common/event.cpp | 25 ++++--------------------- 3 files changed, 8 insertions(+), 47 deletions(-) diff --git a/include/wx/event.h b/include/wx/event.h index a3e78eb852..60d4978b74 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -23,15 +23,13 @@ #endif #include "wx/dynarray.h" +#include "wx/thread.h" // ---------------------------------------------------------------------------- // forward declarations // ---------------------------------------------------------------------------- class WXDLLIMPEXP_FWD_BASE wxList; -#if wxUSE_THREADS - class WXDLLIMPEXP_FWD_BASE wxCriticalSection; -#endif #if wxUSE_GUI class WXDLLIMPEXP_FWD_CORE wxDC; class WXDLLIMPEXP_FWD_CORE wxMenu; @@ -2359,10 +2357,6 @@ public: virtual bool SearchEventTable(wxEventTable& table, wxEvent& event); bool SearchDynamicEventTable( wxEvent& event ); -#if wxUSE_THREADS - void ClearEventLocker(); -#endif // wxUSE_THREADS - // Avoid problems at exit by cleaning up static hash table gracefully void ClearEventHashTable() { GetEventHashTable().Clear(); } @@ -2402,18 +2396,9 @@ protected: wxList* m_pendingEvents; #if wxUSE_THREADS -#if defined (__VISAGECPP__) - const wxCriticalSection& Lock() const { return m_eventsLocker; } - wxCriticalSection& Lock() { return m_eventsLocker; } - - wxCriticalSection m_eventsLocker; -# else - const wxCriticalSection& Lock() const { return *m_eventsLocker; } - wxCriticalSection& Lock() { return *m_eventsLocker; } - - wxCriticalSection* m_eventsLocker; -# endif -#endif + // critical section protecting m_pendingEvents + wxCriticalSection m_pendingEventsLock; +#endif // wxUSE_THREADS // Is event handler enabled? bool m_enabled; diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 3be7882932..15f409dbd6 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -138,13 +138,6 @@ void wxAppBase::CleanUp() delete wxTheColourDatabase; wxTheColourDatabase = NULL; -#if wxUSE_THREADS - #if wxUSE_VALIDATORS - // If we don't do the following, we get an apparent memory leak. - ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); - #endif // wxUSE_VALIDATORS -#endif // wxUSE_THREADS - wxAppConsole::CleanUp(); } diff --git a/src/common/event.cpp b/src/common/event.cpp index e5d4884bba..dc121dee42 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -1028,11 +1028,6 @@ wxEvtHandler::wxEvtHandler() m_enabled = true; m_dynamicEvents = (wxList *) NULL; m_pendingEvents = (wxList *) NULL; -#if wxUSE_THREADS -# if !defined(__VISAGECPP__) - m_eventsLocker = new wxCriticalSection; -# endif -#endif // no client data (yet) m_clientData = NULL; @@ -1068,10 +1063,6 @@ wxEvtHandler::~wxEvtHandler() m_pendingEvents->DeleteContents(true); delete m_pendingEvents; -# if !defined(__VISAGECPP__) - delete m_eventsLocker; -# endif - // Remove us from wxPendingEvents if necessary. if ( wxPendingEvents ) { @@ -1108,14 +1099,6 @@ bool wxEvtHandler::ProcessThreadEvent(const wxEvent& event) return true; } -void wxEvtHandler::ClearEventLocker() -{ -#if !defined(__VISAGECPP__) - delete m_eventsLocker; - m_eventsLocker = NULL; -#endif -} - #endif // wxUSE_THREADS void wxEvtHandler::AddPendingEvent(const wxEvent& event) @@ -1129,14 +1112,14 @@ void wxEvtHandler::AddPendingEvent(const wxEvent& event) wxCHECK_RET( eventCopy, _T("events of this type aren't supposed to be posted") ); - wxENTER_CRIT_SECT( Lock() ); + wxENTER_CRIT_SECT( m_pendingEventsLock ); if ( !m_pendingEvents ) m_pendingEvents = new wxList; m_pendingEvents->Append(eventCopy); - wxLEAVE_CRIT_SECT( Lock() ); + wxLEAVE_CRIT_SECT( m_pendingEventsLock ); // 2) Add this event handler to list of event handlers that // have pending events. @@ -1157,7 +1140,7 @@ void wxEvtHandler::AddPendingEvent(const wxEvent& event) void wxEvtHandler::ProcessPendingEvents() { - wxENTER_CRIT_SECT( Lock() ); + wxENTER_CRIT_SECT( m_pendingEventsLock ); // this method is only called by wxApp if this handler does have // pending events @@ -1177,7 +1160,7 @@ void wxEvtHandler::ProcessPendingEvents() if ( m_pendingEvents->IsEmpty() ) wxPendingEvents->DeleteObject(this); - wxLEAVE_CRIT_SECT( Lock() ); + wxLEAVE_CRIT_SECT( m_pendingEventsLock ); ProcessEvent(*event); -- 2.45.2