aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/dependencies.rb
diff options
context:
space:
mode:
authorCharles Nutter <charles.nutter@sun.com>2009-01-29 00:31:07 -0600
committerJeremy Kemper <jeremy@bitsweat.net>2009-01-30 08:27:03 -0800
commited0e5640879fd42c00fc5900e0355a0ea1dcf2ad (patch)
tree9e54f95eb28a1473483cfe9c2734a8ff2132ed66 /activesupport/lib/active_support/dependencies.rb
parent2dedb5b03ab88a1c31068f71c8d4cad7c5a5d9ae (diff)
downloadrails-ed0e5640879fd42c00fc5900e0355a0ea1dcf2ad.tar.gz
rails-ed0e5640879fd42c00fc5900e0355a0ea1dcf2ad.tar.bz2
rails-ed0e5640879fd42c00fc5900e0355a0ea1dcf2ad.zip
Ensure constant_watch_stack is protected by a mutex, so concurrent requires do not corrupt it.
[#1816 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r--activesupport/lib/active_support/dependencies.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 7ce9adec2c..2badad5f5f 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -51,6 +51,9 @@ module ActiveSupport #:nodoc:
mattr_accessor :constant_watch_stack
self.constant_watch_stack = []
+ mattr_accessor :constant_watch_stack_mutex
+ self.constant_watch_stack_mutex = Mutex.new
+
# Module includes this module
module ModuleConstMissing #:nodoc:
def self.included(base) #:nodoc:
@@ -509,7 +512,9 @@ module ActiveSupport #:nodoc:
[mod_name, initial_constants]
end
- constant_watch_stack.concat watch_frames
+ constant_watch_stack_mutex.synchronize do
+ constant_watch_stack.concat watch_frames
+ end
aborting = true
begin
@@ -526,8 +531,10 @@ module ActiveSupport #:nodoc:
new_constants = mod.local_constant_names - prior_constants
# Make sure no other frames takes credit for these constants.
- constant_watch_stack.each do |frame_name, constants|
- constants.concat new_constants if frame_name == mod_name
+ constant_watch_stack_mutex.synchronize do
+ constant_watch_stack.each do |frame_name, constants|
+ constants.concat new_constants if frame_name == mod_name
+ end
end
new_constants.collect do |suffix|
@@ -549,8 +556,10 @@ module ActiveSupport #:nodoc:
# Remove the stack frames that we added.
if defined?(watch_frames) && ! watch_frames.blank?
frame_ids = watch_frames.collect { |frame| frame.object_id }
- constant_watch_stack.delete_if do |watch_frame|
- frame_ids.include? watch_frame.object_id
+ constant_watch_stack_mutex.synchronize do
+ constant_watch_stack.delete_if do |watch_frame|
+ frame_ids.include? watch_frame.object_id
+ end
end
end
end