From 74e10fcc6ad3dd08e94996c2687f15725c95a0dd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 4 Jun 2007 13:34:54 +0000 Subject: [PATCH] reset one shot timer internal state instead of leaving it thinking that it's still running (mdified patch 1730597) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/unix/private/timer.h | 11 +++++++++-- samples/console/console.cpp | 7 +++++++ src/unix/timerunx.cpp | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/wx/unix/private/timer.h b/include/wx/unix/private/timer.h index cdcf53b3d2..17776738c9 100644 --- a/include/wx/unix/private/timer.h +++ b/include/wx/unix/private/timer.h @@ -31,10 +31,17 @@ public: virtual bool Start(int milliseconds = -1, bool oneShot = false); virtual void Stop(); + // for wxTimerScheduler only: resets the internal flag indicating that the + // timer is running + void MarkStopped() + { + wxASSERT_MSG( m_isRunning, _T("stopping non-running timer?") ); + + m_isRunning = false; + } + private: bool m_isRunning; - - friend class wxTimerScheduler; }; // ---------------------------------------------------------------------------- diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 696467232b..2244fb1cee 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -27,6 +27,7 @@ #include "wx/log.h" #include "wx/apptrait.h" #include "wx/platinfo.h" +#include "wx/wxchar.h" // without this pragma, the stupid compiler precompiles #defines below so that // changing them doesn't "take place" later! @@ -2958,6 +2959,7 @@ void TestTimer() virtual void Notify() { wxPrintf(_T("%d"), m_num++); + fflush(stdout); if ( m_num == 10 ) { @@ -2977,6 +2979,11 @@ void TestTimer() wxEventLoop loop; + wxTimer timer1; + timer1.Start(100, true /* one shot */); + timer1.Stop(); + timer1.Start(100, true /* one shot */); + MyTimer timer; timer.Start(500); diff --git a/src/unix/timerunx.cpp b/src/unix/timerunx.cpp index 12dc0bdf27..c7734b4235 100644 --- a/src/unix/timerunx.cpp +++ b/src/unix/timerunx.cpp @@ -159,6 +159,11 @@ 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; } -- 2.45.2