diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Timer.cc | 20 |
1 files 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 <signal.h> #include <sys/wait.h> #include <sys/time.h> +#include <stdio.h> /*!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); } |