1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Avoid creating Hash objects per each mon_synchronize call (#2393)

This commit is contained in:
Akira Matsuda 2019-08-20 22:08:41 +09:00 committed by GitHub
parent af12172035
commit 9557069299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2019-08-31 04:40:14 +09:00
Merged-By: amatsuda <ronnie@dio.jp>

View file

@ -87,6 +87,9 @@
# MonitorMixin module.
#
module MonitorMixin
EXCEPTION_NEVER = {Exception => :never}.freeze
EXCEPTION_IMMEDIATE = {Exception => :immediate}.freeze
#
# FIXME: This isn't documented in Nutshell.
#
@ -103,11 +106,11 @@ module MonitorMixin
# even if no other thread doesn't signal.
#
def wait(timeout = nil)
Thread.handle_interrupt(Exception => :never) do
Thread.handle_interrupt(EXCEPTION_NEVER) do
@monitor.__send__(:mon_check_owner)
count = @monitor.__send__(:mon_exit_for_cond)
begin
Thread.handle_interrupt(Exception => :immediate) do
Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
@cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
end
return true
@ -227,11 +230,11 @@ module MonitorMixin
def mon_synchronize
# Prevent interrupt on handling interrupts; for example timeout errors
# it may break locking state.
Thread.handle_interrupt(Exception => :never){ mon_enter }
Thread.handle_interrupt(EXCEPTION_NEVER){ mon_enter }
begin
yield
ensure
Thread.handle_interrupt(Exception => :never){ mon_exit }
Thread.handle_interrupt(EXCEPTION_NEVER){ mon_exit }
end
end
alias synchronize mon_synchronize