Skip to content

Commit

Permalink
Adding thread exclusivity to memory and cpu reading
Browse files Browse the repository at this point in the history
git-svn-id: http://reductivelabs.com/svn/facter/trunk@147 1f5c1d6a-bddf-0310-8f58-fc49e503516a
  • Loading branch information
luke committed Jun 27, 2006
1 parent ace180f commit c2aa508
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions lib/facter/memory.rb
Expand Up @@ -17,11 +17,15 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA

module Facter::Memory
require 'thread'

def self.meminfo_number(tag)
memsize = ""
File.readlines("/proc/meminfo").each do |l|
if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/
memsize = scale_number($1.to_f, $2)
Thread::exclusive do
File.readlines("/proc/meminfo").each do |l|
if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/
memsize = scale_number($1.to_f, $2)
end
end
end

Expand Down
16 changes: 10 additions & 6 deletions lib/facter/processor.rb
Expand Up @@ -18,15 +18,19 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
#

require 'thread'

if Facter.kernel == "Linux"
processor_num = -1
processor_list = []
File.readlines("/proc/cpuinfo").each do |l|
if l =~ /processor\s+:\s+(\d+)/
processor_num = $1.to_i
elsif l =~ /model name\s+:\s+(.*)\s*$/
processor_list[processor_num] = $1 unless processor_num == -1
processor_num = -1
Thread::exclusive do
File.readlines("/proc/cpuinfo").each do |l|
if l =~ /processor\s+:\s+(\d+)/
processor_num = $1.to_i
elsif l =~ /model name\s+:\s+(.*)\s*$/
processor_list[processor_num] = $1 unless processor_num == -1
processor_num = -1
end
end
end

Expand Down

0 comments on commit c2aa508

Please sign in to comment.