]> Dogcows Code - chaz/openbox/blob - otk/timerqueuemanager.cc
split the OBTimerQueueManager and TimerQueue into their own files
[chaz/openbox] / otk / timerqueuemanager.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 #include "timerqueuemanager.hh"
8 #include "display.hh"
9
10 namespace otk {
11
12 void OBTimerQueueManager::fire()
13 {
14 fd_set rfds;
15 timeval now, tm, *timeout = (timeval *) 0;
16
17 const int xfd = ConnectionNumber(otk::OBDisplay::display);
18
19 FD_ZERO(&rfds);
20 FD_SET(xfd, &rfds); // break on any x events
21
22 if (! timerList.empty()) {
23 const OBTimer* const timer = timerList.top();
24
25 gettimeofday(&now, 0);
26 tm = timer->timeRemaining(now);
27
28 timeout = &tm;
29 }
30
31 select(xfd + 1, &rfds, 0, 0, timeout);
32
33 // check for timer timeout
34 gettimeofday(&now, 0);
35
36 // there is a small chance for deadlock here:
37 // *IF* the timer list keeps getting refreshed *AND* the time between
38 // timer->start() and timer->shouldFire() is within the timer's period
39 // then the timer will keep firing. This should be VERY near impossible.
40 while (! timerList.empty()) {
41 OBTimer *timer = timerList.top();
42 if (! timer->shouldFire(now))
43 break;
44
45 timerList.pop();
46
47 timer->fireTimeout();
48 timer->halt();
49 if (timer->isRecurring())
50 timer->start();
51 }
52 }
53
54
55 void OBTimerQueueManager::addTimer(OBTimer *timer)
56 {
57 assert(timer);
58 timerList.push(timer);
59 }
60
61 void OBTimerQueueManager::removeTimer(OBTimer* timer)
62 {
63 assert(timer);
64 timerList.release(timer);
65 }
66
67 }
This page took 0.040953 seconds and 4 git commands to generate.