add Rscons.n_threads
This commit is contained in:
1 parent
695bf84092
commit
dab870854a
2 files changed
+108
No files matched your search
@@ -41,6 +41,10 @@ module Rscons
|
||||
|
||||
class << self
|
||||
|
||||
# @return [Integer]
|
||||
# The number of threads to use when scheduling subprocesses.
|
||||
attr_accessor :n_threads
|
||||
|
||||
# Remove all generated files.
|
||||
#
|
||||
# @return [void]
|
||||
@@ -147,7 +151,45 @@ module Rscons
|
||||
@command_executer = val
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Determine the number of threads to use by default.
|
||||
#
|
||||
# @return [Integer]
|
||||
# The number of threads to use by default.
|
||||
def determine_n_threads
|
||||
# If the user specifies the number of threads in the environment, then
|
||||
# respect that.
|
||||
if ENV["RSCONS_NTHREADS"] =~ /^(\d+)$/
|
||||
return $1.to_i
|
||||
end
|
||||
|
||||
# Otherwise try to figure out how many threads are available on the
|
||||
# host hardware.
|
||||
begin
|
||||
case RbConfig::CONFIG["host_os"]
|
||||
when /linux/
|
||||
return File.read("/proc/cpuinfo").scan(/^processor\s*:/).size
|
||||
when /mswin|mingw/
|
||||
if `wmic cpu get NumberOfLogicalProcessors /value` =~ /NumberOfLogicalProcessors=(\d+)/
|
||||
return $1.to_i
|
||||
end
|
||||
when /darwin/
|
||||
if `sysctl -n hw.ncpu` =~ /(\d+)/
|
||||
return $1.to_i
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
|
||||
# If we can't figure it out, default to 1.
|
||||
1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@n_threads = determine_n_threads
|
||||
|
||||
end
|
||||
|
||||
# Unbuffer $stdout
|
||||
|
||||
Reference in new issue
Block a user