blob: dceb1043b2f91763198893400b6ea89c06114ae4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
From 4d307dcd10af9d817ff5c05fc40ae7487564cb31 Mon Sep 17 00:00:00 2001
From: Mathias Gumz <akira at fluxbox dot org>
Date: Sat, 12 Jan 2013 08:24:11 +0000
Subject: Fix bug: handle the list of Timers not in-place
With commit 541c8c4 we switched from an (manually) ordered list to a
std::set<> to handle the active timers. The code which checks for overdue
timers now traverses and modifies the std::set<> in place. This might
lead to an infinite loop. Examples of such bad behavior are "flickering of
the tooltip" (bug #3590078) or crashes (bug #3600143) or just insanely high
cpu load when autoraising windows or submenus.
We now make a copy of the std::set<> traverse this instead of the original.
---
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc
index f63ea38..dd736dd 100644
--- a/src/FbTk/Timer.cc
+++ b/src/FbTk/Timer.cc
@@ -52,6 +52,7 @@
#endif
#include <cstdio>
+#include <vector>
#include <set>
@@ -195,32 +196,35 @@ void Timer::updateTimers(int fd) {
return;
}
+ // stoping / restarting the timers modifies the list in an upredictable
+ // way. to avoid problems such as infinite loops we save the current
+ // (ordered) list of timers into a list and work on it.
+
+ ssize_t i;
+ const ssize_t ts = s_timerlist.size();
+ std::vector<FbTk::Timer*> timers;
+
+ timers.reserve(ts);
+ for (it = s_timerlist.begin(); it != s_timerlist.end(); ++it ) {
+ timers.push_back(*it);
+ }
+
now = FbTime::now();
- for (it = s_timerlist.begin(); it != s_timerlist.end(); ) {
+ for (i = 0; i < ts; ++i) {
+
+ FbTk::Timer* t = timers[i];
- // t->fireTimeout() might add timers to the list
- // this invalidates 'it'. thus we store the current timer
- Timer* t = *it;
if (now < t->getEndTime()) {
break;
}
t->fireTimeout();
-
- // find the iterator to the timer again
- // and continue working on the list
- it = s_timerlist.find(t);
- it++;
- s_timerlist.erase(t);
+ t->stop();
if (! t->doOnce()) { // restart the current timer
- t->m_timing = false;
t->start();
- } else {
- t->stop();
}
}
-
}
--
cgit v0.9.1
|