diff options
author | dmitry kim <jason@nichego.net> | 2008-12-29 03:57:42 +0300 |
---|---|---|
committer | dmitry kim <jason@nichego.net> | 2008-12-29 03:57:42 +0300 |
commit | ab6aebf3f87aac76cb8b568e0ea8626d19e4d9a9 (patch) | |
tree | 59fce404d53cd4e070f9dfe7e97337179af599d5 | |
parent | 51c35168127e0faed56bceb3f5103f92ed31478c (diff) |
* (timer.rb) race condition on @actions.each() fixed (thanks, Mike`)
-rw-r--r-- | lib/rbot/timer.rb | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/lib/rbot/timer.rb b/lib/rbot/timer.rb index 8adb14d8..f68e490a 100644 --- a/lib/rbot/timer.rb +++ b/lib/rbot/timer.rb @@ -233,31 +233,23 @@ class Timer end def run_actions(now = Time.now) - nxt = nil @actions.keys.each do |k| return -1 if @stopping - a = @actions[k] - next if (!a) or a.blocked? - - if a.next <= now - begin - @current = k - v = a.run(now) - ensure - @current = nil - end - - unless v - @actions.delete k - next - end - else - v = a.next + a = @actions[k] or next + next if a.blocked? || a.next > now + + begin + @current = k + a.run(now) + ensure + @current = nil end - nxt = v if v and ((!nxt) or (v < nxt)) + @actions.delete k unless a.next end + nxt = @actions.values.map { |v| v.next }.min + if nxt delta = nxt - now delta = 0 if delta < 0 |