mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
cpu_counter.rb: separate implementations
* lib/rake/cpu_counter.rb (Rake::CpuCounter#count): separate Etc.nprocessors implementation, and if is is available other utility methods are never used. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ef8139db13
commit
7fecd1e75d
1 changed files with 21 additions and 18 deletions
|
@ -1,8 +1,3 @@
|
||||||
require 'rbconfig'
|
|
||||||
|
|
||||||
# TODO: replace with IO.popen using array-style arguments in Rake 11
|
|
||||||
require 'open3'
|
|
||||||
|
|
||||||
module Rake
|
module Rake
|
||||||
|
|
||||||
# Based on a script at:
|
# Based on a script at:
|
||||||
|
@ -18,6 +13,26 @@ module Rake
|
||||||
default
|
default
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
require 'etc'
|
||||||
|
rescue LoadError
|
||||||
|
else
|
||||||
|
if Etc.respond_to?(:nprocessors)
|
||||||
|
def count
|
||||||
|
return Etc.nprocessors
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
unless Rake::CpuCounter.method_defined?(:count)
|
||||||
|
Rake::CpuCounter.class_eval <<-'end;', __FILE__, __LINE__+1
|
||||||
|
require 'rbconfig'
|
||||||
|
|
||||||
|
# TODO: replace with IO.popen using array-style arguments in Rake 11
|
||||||
|
require 'open3'
|
||||||
|
|
||||||
def count
|
def count
|
||||||
if defined?(Java::Java)
|
if defined?(Java::Java)
|
||||||
count_via_java_runtime
|
count_via_java_runtime
|
||||||
|
@ -44,18 +59,6 @@ module Rake
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
|
||||||
require 'etc'
|
|
||||||
rescue LoadError
|
|
||||||
else
|
|
||||||
if Etc.respond_to?(:nprocessors)
|
|
||||||
undef count
|
|
||||||
def count
|
|
||||||
return Etc.nprocessors
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def count_via_java_runtime
|
def count_via_java_runtime
|
||||||
Java::Java.lang.Runtime.getRuntime.availableProcessors
|
Java::Java.lang.Runtime.getRuntime.availableProcessors
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
|
@ -118,5 +121,5 @@ module Rake
|
||||||
out.eof? ? nil : command
|
out.eof? ? nil : command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end;
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue