Skip to content

Commit 37286c5

Browse files
authored
Merge pull request #814 from jhawthorn/etc_nprocessors
Use Ruby's Etc.nprocessors for processor_count if available
2 parents d11b29c + 9c067bb commit 37286c5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/concurrent/utility/processor_counter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'etc'
12
require 'rbconfig'
23
require 'concurrent/delay'
34

@@ -22,6 +23,8 @@ def initialize
2223
# occasionally poll this property." Subsequently the result will NOT be
2324
# memoized under JRuby.
2425
#
26+
# Ruby's Etc.nprocessors will be used if available (MRI 2.2+).
27+
#
2528
# On Windows the Win32 API will be queried for the
2629
# `NumberOfLogicalProcessors from Win32_Processor`. This will return the
2730
# total number "logical processors for the current instance of the
@@ -76,6 +79,8 @@ def physical_processor_count
7679
def compute_processor_count
7780
if Concurrent.on_jruby?
7881
java.lang.Runtime.getRuntime.availableProcessors
82+
elsif Etc.respond_to?(:nprocessors) && (nprocessor = Etc.nprocessors rescue nil)
83+
nprocessor
7984
else
8085
os_name = RbConfig::CONFIG["target_os"]
8186
if os_name =~ /mingw|mswin/

0 commit comments

Comments
 (0)