From 132db318b324ab3829362d4aa29f1eef75ed1aea Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 14 May 2013 16:18:11 -0700 Subject: make the compile method thread safe --- activesupport/lib/active_support/callbacks.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index e6e2fcfb3f..1386c22f45 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -1,9 +1,9 @@ -require 'thread_safe' require 'active_support/concern' require 'active_support/descendants_tracker' require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/singleton_class' +require 'thread' module ActiveSupport # Callbacks are code hooks that are run at key points in an object's lifecycle. @@ -510,6 +510,7 @@ module ActiveSupport }.merge!(config) @chain = [] @callbacks = nil + @mutex = Mutex.new end def each(&block); @chain.each(&block); end @@ -535,13 +536,14 @@ module ActiveSupport def initialize_copy(other) @callbacks = nil @chain = other.chain.dup + @mutex = Mutex.new end def compile - return @callbacks if @callbacks - - @callbacks = @chain.reverse.inject(Filters::ENDING) do |chain, callback| - callback.apply chain + @callbacks || @mutex.synchronize do + @callbacks ||= @chain.reverse.inject(Filters::ENDING) do |chain, callback| + callback.apply chain + end end end -- cgit v1.2.3