summaryrefslogtreecommitdiff
path: root/otk/timer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'otk/timer.cc')
-rw-r--r--otk/timer.cc67
1 files changed, 5 insertions, 62 deletions
diff --git a/otk/timer.cc b/otk/timer.cc
index b2b85a66..bde95f89 100644
--- a/otk/timer.cc
+++ b/otk/timer.cc
@@ -5,8 +5,7 @@
#endif // HAVE_CONFIG_H
#include "timer.hh"
-#include "display.hh"
-#include "util.hh"
+#include "timerqueuemanager.hh"
namespace otk {
@@ -40,7 +39,7 @@ OBTimer::OBTimer(OBTimerQueueManager *m, OBTimeoutHandler h, OBTimeoutData d)
handler = h;
data = d;
- recur = timing = False;
+ recur = timing = false;
}
@@ -70,7 +69,7 @@ void OBTimer::start(void)
gettimeofday(&_start, 0);
if (! timing) {
- timing = True;
+ timing = true;
manager->addTimer(this);
}
}
@@ -78,7 +77,7 @@ void OBTimer::start(void)
void OBTimer::stop(void)
{
- timing = False;
+ timing = false;
manager->removeTimer(this);
}
@@ -86,7 +85,7 @@ void OBTimer::stop(void)
void OBTimer::halt(void)
{
- timing = False;
+ timing = false;
}
@@ -127,60 +126,4 @@ bool OBTimer::shouldFire(const timeval &tm) const
(tm.tv_sec == end.tv_sec && tm.tv_usec < end.tv_usec));
}
-
-void OBTimerQueueManager::fire()
-{
- fd_set rfds;
- timeval now, tm, *timeout = (timeval *) 0;
-
- const int xfd = ConnectionNumber(otk::OBDisplay::display);
-
- FD_ZERO(&rfds);
- FD_SET(xfd, &rfds); // break on any x events
-
- if (! timerList.empty()) {
- const OBTimer* const timer = timerList.top();
-
- gettimeofday(&now, 0);
- tm = timer->timeRemaining(now);
-
- timeout = &tm;
- }
-
- select(xfd + 1, &rfds, 0, 0, timeout);
-
- // check for timer timeout
- gettimeofday(&now, 0);
-
- // there is a small chance for deadlock here:
- // *IF* the timer list keeps getting refreshed *AND* the time between
- // timer->start() and timer->shouldFire() is within the timer's period
- // then the timer will keep firing. This should be VERY near impossible.
- while (! timerList.empty()) {
- OBTimer *timer = timerList.top();
- if (! timer->shouldFire(now))
- break;
-
- timerList.pop();
-
- timer->fireTimeout();
- timer->halt();
- if (timer->isRecurring())
- timer->start();
- }
-}
-
-
-void OBTimerQueueManager::addTimer(OBTimer *timer)
-{
- assert(timer);
- timerList.push(timer);
-}
-
-void OBTimerQueueManager::removeTimer(OBTimer* timer)
-{
- assert(timer);
- timerList.release(timer);
-}
-
}