]> Dogcows Code - chaz/openbox/blob - otk/timerqueuemanager.cc
in synch mode, chew up 100% cpu, cuz we cant select on the display's fd
[chaz/openbox] / otk / timerqueuemanager.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
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(bool wait)
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 (wait) {
23 if (! timerList.empty()) {
24 const OBTimer* const timer = timerList.top();
25
26 gettimeofday(&now, 0);
27 tm = timer->remainingTime(now);
28
29 timeout = &tm;
30 }
31
32 select(xfd + 1, &rfds, 0, 0, timeout);
33 }
34
35 // check for timer timeout
36 gettimeofday(&now, 0);
37
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))
45 break;
46
47 timerList.pop();
48
49 timer->fire();
50 if (timer->recurring())
51 timer->start();
52 }
53 }
54
55
56 void OBTimerQueueManager::addTimer(OBTimer *timer)
57 {
58 assert(timer);
59 timerList.push(timer);
60 }
61
62 void OBTimerQueueManager::removeTimer(OBTimer* timer)
63 {
64 assert(timer);
65 timerList.release(timer);
66 }
67
68 }
This page took 0.043273 seconds and 5 git commands to generate.