Browse files

use thread local queues.

Log listener is a singleton shared across threads, so make sure the
event queues are local to each thread.
  • Loading branch information...
1 parent c1c4ecb commit b9f9951d5f7e6f2c947c292a929a48d41c529f26 @tenderlove tenderlove committed Jun 20, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 activesupport/lib/active_support/log_subscriber.rb
View
14 activesupport/lib/active_support/log_subscriber.rb
@@ -87,7 +87,7 @@ def flush_all!
end
def initialize
- @event_stack = []
+ @queue_key = [self.class.name, object_id].join "-"
super
end
@@ -99,17 +99,17 @@ def start(name, id, payload)
return unless logger
e = ActiveSupport::Notifications::Event.new(name, Time.now, nil, id, payload)
- parent = @event_stack.last
+ parent = event_stack.last
parent << e if parent
- @event_stack.push e
+ event_stack.push e
end
def finish(name, id, payload)
return unless logger
finished = Time.now
- event = @event_stack.pop
+ event = event_stack.pop
event.end = finished
event.payload.merge!(payload)
@@ -142,5 +142,11 @@ def color(text, color, bold=false)
bold = bold ? BOLD : ""
"#{bold}#{color}#{text}#{CLEAR}"
end
+
+ private
+
+ def event_stack
+ Thread.current[@queue_key] ||= []
+ end
end
end

0 comments on commit b9f9951

Please sign in to comment.