diff --git a/lib/concurrent/utility/processor_counter.rb b/lib/concurrent/utility/processor_counter.rb index 6d6ae8dea..531ca0a3c 100644 --- a/lib/concurrent/utility/processor_counter.rb +++ b/lib/concurrent/utility/processor_counter.rb @@ -1,3 +1,4 @@ +require 'etc' require 'rbconfig' require 'concurrent/delay' @@ -22,6 +23,8 @@ def initialize # occasionally poll this property." Subsequently the result will NOT be # memoized under JRuby. # + # Ruby's Etc.nprocessors will be used if available (MRI 2.2+). + # # On Windows the Win32 API will be queried for the # `NumberOfLogicalProcessors from Win32_Processor`. This will return the # total number "logical processors for the current instance of the @@ -76,6 +79,8 @@ def physical_processor_count def compute_processor_count if Concurrent.on_jruby? java.lang.Runtime.getRuntime.availableProcessors + elsif Etc.respond_to?(:nprocessors) && (nprocessor = Etc.nprocessors rescue nil) + nprocessor else os_name = RbConfig::CONFIG["target_os"] if os_name =~ /mingw|mswin/