Skip to content

Commit a68f114

Browse files
authored
Merge pull request rails#38069 from y-yagi/make_load_interlock_aware_monitor_work_in_ruby27
Make `LoadInterlockAwareMonitor` work in Ruby 2.7
2 parents 0b3c710 + 4f4f8a7 commit a68f114

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,29 @@ module Concurrency
77
# A monitor that will permit dependency loading while blocked waiting for
88
# the lock.
99
class LoadInterlockAwareMonitor < Monitor
10+
EXCEPTION_NEVER = { Exception => :never }.freeze
11+
EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze
12+
private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE
13+
1014
# Enters an exclusive section, but allows dependency loading while blocked
1115
def mon_enter
1216
mon_try_enter ||
1317
ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
1418
end
19+
20+
def synchronize
21+
Thread.handle_interrupt(EXCEPTION_NEVER) do
22+
mon_enter
23+
24+
begin
25+
Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
26+
yield
27+
end
28+
ensure
29+
mon_exit
30+
end
31+
end
32+
end
1533
end
1634
end
1735
end

0 commit comments

Comments
 (0)