From be7e34bc1ef81a5c78a86be7201d3aab5106978b Mon Sep 17 00:00:00 2001 From: wangjohn Date: Sun, 21 Apr 2013 11:39:48 -0400 Subject: Created a registry based on the +PerThreadRegistry+ module for subscriber queues. Helps limit the number of thread locals. --- activesupport/lib/active_support/subscriber.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/subscriber.rb b/activesupport/lib/active_support/subscriber.rb index ab76cf5c85..34c6f900c1 100644 --- a/activesupport/lib/active_support/subscriber.rb +++ b/activesupport/lib/active_support/subscriber.rb @@ -1,3 +1,5 @@ +require 'active_support/per_thread_registry' + module ActiveSupport # ActiveSupport::Subscriber is an object set to consume # ActiveSupport::Notifications. The subscriber dispatches notifications to @@ -68,8 +70,24 @@ module ActiveSupport private - def event_stack - Thread.current[@queue_key] ||= [] + def event_stack + SubscriberQueueRegistry.get_queue(@queue_key) + end + end + + # This is a registry for all the event stacks kept for subscribers. + # + # See the documentation of ActiveSupport::PerThreadRegistry + # for further details. + class SubscriberQueueRegistry # :nodoc: + extend PerThreadRegistry + + def initialize + @registry = {} + end + + def get_queue(queue_key) + @registry[queue_key] ||= [] end end end -- cgit v1.2.3