X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d45242a64a347a84b0c9213d4adcd732ece39cb3..9ab7ff537d1ead0f0b07c14841474203c7fa59ba:/src/unix/timerunx.cpp diff --git a/src/unix/timerunx.cpp b/src/unix/timerunx.cpp index c3c563af04..eb2c4e02b1 100644 --- a/src/unix/timerunx.cpp +++ b/src/unix/timerunx.cpp @@ -31,6 +31,7 @@ #include "wx/apptrait.h" #include "wx/longlong.h" +#include "wx/vector.h" #include #include @@ -53,7 +54,7 @@ static inline wxString wxUsecClockAsString(wxUsecClock_t usec) #if wxUSE_LONGLONG return usec.ToString(); #else // wxUsecClock_t == double - return wxString::Format(_T("%.0f"), usec); + return wxString::Format(wxT("%.0f"), usec); #endif } @@ -85,7 +86,7 @@ void wxTimerScheduler::DoAddTimer(wxTimerSchedule *s) for ( node = m_timers.begin(); node != m_timers.end(); ++node ) { wxASSERT_MSG( (*node)->m_timer != s->m_timer, - _T("adding the same timer twice?") ); + wxT("adding the same timer twice?") ); if ( (*node)->m_expiration > s->m_expiration ) break; @@ -114,7 +115,7 @@ void wxTimerScheduler::RemoveTimer(wxUnixTimerImpl *timer) } } - wxFAIL_MSG( _T("removing inexistent timer?") ); + wxFAIL_MSG( wxT("removing inexistent timer?") ); } bool wxTimerScheduler::GetNext(wxUsecClock_t *remaining) const @@ -122,7 +123,7 @@ bool wxTimerScheduler::GetNext(wxUsecClock_t *remaining) const if ( m_timers.empty() ) return false; - wxCHECK_MSG( remaining, false, _T("NULL pointer") ); + wxCHECK_MSG( remaining, false, wxT("NULL pointer") ); *remaining = (*m_timers.begin())->m_expiration - wxGetLocalTimeUsec(); if ( *remaining < 0 ) @@ -134,16 +135,17 @@ bool wxTimerScheduler::GetNext(wxUsecClock_t *remaining) const return true; } -void wxTimerScheduler::NotifyExpired() +bool wxTimerScheduler::NotifyExpired() { if ( m_timers.empty() ) - return; + return false; const wxUsecClock_t now = wxGetLocalTimeUsec(); - wxTimerList::iterator cur, - next; - for ( cur = m_timers.begin(); cur != m_timers.end(); cur = next ) + typedef wxVector TimerImpls; + TimerImpls toNotify; + for ( wxTimerList::iterator next, + cur = m_timers.begin(); cur != m_timers.end(); cur = next ) { wxTimerSchedule * const s = *cur; if ( s->m_expiration > now ) @@ -180,9 +182,25 @@ void wxTimerScheduler::NotifyExpired() DoAddTimer(s); } - // and finally notify the timer - timer->Notify(); + // we can't notify the timer from this loop as the timer event handler + // could modify m_timers (for example, but not only, by stopping this + // timer) which would render our iterators invalid, so do it after the + // loop end + toNotify.push_back(timer); } + + if ( toNotify.empty() ) + return false; + + for ( TimerImpls::const_iterator i = toNotify.begin(), + end = toNotify.end(); + i != end; + ++i ) + { + (*i)->Notify(); + } + + return true; } // ============================================================================ @@ -223,7 +241,7 @@ bool wxUnixTimerImpl::IsRunning() const wxUnixTimerImpl::~wxUnixTimerImpl() { - wxASSERT_MSG( !m_isRunning, _T("must have been stopped before") ); + wxASSERT_MSG( !m_isRunning, wxT("must have been stopped before") ); } // ============================================================================