diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-14 16:18:11 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-14 16:18:11 -0700 |
commit | 132db318b324ab3829362d4aa29f1eef75ed1aea (patch) | |
tree | 7fae0d3cd515535b6837dae4be3937bf74017659 /activesupport | |
parent | d2405a0aab6b246842163cdb1a40d2d300b7b879 (diff) | |
download | rails-132db318b324ab3829362d4aa29f1eef75ed1aea.tar.gz rails-132db318b324ab3829362d4aa29f1eef75ed1aea.tar.bz2 rails-132db318b324ab3829362d4aa29f1eef75ed1aea.zip |
make the compile method thread safe
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 12 |
1 files changed, 7 insertions, 5 deletions
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 |