concurrent-ruby 0.8.0.pre2-java → 0.9.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -3
- data/README.md +111 -55
- data/lib/concurrent.rb +90 -14
- data/lib/concurrent/async.rb +143 -51
- data/lib/concurrent/atom.rb +131 -0
- data/lib/concurrent/atomic/atomic_boolean.rb +57 -107
- data/lib/concurrent/atomic/atomic_fixnum.rb +73 -101
- data/lib/concurrent/atomic/atomic_reference.rb +49 -0
- data/lib/concurrent/atomic/condition.rb +23 -12
- data/lib/concurrent/atomic/count_down_latch.rb +23 -21
- data/lib/concurrent/atomic/cyclic_barrier.rb +47 -47
- data/lib/concurrent/atomic/event.rb +33 -42
- data/lib/concurrent/atomic/read_write_lock.rb +252 -0
- data/lib/concurrent/atomic/semaphore.rb +64 -89
- data/lib/concurrent/atomic/thread_local_var.rb +130 -58
- data/lib/concurrent/atomic/thread_local_var/weak_key_map.rb +236 -0
- data/lib/concurrent/atomic_reference/direct_update.rb +34 -3
- data/lib/concurrent/atomic_reference/jruby.rb +6 -3
- data/lib/concurrent/atomic_reference/mutex_atomic.rb +17 -39
- data/lib/concurrent/atomic_reference/numeric_cas_wrapper.rb +3 -0
- data/lib/concurrent/atomic_reference/rbx.rb +4 -1
- data/lib/concurrent/atomic_reference/ruby.rb +6 -3
- data/lib/concurrent/atomics.rb +74 -4
- data/lib/concurrent/collection/copy_on_notify_observer_set.rb +115 -0
- data/lib/concurrent/collection/copy_on_write_observer_set.rb +119 -0
- data/lib/concurrent/collection/priority_queue.rb +300 -245
- data/lib/concurrent/concern/deprecation.rb +34 -0
- data/lib/concurrent/concern/dereferenceable.rb +88 -0
- data/lib/concurrent/concern/logging.rb +27 -0
- data/lib/concurrent/concern/obligation.rb +228 -0
- data/lib/concurrent/concern/observable.rb +85 -0
- data/lib/concurrent/configuration.rb +234 -109
- data/lib/concurrent/dataflow.rb +2 -3
- data/lib/concurrent/delay.rb +141 -50
- data/lib/concurrent/edge.rb +30 -0
- data/lib/concurrent/errors.rb +19 -7
- data/lib/concurrent/exchanger.rb +25 -1
- data/lib/concurrent/executor/cached_thread_pool.rb +51 -33
- data/lib/concurrent/executor/executor.rb +46 -299
- data/lib/concurrent/executor/executor_service.rb +521 -0
- data/lib/concurrent/executor/fixed_thread_pool.rb +196 -23
- data/lib/concurrent/executor/immediate_executor.rb +9 -9
- data/lib/concurrent/executor/indirect_immediate_executor.rb +4 -3
- data/lib/concurrent/executor/java_single_thread_executor.rb +17 -16
- data/lib/concurrent/executor/java_thread_pool_executor.rb +55 -102
- data/lib/concurrent/executor/ruby_single_thread_executor.rb +14 -16
- data/lib/concurrent/executor/ruby_thread_pool_executor.rb +250 -166
- data/lib/concurrent/executor/safe_task_executor.rb +5 -4
- data/lib/concurrent/executor/serialized_execution.rb +22 -18
- data/lib/concurrent/executor/{per_thread_executor.rb → simple_executor_service.rb} +29 -20
- data/lib/concurrent/executor/single_thread_executor.rb +32 -21
- data/lib/concurrent/executor/thread_pool_executor.rb +73 -60
- data/lib/concurrent/executor/timer_set.rb +96 -84
- data/lib/concurrent/executors.rb +1 -1
- data/lib/concurrent/future.rb +71 -38
- data/lib/concurrent/immutable_struct.rb +89 -0
- data/lib/concurrent/ivar.rb +152 -60
- data/lib/concurrent/lazy_register.rb +40 -20
- data/lib/concurrent/maybe.rb +226 -0
- data/lib/concurrent/mutable_struct.rb +227 -0
- data/lib/concurrent/mvar.rb +44 -43
- data/lib/concurrent/promise.rb +229 -136
- data/lib/concurrent/scheduled_task.rb +341 -43
- data/lib/concurrent/settable_struct.rb +127 -0
- data/lib/concurrent/synchronization.rb +17 -0
- data/lib/concurrent/synchronization/abstract_object.rb +163 -0
- data/lib/concurrent/synchronization/abstract_struct.rb +158 -0
- data/lib/concurrent/synchronization/condition.rb +53 -0
- data/lib/concurrent/synchronization/java_object.rb +34 -0
- data/lib/concurrent/synchronization/lock.rb +32 -0
- data/lib/concurrent/synchronization/monitor_object.rb +26 -0
- data/lib/concurrent/synchronization/mutex_object.rb +43 -0
- data/lib/concurrent/synchronization/object.rb +78 -0
- data/lib/concurrent/synchronization/rbx_object.rb +75 -0
- data/lib/concurrent/timer_task.rb +92 -103
- data/lib/concurrent/tvar.rb +42 -38
- data/lib/concurrent/utilities.rb +3 -1
- data/lib/concurrent/utility/at_exit.rb +97 -0
- data/lib/concurrent/utility/engine.rb +44 -0
- data/lib/concurrent/utility/monotonic_time.rb +59 -0
- data/lib/concurrent/utility/native_extension_loader.rb +56 -0
- data/lib/concurrent/utility/processor_counter.rb +156 -0
- data/lib/concurrent/utility/timeout.rb +18 -14
- data/lib/concurrent/utility/timer.rb +11 -6
- data/lib/concurrent/version.rb +2 -1
- data/lib/concurrent_ruby.rb +1 -0
- data/lib/concurrent_ruby_ext.jar +0 -0
- metadata +46 -66
- data/lib/concurrent/actor.rb +0 -103
- data/lib/concurrent/actor/behaviour.rb +0 -70
- data/lib/concurrent/actor/behaviour/abstract.rb +0 -48
- data/lib/concurrent/actor/behaviour/awaits.rb +0 -21
- data/lib/concurrent/actor/behaviour/buffer.rb +0 -54
- data/lib/concurrent/actor/behaviour/errors_on_unknown_message.rb +0 -12
- data/lib/concurrent/actor/behaviour/executes_context.rb +0 -18
- data/lib/concurrent/actor/behaviour/linking.rb +0 -45
- data/lib/concurrent/actor/behaviour/pausing.rb +0 -77
- data/lib/concurrent/actor/behaviour/removes_child.rb +0 -16
- data/lib/concurrent/actor/behaviour/sets_results.rb +0 -36
- data/lib/concurrent/actor/behaviour/supervised.rb +0 -59
- data/lib/concurrent/actor/behaviour/supervising.rb +0 -34
- data/lib/concurrent/actor/behaviour/terminates_children.rb +0 -13
- data/lib/concurrent/actor/behaviour/termination.rb +0 -54
- data/lib/concurrent/actor/context.rb +0 -154
- data/lib/concurrent/actor/core.rb +0 -217
- data/lib/concurrent/actor/default_dead_letter_handler.rb +0 -9
- data/lib/concurrent/actor/envelope.rb +0 -41
- data/lib/concurrent/actor/errors.rb +0 -27
- data/lib/concurrent/actor/internal_delegations.rb +0 -49
- data/lib/concurrent/actor/public_delegations.rb +0 -40
- data/lib/concurrent/actor/reference.rb +0 -81
- data/lib/concurrent/actor/root.rb +0 -37
- data/lib/concurrent/actor/type_check.rb +0 -48
- data/lib/concurrent/actor/utils.rb +0 -10
- data/lib/concurrent/actor/utils/ad_hoc.rb +0 -21
- data/lib/concurrent/actor/utils/balancer.rb +0 -42
- data/lib/concurrent/actor/utils/broadcast.rb +0 -52
- data/lib/concurrent/actor/utils/pool.rb +0 -59
- data/lib/concurrent/actress.rb +0 -3
- data/lib/concurrent/agent.rb +0 -209
- data/lib/concurrent/atomic.rb +0 -92
- data/lib/concurrent/atomic/copy_on_notify_observer_set.rb +0 -118
- data/lib/concurrent/atomic/copy_on_write_observer_set.rb +0 -117
- data/lib/concurrent/atomic/synchronization.rb +0 -51
- data/lib/concurrent/channel/buffered_channel.rb +0 -85
- data/lib/concurrent/channel/channel.rb +0 -41
- data/lib/concurrent/channel/unbuffered_channel.rb +0 -35
- data/lib/concurrent/channel/waitable_list.rb +0 -40
- data/lib/concurrent/channels.rb +0 -5
- data/lib/concurrent/collection/blocking_ring_buffer.rb +0 -71
- data/lib/concurrent/collection/ring_buffer.rb +0 -59
- data/lib/concurrent/collections.rb +0 -3
- data/lib/concurrent/dereferenceable.rb +0 -108
- data/lib/concurrent/executor/java_cached_thread_pool.rb +0 -32
- data/lib/concurrent/executor/java_fixed_thread_pool.rb +0 -31
- data/lib/concurrent/executor/ruby_cached_thread_pool.rb +0 -29
- data/lib/concurrent/executor/ruby_fixed_thread_pool.rb +0 -32
- data/lib/concurrent/executor/ruby_thread_pool_worker.rb +0 -73
- data/lib/concurrent/logging.rb +0 -20
- data/lib/concurrent/obligation.rb +0 -171
- data/lib/concurrent/observable.rb +0 -73
- data/lib/concurrent/options_parser.rb +0 -48
- data/lib/concurrent/utility/processor_count.rb +0 -152
- data/lib/extension_helper.rb +0 -37
@@ -1,48 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
|
3
|
-
# A mixin module for parsing options hashes related to gem-level configuration.
|
4
|
-
module OptionsParser
|
5
|
-
|
6
|
-
# Get the requested `Executor` based on the values set in the options hash.
|
7
|
-
#
|
8
|
-
# @param [Hash] opts the options defining the requested executor
|
9
|
-
# @option opts [Executor] :executor (`nil`) when set use the given `Executor` instance
|
10
|
-
# @option opts [Boolean] :operation (`false`) when true use the global operation pool
|
11
|
-
# @option opts [Boolean] :task (`true`) when true use the global task pool
|
12
|
-
#
|
13
|
-
# @return [Executor, nil] the requested thread pool, or nil when no option specified
|
14
|
-
def get_executor_from(opts = {})
|
15
|
-
if opts[:executor]
|
16
|
-
opts[:executor]
|
17
|
-
elsif opts[:operation] == true || opts[:task] == false
|
18
|
-
Concurrent.configuration.global_operation_pool
|
19
|
-
elsif opts[:operation] == false || opts[:task] == true
|
20
|
-
Concurrent.configuration.global_task_pool
|
21
|
-
else
|
22
|
-
nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Get the requested `Executor` based on the values set in the options hash.
|
27
|
-
#
|
28
|
-
# @param [Hash] opts the options defining the requested executor
|
29
|
-
# @option opts [Executor] :task_executor (`nil`) when set use the given `Executor` instance
|
30
|
-
#
|
31
|
-
# @return [Executor] the requested thread pool (default: global task pool)
|
32
|
-
def get_task_executor_from(opts = {})
|
33
|
-
opts[:task_executor] || opts[:executor] || Concurrent.configuration.global_task_pool
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get the requested `Executor` based on the values set in the options hash.
|
37
|
-
#
|
38
|
-
# @param [Hash] opts the options defining the requested executor
|
39
|
-
# @option opts [Executor] :task_executor (`nil`) when set use the given `Executor` instance
|
40
|
-
#
|
41
|
-
# @return [Executor] the requested thread pool (default: global operation pool)
|
42
|
-
def get_operation_executor_from(opts = {})
|
43
|
-
opts[:operation_executor] || opts[:executor] || Concurrent.configuration.global_operation_pool
|
44
|
-
end
|
45
|
-
|
46
|
-
extend self
|
47
|
-
end
|
48
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'concurrent/delay'
|
3
|
-
require 'concurrent/executor/immediate_executor'
|
4
|
-
|
5
|
-
module Concurrent
|
6
|
-
|
7
|
-
class ProcessorCounter
|
8
|
-
def initialize
|
9
|
-
immediate_executor = ImmediateExecutor.new
|
10
|
-
@processor_count = Delay.new(executor: immediate_executor) { compute_processor_count }
|
11
|
-
@physical_processor_count = Delay.new(executor: immediate_executor) { compute_physical_processor_count }
|
12
|
-
end
|
13
|
-
|
14
|
-
# Number of processors seen by the OS and used for process scheduling. For performance
|
15
|
-
# reasons the calculated value will be memoized on the first call.
|
16
|
-
#
|
17
|
-
# When running under JRuby the Java runtime call `java.lang.Runtime.getRuntime.availableProcessors`
|
18
|
-
# will be used. According to the Java documentation this "value may change
|
19
|
-
# during a particular invocation of the virtual machine... [applications]
|
20
|
-
# should therefore occasionally poll this property." Subsequently the result
|
21
|
-
# will NOT be memoized under JRuby.
|
22
|
-
#
|
23
|
-
# On Windows the Win32 API will be queried for the `NumberOfLogicalProcessors from Win32_Processor`.
|
24
|
-
# This will return the total number "logical processors for the current instance of the processor",
|
25
|
-
# which taked into account hyperthreading.
|
26
|
-
#
|
27
|
-
# * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
|
28
|
-
# * BSD: /sbin/sysctl
|
29
|
-
# * Cygwin: /proc/cpuinfo
|
30
|
-
# * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
|
31
|
-
# * HP-UX: /usr/sbin/ioscan
|
32
|
-
# * IRIX: /usr/sbin/sysconf
|
33
|
-
# * Linux: /proc/cpuinfo
|
34
|
-
# * Minix 3+: /proc/cpuinfo
|
35
|
-
# * Solaris: /usr/sbin/psrinfo
|
36
|
-
# * Tru64 UNIX: /usr/sbin/psrinfo
|
37
|
-
# * UnixWare: /usr/sbin/psrinfo
|
38
|
-
#
|
39
|
-
# @return [Integer] number of processors seen by the OS or Java runtime
|
40
|
-
#
|
41
|
-
# @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
|
42
|
-
#
|
43
|
-
# @see http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors()
|
44
|
-
# @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
|
45
|
-
def processor_count
|
46
|
-
@processor_count.value
|
47
|
-
end
|
48
|
-
|
49
|
-
# Number of physical processor cores on the current system. For performance reasons
|
50
|
-
# the calculated value will be memoized on the first call.
|
51
|
-
#
|
52
|
-
# On Windows the Win32 API will be queried for the `NumberOfCores from Win32_Processor`.
|
53
|
-
# This will return the total number "of cores for the current instance of the processor."
|
54
|
-
# On Unix-like operating systems either the `hwprefs` or `sysctl` utility will be called
|
55
|
-
# in a subshell and the returned value will be used. In the rare case where none of these
|
56
|
-
# methods work or an exception is raised the function will simply return 1.
|
57
|
-
#
|
58
|
-
# @return [Integer] number physical processor cores on the current system
|
59
|
-
#
|
60
|
-
# @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
|
61
|
-
#
|
62
|
-
# @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
|
63
|
-
# @see http://www.unix.com/man-page/osx/1/HWPREFS/
|
64
|
-
# @see http://linux.die.net/man/8/sysctl
|
65
|
-
def physical_processor_count
|
66
|
-
@physical_processor_count.value
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def compute_processor_count
|
72
|
-
if RUBY_PLATFORM == 'java'
|
73
|
-
java.lang.Runtime.getRuntime.availableProcessors
|
74
|
-
else
|
75
|
-
os_name = RbConfig::CONFIG["target_os"]
|
76
|
-
if os_name =~ /mingw|mswin/
|
77
|
-
require 'win32ole'
|
78
|
-
result = WIN32OLE.connect("winmgmts://").ExecQuery(
|
79
|
-
"select NumberOfLogicalProcessors from Win32_Processor")
|
80
|
-
result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
|
81
|
-
elsif File.readable?("/proc/cpuinfo")
|
82
|
-
IO.read("/proc/cpuinfo").scan(/^processor/).size
|
83
|
-
elsif File.executable?("/usr/bin/hwprefs")
|
84
|
-
IO.popen("/usr/bin/hwprefs thread_count").read.to_i
|
85
|
-
elsif File.executable?("/usr/sbin/psrinfo")
|
86
|
-
IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
|
87
|
-
elsif File.executable?("/usr/sbin/ioscan")
|
88
|
-
IO.popen("/usr/sbin/ioscan -kC processor") do |out|
|
89
|
-
out.read.scan(/^.*processor/).size
|
90
|
-
end
|
91
|
-
elsif File.executable?("/usr/sbin/pmcycles")
|
92
|
-
IO.popen("/usr/sbin/pmcycles -m").read.count("\n")
|
93
|
-
elsif File.executable?("/usr/sbin/lsdev")
|
94
|
-
IO.popen("/usr/sbin/lsdev -Cc processor -S 1").read.count("\n")
|
95
|
-
elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
|
96
|
-
IO.popen("/usr/sbin/sysconf NPROC_ONLN").read.to_i
|
97
|
-
elsif File.executable?("/usr/sbin/sysctl")
|
98
|
-
IO.popen("/usr/sbin/sysctl -n hw.ncpu").read.to_i
|
99
|
-
elsif File.executable?("/sbin/sysctl")
|
100
|
-
IO.popen("/sbin/sysctl -n hw.ncpu").read.to_i
|
101
|
-
else
|
102
|
-
1
|
103
|
-
end
|
104
|
-
end
|
105
|
-
rescue
|
106
|
-
return 1
|
107
|
-
end
|
108
|
-
|
109
|
-
def compute_physical_processor_count
|
110
|
-
ppc = case RbConfig::CONFIG["target_os"]
|
111
|
-
when /darwin1/
|
112
|
-
IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
|
113
|
-
when /linux/
|
114
|
-
cores = {} # unique physical ID / core ID combinations
|
115
|
-
phy = 0
|
116
|
-
IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
|
117
|
-
if ln.start_with?("physical")
|
118
|
-
phy = ln[/\d+/]
|
119
|
-
elsif ln.start_with?("core")
|
120
|
-
cid = phy + ":" + ln[/\d+/]
|
121
|
-
cores[cid] = true if not cores[cid]
|
122
|
-
end
|
123
|
-
end
|
124
|
-
cores.count
|
125
|
-
when /mswin|mingw/
|
126
|
-
require 'win32ole'
|
127
|
-
result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
|
128
|
-
"select NumberOfCores from Win32_Processor")
|
129
|
-
result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
|
130
|
-
else
|
131
|
-
processor_count
|
132
|
-
end
|
133
|
-
# fall back to logical count if physical info is invalid
|
134
|
-
ppc > 0 ? ppc : processor_count
|
135
|
-
rescue
|
136
|
-
return 1
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# create the default ProcessorCounter on load
|
141
|
-
@processor_counter = ProcessorCounter.new
|
142
|
-
singleton_class.send :attr_reader, :processor_counter
|
143
|
-
|
144
|
-
def self.processor_count
|
145
|
-
processor_counter.processor_count
|
146
|
-
end
|
147
|
-
|
148
|
-
def self.physical_processor_count
|
149
|
-
processor_counter.physical_processor_count
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
data/lib/extension_helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
|
3
|
-
@@c_ext_loaded ||= false
|
4
|
-
@@java_ext_loaded ||= false
|
5
|
-
|
6
|
-
# @!visibility private
|
7
|
-
def self.allow_c_extensions?
|
8
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
|
9
|
-
end
|
10
|
-
|
11
|
-
# @!visibility private
|
12
|
-
def self.jruby?
|
13
|
-
RUBY_PLATFORM == 'java'
|
14
|
-
end
|
15
|
-
|
16
|
-
if allow_c_extensions? && !@@c_ext_loaded
|
17
|
-
begin
|
18
|
-
require 'concurrent/extension'
|
19
|
-
@@c_ext_loaded = true
|
20
|
-
rescue LoadError
|
21
|
-
# may be a Windows cross-compiled native gem
|
22
|
-
begin
|
23
|
-
require "#{RUBY_VERSION[0..2]}/concurrent/extension"
|
24
|
-
@@c_ext_loaded = true
|
25
|
-
rescue LoadError
|
26
|
-
warn 'Performance on MRI may be improved with the concurrent-ruby-ext gem. Please see http://concurrent-ruby.com'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
elsif jruby? && !@@java_ext_loaded
|
30
|
-
begin
|
31
|
-
require 'concurrent_ruby_ext'
|
32
|
-
@@java_ext_loaded = true
|
33
|
-
rescue LoadError
|
34
|
-
warn 'Attempted to load Java extensions on unsupported platform. Continuing with pure-Ruby.'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|