aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/dependencies
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2015-07-20 08:09:21 +0930
committerMatthew Draper <matthew@trebex.net>2015-07-20 09:14:10 +0930
commitbd31aec9c33453e0ba96aec614e56958784e6b8d (patch)
tree58cdcf70d61a52bd4df139c8cefbdebe3bd06621 /activesupport/lib/active_support/dependencies
parent6ffec3c16c0ee0b0ab4643907af1f2ed80a71a9a (diff)
downloadrails-bd31aec9c33453e0ba96aec614e56958784e6b8d.tar.gz
rails-bd31aec9c33453e0ba96aec614e56958784e6b8d.tar.bz2
rails-bd31aec9c33453e0ba96aec614e56958784e6b8d.zip
We need stricter locking before we can unload
Specifically, the "loose upgrades" behaviour that allows us to obtain an exclusive right to load things while other requests are in progress (but waiting on the exclusive lock for themselves) prevents us from treating load & unload interchangeably: new things appearing is fine, but they do *not* expect previously-present constants to vanish. We can still use loose upgrades for unloading -- once someone has decided to unload, they don't really care if someone else gets there first -- it just needs to be tracked separately.
Diffstat (limited to 'activesupport/lib/active_support/dependencies')
-rw-r--r--activesupport/lib/active_support/dependencies/interlock.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/dependencies/interlock.rb b/activesupport/lib/active_support/dependencies/interlock.rb
index 148212c951..fbeb904684 100644
--- a/activesupport/lib/active_support/dependencies/interlock.rb
+++ b/activesupport/lib/active_support/dependencies/interlock.rb
@@ -4,21 +4,27 @@ module ActiveSupport #:nodoc:
module Dependencies #:nodoc:
class Interlock
def initialize # :nodoc:
- @lock = ActiveSupport::Concurrency::ShareLock.new(true)
+ @lock = ActiveSupport::Concurrency::ShareLock.new
end
def loading
- @lock.exclusive do
+ @lock.exclusive(purpose: :load, compatible: [:load]) do
yield
end
end
- # Attempt to obtain a "loading" (exclusive) lock. If possible,
+ def unloading
+ @lock.exclusive(purpose: :unload, compatible: [:load, :unload]) do
+ yield
+ end
+ end
+
+ # Attempt to obtain an "unloading" (exclusive) lock. If possible,
# execute the supplied block while holding the lock. If there is
# concurrent activity, return immediately (without executing the
# block) instead of waiting.
- def attempt_loading
- @lock.exclusive(true) do
+ def attempt_unloading
+ @lock.exclusive(purpose: :unload, compatible: [:load, :unload], no_wait: true) do
yield
end
end