diff options
author | Matthew Draper <matthew@trebex.net> | 2014-09-30 01:32:42 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-07-09 02:23:23 +0930 |
commit | c37d47e30897762145835e66ae752cce924af01d (patch) | |
tree | 1b615adf6030b9d77557c88a51497c432a2c58a8 /activesupport/lib/active_support/dependencies | |
parent | c2b5aa041b04e65475dd3ebb9f33a68b26e25895 (diff) | |
download | rails-c37d47e30897762145835e66ae752cce924af01d.tar.gz rails-c37d47e30897762145835e66ae752cce924af01d.tar.bz2 rails-c37d47e30897762145835e66ae752cce924af01d.zip |
Soften the lock requirements when eager_load is disabled
We don't need to fully disable concurrent requests: just ensure that
loads are performed in isolation.
Diffstat (limited to 'activesupport/lib/active_support/dependencies')
-rw-r--r-- | activesupport/lib/active_support/dependencies/interlock.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/dependencies/interlock.rb b/activesupport/lib/active_support/dependencies/interlock.rb new file mode 100644 index 0000000000..c3601bac13 --- /dev/null +++ b/activesupport/lib/active_support/dependencies/interlock.rb @@ -0,0 +1,35 @@ +require 'active_support/concurrency/share_lock' + +module ActiveSupport + module Dependencies #:nodoc: + class Interlock + def initialize + @lock = ActiveSupport::Concurrency::ShareLock.new(true) + end + + def loading + @lock.exclusive do + yield + end + end + + def start_running + @lock.start_sharing + end + + def done_running + @lock.stop_sharing + end + + def running + @lock.sharing do + yield + end + end + + # Match the Mutex API, so we can be used by Rack::Lock + alias :lock :start_running + alias :unlock :done_running + end + end +end |