Skip to content

Commit

Permalink
Avoid forking for processor_count if possible
Browse files Browse the repository at this point in the history
This re-orders the checks for the processor count so that forking is
only done when needed. alpha-linux does not support the processor entry
in /proc/cpuinfo so we must catch that case and fall back to using nproc
which does work on alpha.

This is a rework of ruby-concurrency#549 based on suggestions made in ruby-concurrency#576
  • Loading branch information
graaff authored and pitr-ch committed Nov 10, 2016
1 parent 72b7d71 commit 0371ed4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/concurrent/utility/processor_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def compute_processor_count
result = WIN32OLE.connect("winmgmts://").ExecQuery(
"select NumberOfLogicalProcessors from Win32_Processor")
result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
elsif File.readable?("/proc/cpuinfo") && (cpuinfo_count = IO.read("/proc/cpuinfo").scan(/^processor/).size) > 0
cpuinfo_count
elsif File.executable?("/usr/bin/nproc")
IO.popen("/usr/bin/nproc --all", &:read).to_i
elsif File.readable?("/proc/cpuinfo")
IO.read("/proc/cpuinfo").scan(/^processor/).size
elsif File.executable?("/usr/bin/hwprefs")
IO.popen("/usr/bin/hwprefs thread_count", &:read).to_i
elsif File.executable?("/usr/sbin/psrinfo")
Expand Down

0 comments on commit 0371ed4

Please sign in to comment.