1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "timerqueuemanager.hh"
12 void OBTimerQueueManager::fire(bool wait)
15 timeval now, tm, *timeout = (timeval *) 0;
17 const int xfd = ConnectionNumber(otk::OBDisplay::display);
20 FD_SET(xfd, &rfds); // break on any x events
23 if (! timerList.empty()) {
24 const OBTimer* const timer = timerList.top();
26 gettimeofday(&now, 0);
27 tm = timer->remainingTime(now);
32 select(xfd + 1, &rfds, 0, 0, timeout);
35 // check for timer timeout
36 gettimeofday(&now, 0);
38 // there is a small chance for deadlock here:
39 // *IF* the timer list keeps getting refreshed *AND* the time between
40 // timer->start() and timer->shouldFire() is within the timer's period
41 // then the timer will keep firing. This should be VERY near impossible.
42 while (! timerList.empty()) {
43 OBTimer *timer = timerList.top();
44 if (! timer->shouldFire(now))
50 if (timer->recurring())
56 void OBTimerQueueManager::addTimer(OBTimer *timer)
59 timerList.push(timer);
62 void OBTimerQueueManager::removeTimer(OBTimer* timer)
65 timerList.release(timer);