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

make the compile method thread safe

This commit is contained in:
Aaron Patterson 2013-05-14 16:18:11 -07:00
parent d2405a0aab
commit 132db318b3

View file

@ -1,9 +1,9 @@
require 'thread_safe'
require 'active_support/concern' require 'active_support/concern'
require 'active_support/descendants_tracker' require 'active_support/descendants_tracker'
require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/singleton_class' require 'active_support/core_ext/kernel/singleton_class'
require 'thread'
module ActiveSupport module ActiveSupport
# Callbacks are code hooks that are run at key points in an object's lifecycle. # Callbacks are code hooks that are run at key points in an object's lifecycle.
@ -510,6 +510,7 @@ module ActiveSupport
}.merge!(config) }.merge!(config)
@chain = [] @chain = []
@callbacks = nil @callbacks = nil
@mutex = Mutex.new
end end
def each(&block); @chain.each(&block); end def each(&block); @chain.each(&block); end
@ -535,13 +536,14 @@ module ActiveSupport
def initialize_copy(other) def initialize_copy(other)
@callbacks = nil @callbacks = nil
@chain = other.chain.dup @chain = other.chain.dup
@mutex = Mutex.new
end end
def compile def compile
return @callbacks if @callbacks @callbacks || @mutex.synchronize do
@callbacks ||= @chain.reverse.inject(Filters::ENDING) do |chain, callback|
@callbacks = @chain.reverse.inject(Filters::ENDING) do |chain, callback| callback.apply chain
callback.apply chain end
end end
end end