diff options
author | Matthew Draper <matthew@trebex.net> | 2015-07-09 04:33:14 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-07-09 04:33:14 +0930 |
commit | 0b93c48bbe74857ead9a9ef56b35f87965edbb49 (patch) | |
tree | 1861b4f1710fda3a66a8eedd94ae8e6cec44fc18 /activesupport/lib/active_support/dependencies.rb | |
parent | 48a735aff7032afaf5534613b10c635acead042a (diff) | |
download | rails-0b93c48bbe74857ead9a9ef56b35f87965edbb49.tar.gz rails-0b93c48bbe74857ead9a9ef56b35f87965edbb49.tar.bz2 rails-0b93c48bbe74857ead9a9ef56b35f87965edbb49.zip |
Document ShareLock and the Interlock
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 2a0e06495f..770c845435 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -22,6 +22,23 @@ module ActiveSupport #:nodoc: mattr_accessor :interlock self.interlock = Interlock.new + # :doc: + + # Execute the supplied block without interference from any + # concurrent loads + def self.run_interlock + Dependencies.interlock.running { yield } + end + + # Execute the supplied block while holding an exclusive lock, + # preventing any other thread from being inside a #run_interlock + # block at the same time + def self.load_interlock + Dependencies.interlock.loading { yield } + end + + # :nodoc: + # Should we turn on Ruby warnings on the first load of dependent files? mattr_accessor :warnings_on_first_load self.warnings_on_first_load = false @@ -238,7 +255,7 @@ module ActiveSupport #:nodoc: end def load_dependency(file) - Dependencies.interlock.loading do + Dependencies.load_interlock do if Dependencies.load? && ActiveSupport::Dependencies.constant_watch_stack.watching? Dependencies.new_constants_in(Object) { yield } else @@ -331,7 +348,7 @@ module ActiveSupport #:nodoc: def clear log_call - Dependencies.interlock.loading do + Dependencies.load_interlock do loaded.clear loading.clear remove_unloadable_constants! @@ -344,7 +361,7 @@ module ActiveSupport #:nodoc: expanded = File.expand_path(file_name) return if loaded.include?(expanded) - Dependencies.interlock.loading do + Dependencies.load_interlock do # Maybe it got loaded while we were waiting for our lock: return if loaded.include?(expanded) |