From a9c02e6c84692d85cc0c90b32161885834940be0 Mon Sep 17 00:00:00 2001 From: chatty Date: Wed, 6 Jul 1994 10:59:12 +0000 Subject: Fixed bug: StopAlarm was not called when no timer was active Handled very special case in Fire, and bug in Solaris --- utils/Timer.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/utils/Timer.cc b/utils/Timer.cc index def04c1..a5fbbad 100644 --- a/utils/Timer.cc +++ b/utils/Timer.cc @@ -21,6 +21,7 @@ #include #include #include +#include /*!class CcuCoreTimer The implementation of \typ{CcuCoreTimer} is a bit tricky, because it tries to be fast. @@ -126,9 +127,19 @@ CcuCoreTimer :: Fire (CcuTimerSet* s) /* If the first timer is not mature yet, ignore this call */ if (!first) return; + CcuTimeStamp now; - if (first->NextDate > now) +#if defined(sun) && defined(__svr4__) + /* add tolerance because Solaris sends signals before the expected time (bug #1164919)*/ + if (first->NextDate > now + 5) { +#else + if (first->NextDate > now) { +#endif + /* this should never happen, except with bogus Solaris... */ + first->SetAlarm (first->NextDate - now); +// fprintf (stderr, "%d > %d\n", first->NextDate, now); return; + } /* Handle the first timer */ first->Reschedule (); @@ -147,6 +158,10 @@ CcuCoreTimer :: Fire (CcuTimerSet* s) if (t) { CcuTimeStamp then; t->SetAlarm (t->NextDate - then); + } else if (first) { + /* we need a valid timer just to be able to call StopAlarm */ + /* if first is null, StopAlarm has already been called (?) */ + first->StopAlarm (); } first = t; @@ -485,7 +500,8 @@ CcuBaseTimer :: SetAlarm (Millisecond delay) timerclear (&itval.it_interval); itval.it_value.tv_sec = delay / 1000; itval.it_value.tv_usec = 1000 * (delay % 1000); - setitimer (ITIMER_REAL, &itval, 0); + if (setitimer (ITIMER_REAL, &itval, 0) < 0) + fprintf (stderr, "setitimer failed for interval %d\n", delay); } -- cgit v1.1