diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-08 14:41:45 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-08 14:41:45 -0700 |
commit | fb6c661fe946dc899b15d15b92cc8cf9a21d424e (patch) | |
tree | 54a741b500fb3d88e4b2790e864da63540336b06 | |
parent | 5afaf4e2ba83e3e7a76a04006850bc0752ea558e (diff) | |
parent | b62c197a226d08c24f3ecf95b3ff3cfaae0a0c0b (diff) | |
download | rails-fb6c661fe946dc899b15d15b92cc8cf9a21d424e.tar.gz rails-fb6c661fe946dc899b15d15b92cc8cf9a21d424e.tar.bz2 rails-fb6c661fe946dc899b15d15b92cc8cf9a21d424e.zip |
Merge pull request #10145 from wangjohn/instrumentation_registry_creation
Consolidating thread locals in AS::Notifications
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 705a4693b7..ab2bb5fafe 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -177,7 +177,33 @@ module ActiveSupport end def instrumenter - Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier) + InstrumentationRegistry.instrumenter_for(notifier) + end + end + + # This class is a registry which holds all of the +Instrumenter+ objects + # in a particular thread local. To access the +Instrumenter+ object for a + # particular +notifier+, you can call the following method: + # + # InstrumentationRegistry.instrumenter_for(notifier) + # + # The instrumenters for multiple notifiers are held in a single instance of + # this class. + class InstrumentationRegistry # :nodoc: + class << self + delegate :instrumenter_for, to: :current + + def current + Thread.current[:instrumentation_registry] ||= new + end + end + + def initialize + @registry = {} + end + + def instrumenter_for(notifier) + @registry[notifier] ||= Instrumenter.new(notifier) end end |