Permalink
Browse files

Fix timeout handling in the mainloop: allows callbacks to add new timers

  • Loading branch information...
1 parent d896b60 commit 5ad0e2ffa47b491c3b684e2ec9a3caac6e03b83c @migueldeicaza migueldeicaza committed Feb 7, 2011
Showing with 5 additions and 13 deletions.
  1. +5 −13 mainloop.cs
View
@@ -249,25 +249,17 @@ void UpdatePollMap ()
void RunTimers ()
{
- var add = new List<Timeout> ();
- var remove = new List<double> ();
-
long now = DateTime.UtcNow.Ticks;
- foreach (var k in timeouts.Keys){
+ var copy = timeouts;
+ timeouts = new SortedList<double,Timeout> ();
+ foreach (var k in copy.Keys){
if (k >= now)
break;
- var timeout = timeouts [k];
+ var timeout = copy [k];
if (timeout.Callback (this))
- add.Add (timeout);
-
- remove.Add (k);
+ AddTimeout (timeout.Span, timeout);
}
- foreach (var ticks in remove)
- timeouts.Remove (ticks);
-
- foreach (var timeout in add)
- AddTimeout (timeout.Span, timeout);
}
void RunIdle ()

0 comments on commit 5ad0e2f

Please sign in to comment.