Permalink
Browse files

Revert "Use Facter for CPU count"

This reverts commit e3246ed.

Conflicts:
	lib/celluloid.rb
  • Loading branch information...
tarcieri committed Feb 8, 2013
1 parent c6c9027 commit 568708d627d7bd1ece33c0b00a3f9ac6bf1e0c22
Showing with 20 additions and 21 deletions.
  1. +0 −1 CHANGES.md
  2. +0 −1 celluloid.gemspec
  3. +2 −19 lib/celluloid.rb
  4. +18 −0 lib/celluloid/cpu_counter.rb
View
@@ -40,7 +40,6 @@ HEAD
* Initial thread dumper support
* Remove Celluloid#alive? as it cannot be called in any manner that will ever
return anything but true, rendering it useless
-* Use Facter to get CPU count
0.12.0
------
View
@@ -21,7 +21,6 @@ Gem::Specification.new do |gem|
gem.require_path = 'lib'
gem.add_runtime_dependency 'timers', '>= 1.0.0'
- gem.add_runtime_dependency 'facter', '>= 1.6.12'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
View
@@ -3,15 +3,6 @@
require 'timeout'
require 'set'
-# Fix for Facter < 1.7.0 changing LANG to C
-# https://github.com/puppetlabs/facter/commit/f77584f4
-begin
- old_lang = ENV['LANG']
- require 'facter'
-ensure
- ENV['LANG'] = old_lang
-end
-
module Celluloid
extend self # expose all instance methods as singleton methods
@@ -43,16 +34,7 @@ def uuid
# Obtain the number of CPUs in the system
def cores
- core_count = Facter.fact(:processorcount)
-
- if core_count
- Integer(core_count.value)
- elsif ENV['CELLULOID_NCPUS']
- ENV['CELLULOID_NCPUS']
- else
- Logger.warn "Unable to determine CPU core count, defaulting to 2"
- 2
- end
+ CPUCounter.cores
end
alias_method :cpus, :cores
alias_method :ncpus, :cores
@@ -443,6 +425,7 @@ def future(meth = nil, *args, &block)
require 'celluloid/calls'
require 'celluloid/condition'
require 'celluloid/core_ext'
+require 'celluloid/cpu_counter'
require 'celluloid/fiber'
require 'celluloid/fsm'
require 'celluloid/internal_pool'
@@ -0,0 +1,18 @@
+require 'rbconfig'
+
+module Celluloid
+ module CPUCounter
+ case RbConfig::CONFIG['host_os'][/^[A-Za-z]+/]
+ when 'darwin'
+ @cores = Integer(`sysctl hw.ncpu`[/\d+/])
+ when 'linux'
+ @cores = File.read("/proc/cpuinfo").scan(/(?:core id|processor)\s+: \d+/).uniq.size
+ when 'mingw', 'mswin'
+ @cores = Integer(`SET NUMBER_OF_PROCESSORS`[/\d+/])
+ else
+ @cores = nil
+ end
+
+ def self.cores; @cores; end
+ end
+end

0 comments on commit 568708d

Please sign in to comment.