X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c2ca375c5620209d77a88d2d378bdcdedbc82e7e..591cc82deb5bc6dd0af6047ecfa7ce7cf4f8d859:/src/unix/timerunx.cpp diff --git a/src/unix/timerunx.cpp b/src/unix/timerunx.cpp index 12dc0bdf27..d6ee503df5 100644 --- a/src/unix/timerunx.cpp +++ b/src/unix/timerunx.cpp @@ -18,6 +18,8 @@ #include "wx/wxprec.h" +#if wxUSE_TIMER + #ifndef WX_PRECOMP #include "wx/log.h" #include "wx/module.h" @@ -27,6 +29,7 @@ #include "wx/event.h" #endif +#include "wx/apptrait.h" #include "wx/longlong.h" #include @@ -35,7 +38,7 @@ #include "wx/unix/private/timer.h" #include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxTimerList); +WX_DEFINE_LIST(wxTimerList) // trace mask for the debugging messages used here #define wxTrace_Timer wxT("timer") @@ -131,10 +134,12 @@ bool wxTimerScheduler::GetNext(wxUsecClock_t *remaining) const return true; } -void wxTimerScheduler::NotifyExpired() +bool wxTimerScheduler::NotifyExpired() { if ( m_timers.empty() ) - return; + return false; + + bool notified = false; const wxUsecClock_t now = wxGetLocalTimeUsec(); @@ -159,18 +164,30 @@ void wxTimerScheduler::NotifyExpired() wxUnixTimerImpl * const timer = s->m_timer; if ( timer->IsOneShot() ) { + // the timer needs to be stopped but don't call its Stop() from + // here as it would attempt to remove the timer from our list and + // we had already done it, so we just need to reset its state + timer->MarkStopped(); + // don't need it any more delete s; } else // reschedule the next timer expiration { - s->m_expiration += timer->GetInterval()*1000; + // always keep the expiration time in the future, i.e. base it on + // the current time instead of just offsetting it from the current + // expiration time because it could happen that we're late and the + // current expiration time is (far) in the past + s->m_expiration = now + timer->GetInterval()*1000; DoAddTimer(s); } // and finally notify the timer timer->Notify(); + notified = true; } + + return notified; } // ============================================================================ @@ -249,3 +266,10 @@ wxUsecClock_t wxGetLocalTimeUsec() return wxGetLocalTimeMillis() * 1000L; } +wxTimerImpl *wxConsoleAppTraits::CreateTimerImpl(wxTimer *timer) +{ + return new wxUnixTimerImpl(timer); +} + +#endif // wxUSE_TIMER +