summaryrefslogtreecommitdiff
path: root/utils/Timer.cc
diff options
context:
space:
mode:
authorchatty1994-07-06 10:59:12 +0000
committerchatty1994-07-06 10:59:12 +0000
commita9c02e6c84692d85cc0c90b32161885834940be0 (patch)
tree2d9214d997c3d9c75d8d352824b6f716e4038b85 /utils/Timer.cc
parent647b38fff595320e52b5c9996d9d9ad79e6d8c28 (diff)
downloadivy-league-a9c02e6c84692d85cc0c90b32161885834940be0.zip
ivy-league-a9c02e6c84692d85cc0c90b32161885834940be0.tar.gz
ivy-league-a9c02e6c84692d85cc0c90b32161885834940be0.tar.bz2
ivy-league-a9c02e6c84692d85cc0c90b32161885834940be0.tar.xz
Fixed bug: StopAlarm was not called when no timer was active
Handled very special case in Fire, and bug in Solaris
Diffstat (limited to 'utils/Timer.cc')
-rw-r--r--utils/Timer.cc20
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);
}