Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make the compile method thread safe

  • Loading branch information...
commit 132db318b324ab3829362d4aa29f1eef75ed1aea 1 parent d2405a0
@tenderlove tenderlove authored
Showing with 7 additions and 5 deletions.
  1. +7 −5 activesupport/lib/active_support/callbacks.rb
View
12 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 @@ def initialize(name, config)
}.merge!(config)
@chain = []
@callbacks = nil
+ @mutex = Mutex.new
end
def each(&block); @chain.each(&block); end
@@ -535,13 +536,14 @@ def clear
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

0 comments on commit 132db31

Please sign in to comment.
Something went wrong with that request. Please try again.