From 8b900a7105eb4ae6957017a99a89e276186c287c Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 5 May 2020 21:33:23 +0900 Subject: [PATCH] Avoid `synchronize { }` call only for MRI https://github.com/rails/rails/commit/5e0ef9ca7abb85343bc9dc3436350b91eb37ce01 https://github.com/rails/rails/commit/dd1aa7388990509796065d4cd19534d4017b42bc https://github.com/rails/rails/commit/ea791e53f9edbe1e2d2ca779f5ce20b27320581f --- actionpack/lib/action_dispatch/http/response.rb | 10 +++++----- .../abstract/connection_pool.rb | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index c9c750c716..7464309b1e 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -215,14 +215,14 @@ module ActionDispatch # :nodoc: end end - if defined?(JRUBY_VERSION) - def sending?; synchronize { @sending }; end - def committed?; synchronize { @committed }; end - def sent?; synchronize { @sent }; end - else + if RUBY_ENGINE == "ruby" def sending?; @sending; end def committed?; @committed; end def sent?; @sent; end + else + def sending?; synchronize { @sending }; end + def committed?; synchronize { @committed }; end + def sent?; synchronize { @sent }; end end # Sets the HTTP status code. diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index bd5892d30f..add1bf454a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -116,16 +116,16 @@ module ActiveRecord end end - if defined?(JRUBY_VERSION) + if RUBY_ENGINE == "ruby" + # Returns the number of threads currently waiting on this queue. + attr_reader :num_waiting + else # Returns the number of threads currently waiting on this queue. def num_waiting synchronize do @num_waiting end end - else - # Returns the number of threads currently waiting on this queue. - attr_reader :num_waiting end # Add +element+ to the queue. Never blocks. @@ -826,12 +826,12 @@ module ActiveRecord end def with_new_connections_blocked - if defined?(JRUBY_VERSION) + if RUBY_ENGINE == "ruby" + @threads_blocking_new_connections += 1 + else synchronize do @threads_blocking_new_connections += 1 end - else - @threads_blocking_new_connections += 1 end yield