]> Dogcows Code - chaz/openbox/blob - otk/timerqueuemanager.cc
make shape work with the titlebar and handle
[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()
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->remainingTime(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->fire();
48 if (timer->recurring())
49 timer->start();
50 }
51 }
52
53
54 void OBTimerQueueManager::addTimer(OBTimer *timer)
55 {
56 assert(timer);
57 timerList.push(timer);
58 }
59
60 void OBTimerQueueManager::removeTimer(OBTimer* timer)
61 {
62 assert(timer);
63 timerList.release(timer);
64 }
65
66 }
This page took 0.0348579999999999 seconds and 4 git commands to generate.