diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-05 05:19:15 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-05 05:19:15 +0000 |
commit | 7fecd1e75d80131c36d6615c38a6b869dfa81054 (patch) | |
tree | 167736f801f910a63552d400aacc8ecda1007591 /lib | |
parent | ef8139db13537ab2e4ef7d141076cfedb3cf8282 (diff) | |
download | ruby-7fecd1e75d80131c36d6615c38a6b869dfa81054.tar.gz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rake/cpu_counter.rb | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/rake/cpu_counter.rb b/lib/rake/cpu_counter.rb index 6d0b878b19..f29778ed5d 100644 --- a/lib/rake/cpu_counter.rb +++ b/lib/rake/cpu_counter.rb @@ -1,8 +1,3 @@ -require 'rbconfig' - -# TODO: replace with IO.popen using array-style arguments in Rake 11 -require 'open3' - module Rake # Based on a script at: @@ -18,6 +13,26 @@ module Rake default 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 if defined?(Java::Java) count_via_java_runtime @@ -44,18 +59,6 @@ module Rake 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 Java::Java.lang.Runtime.getRuntime.availableProcessors rescue StandardError @@ -118,5 +121,5 @@ module Rake out.eof? ? nil : command end end - end + end; end |