From 7f84f875dd5343a4ae60ac39d1666527adf90f85 Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 28 Nov 2000 14:19:34 +0000 Subject: Fixed nasty bug triggered when calling Restart in Handle: added FirstIsUpdated --- utils/Timer.cc | 20 +++++++++++++++++--- utils/Timer.h | 7 ++++--- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/Timer.cc b/utils/Timer.cc index 91e97d0..8342854 100644 --- a/utils/Timer.cc +++ b/utils/Timer.cc @@ -3,7 +3,7 @@ * * by Stephane Chatty * - * Copyright 1992-1995 + * Copyright 1992-1996 * Centre d'Etudes de la Navigation Aerienne (CENA) * * timers @@ -105,6 +105,7 @@ CcuTimerSet :: ExtractNextActive () while ((t = (CcuCoreTimer*) OtherTimers.RemoveFirst ()) && (t->StatusFlag != CcuCoreTimer::Active)) #endif ; + return t; } @@ -144,20 +145,31 @@ CcuCoreTimer :: Fire (CcuTimerSet* s) return; } - /* Handle the first timer */ + /**** Handle the first timer ****/ + /* first, reschedule it ASAP*/ first->Reschedule (); + /* first is not valid, but Handle will perhaps call Stop or Restart and do the job */ + s->FirstIsUpdated = false; + /* then, call the user's code */ first->Handle (now); /* handle all other expired timers. */ CcuCoreTimer* t; while (t = s->ExtractNextActive ()) { /* Problem : if one Handle () is long, "now" will then be wrong. */ - if (t->NextDate > now) + if (t->NextDate > now) { +// fprintf (stderr, "%x is not ready\n", t); break; + } +// fprintf (stderr, "%x is ready\n", t); t->Reschedule (); t->Handle (now); } + /* don't try and update first if it's alredy been done! */ + if (s->FirstIsUpdated) + return; + if (t) { CcuTimeStamp then; t->SetAlarm (t->NextDate - then); @@ -280,6 +292,7 @@ CcuCoreTimer :: Activate () } else Schedule (NextDate); StatusFlag = Active; + MySet->FirstIsUpdated = true; } /*?hidden?*/ @@ -359,6 +372,7 @@ CcuCoreTimer :: Stop () first->SetAlarm (first->NextDate - now); } } + MySet->FirstIsUpdated = true; } /*? diff --git a/utils/Timer.h b/utils/Timer.h index 367a320..bdeb520 100644 --- a/utils/Timer.h +++ b/utils/Timer.h @@ -3,7 +3,7 @@ * * by Stephane Chatty * - * Copyright 1992-1995 + * Copyright 1992-1996 * Centre d'Etudes de la Navigation Aerienne (CENA) * * timers @@ -38,11 +38,12 @@ private: #else CcuList OtherTimers; #endif + bool FirstIsUpdated; CcuCoreTimer* ExtractNextActive (); public: -inline CcuTimerSet () : FirstTimer (0), OtherTimers () {} +inline CcuTimerSet () : FirstTimer (0), OtherTimers (), FirstIsUpdated (false) {} inline ~CcuTimerSet () {} -inline bool IsEmpty () const { return bool (FirstTimer == 0); } +//inline bool IsEmpty () const { return bool (FirstTimer == 0); } seems useless (10 may 96) }; class CcuCoreTimer { -- cgit v1.1