Skip to content

Commit

Permalink
Merge pull request #38069 from y-yagi/make_load_interlock_aware_monit…
Browse files Browse the repository at this point in the history
…or_work_in_ruby27

Make `LoadInterlockAwareMonitor` work in Ruby 2.7
  • Loading branch information
y-yagi authored and eileencodes committed Apr 13, 2022
1 parent c9b6eeb commit de20f93
Showing 1 changed file with 18 additions and 0 deletions.
Expand Up @@ -7,11 +7,29 @@ module Concurrency
# A monitor that will permit dependency loading while blocked waiting for
# the lock.
class LoadInterlockAwareMonitor < Monitor
EXCEPTION_NEVER = { Exception => :never }.freeze
EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze
private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE

# Enters an exclusive section, but allows dependency loading while blocked
def mon_enter
mon_try_enter ||
ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
end

def synchronize
Thread.handle_interrupt(EXCEPTION_NEVER) do
mon_enter

begin
Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
yield
end
ensure
mon_exit
end
end
end
end
end
end

0 comments on commit de20f93

Please sign in to comment.