diff options
Diffstat (limited to 'activesupport/lib/active_support/dependencies/interlock.rb')
-rw-r--r-- | activesupport/lib/active_support/dependencies/interlock.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/dependencies/interlock.rb b/activesupport/lib/active_support/dependencies/interlock.rb index c3601bac13..035802d680 100644 --- a/activesupport/lib/active_support/dependencies/interlock.rb +++ b/activesupport/lib/active_support/dependencies/interlock.rb @@ -13,6 +13,16 @@ module ActiveSupport end end + # Attempt to obtain a "loading" (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 + yield + end + end + def start_running @lock.start_sharing end |