1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

reduce thread locals

This commit is contained in:
Aaron Patterson 2012-06-19 10:15:48 -07:00
parent a01d9dae1c
commit e4de78aec5

View file

@ -137,6 +137,23 @@ module ActiveSupport
module Notifications
@instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }
class Registry # :nodoc:
def self.instance
Thread.current[name] ||= new
end
attr_reader :notifier, :instrumenter
def initialize
self.notifier = Fanout.new
end
def notifier=(notifier)
@notifier = notifier
@instrumenter = Instrumenter.new(notifier)
end
end
class << self
def publish(name, *args)
notifier.publish(name, *args)
@ -169,15 +186,15 @@ module ActiveSupport
end
def instrumenter
Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
Registry.instance.instrumenter
end
def notifier
Thread.current[:notifier] ||= Fanout.new
Registry.instance.notifier
end
def notifier=(notifier)
Thread.current[:notifier] = notifier
Registry.instance.notifier = notifier
end
end
end