33require 'concurrent/delay'
44
55module Concurrent
6+ # @!visibility private
67 module Utility
78
89 # @!visibility private
@@ -12,43 +13,10 @@ def initialize
1213 @physical_processor_count = Delay . new { compute_physical_processor_count }
1314 end
1415
15- # Number of processors seen by the OS and used for process scheduling. For
16- # performance reasons the calculated value will be memoized on the first
17- # call.
18- #
19- # When running under JRuby the Java runtime call
20- # `java.lang.Runtime.getRuntime.availableProcessors` will be used. According
21- # to the Java documentation this "value may change during a particular
22- # invocation of the virtual machine... [applications] should therefore
23- # occasionally poll this property." Subsequently the result will NOT be
24- # memoized under JRuby.
25- #
26- # Otherwise Ruby's Etc.nprocessors will be used.
27- #
28- # @return [Integer] number of processors seen by the OS or Java runtime
29- #
30- # @see http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors()
3116 def processor_count
3217 @processor_count . value
3318 end
3419
35- # Number of physical processor cores on the current system. For performance
36- # reasons the calculated value will be memoized on the first call.
37- #
38- # On Windows the Win32 API will be queried for the `NumberOfCores from
39- # Win32_Processor`. This will return the total number "of cores for the
40- # current instance of the processor." On Unix-like operating systems either
41- # the `hwprefs` or `sysctl` utility will be called in a subshell and the
42- # returned value will be used. In the rare case where none of these methods
43- # work or an exception is raised the function will simply return 1.
44- #
45- # @return [Integer] number physical processor cores on the current system
46- #
47- # @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
48- #
49- # @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
50- # @see http://www.unix.com/man-page/osx/1/HWPREFS/
51- # @see http://linux.die.net/man/8/sysctl
5220 def physical_processor_count
5321 @physical_processor_count . value
5422 end
@@ -99,10 +67,43 @@ def compute_physical_processor_count
9967 @processor_counter = Utility ::ProcessorCounter . new
10068 singleton_class . send :attr_reader , :processor_counter
10169
70+ # Number of processors seen by the OS and used for process scheduling. For
71+ # performance reasons the calculated value will be memoized on the first
72+ # call.
73+ #
74+ # When running under JRuby the Java runtime call
75+ # `java.lang.Runtime.getRuntime.availableProcessors` will be used. According
76+ # to the Java documentation this "value may change during a particular
77+ # invocation of the virtual machine... [applications] should therefore
78+ # occasionally poll this property." Subsequently the result will NOT be
79+ # memoized under JRuby.
80+ #
81+ # Otherwise Ruby's Etc.nprocessors will be used.
82+ #
83+ # @return [Integer] number of processors seen by the OS or Java runtime
84+ #
85+ # @see http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors()
10286 def self . processor_count
10387 processor_counter . processor_count
10488 end
10589
90+ # Number of physical processor cores on the current system. For performance
91+ # reasons the calculated value will be memoized on the first call.
92+ #
93+ # On Windows the Win32 API will be queried for the `NumberOfCores from
94+ # Win32_Processor`. This will return the total number "of cores for the
95+ # current instance of the processor." On Unix-like operating systems either
96+ # the `hwprefs` or `sysctl` utility will be called in a subshell and the
97+ # returned value will be used. In the rare case where none of these methods
98+ # work or an exception is raised the function will simply return 1.
99+ #
100+ # @return [Integer] number physical processor cores on the current system
101+ #
102+ # @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
103+ #
104+ # @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
105+ # @see http://www.unix.com/man-page/osx/1/HWPREFS/
106+ # @see http://linux.die.net/man/8/sysctl
106107 def self . physical_processor_count
107108 processor_counter . physical_processor_count
108109 end
0 commit comments