3
3
require 'concurrent/delay'
4
4
5
5
module Concurrent
6
+ # @!visibility private
6
7
module Utility
7
8
8
9
# @!visibility private
@@ -12,43 +13,10 @@ def initialize
12
13
@physical_processor_count = Delay . new { compute_physical_processor_count }
13
14
end
14
15
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()
31
16
def processor_count
32
17
@processor_count . value
33
18
end
34
19
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
52
20
def physical_processor_count
53
21
@physical_processor_count . value
54
22
end
@@ -99,10 +67,43 @@ def compute_physical_processor_count
99
67
@processor_counter = Utility ::ProcessorCounter . new
100
68
singleton_class . send :attr_reader , :processor_counter
101
69
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()
102
86
def self . processor_count
103
87
processor_counter . processor_count
104
88
end
105
89
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
106
107
def self . physical_processor_count
107
108
processor_counter . physical_processor_count
108
109
end
0 commit comments