concurrent-ruby 0.9.2-java → 1.0.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 +49 -1
- data/README.md +86 -120
- data/lib/concurrent.rb +14 -5
- data/lib/concurrent/agent.rb +587 -0
- data/lib/concurrent/array.rb +39 -0
- data/lib/concurrent/async.rb +296 -149
- data/lib/concurrent/atom.rb +135 -45
- data/lib/concurrent/atomic/abstract_thread_local_var.rb +38 -0
- data/lib/concurrent/atomic/atomic_boolean.rb +83 -118
- data/lib/concurrent/atomic/atomic_fixnum.rb +101 -163
- data/lib/concurrent/atomic/atomic_reference.rb +1 -8
- data/lib/concurrent/atomic/count_down_latch.rb +62 -103
- data/lib/concurrent/atomic/cyclic_barrier.rb +3 -1
- data/lib/concurrent/atomic/event.rb +1 -1
- data/lib/concurrent/atomic/java_count_down_latch.rb +39 -0
- data/lib/concurrent/atomic/java_thread_local_var.rb +50 -0
- data/lib/concurrent/atomic/mutex_atomic_boolean.rb +60 -0
- data/lib/concurrent/atomic/mutex_atomic_fixnum.rb +91 -0
- data/lib/concurrent/atomic/mutex_count_down_latch.rb +43 -0
- data/lib/concurrent/atomic/mutex_semaphore.rb +115 -0
- data/lib/concurrent/atomic/read_write_lock.rb +5 -4
- data/lib/concurrent/atomic/reentrant_read_write_lock.rb +3 -1
- data/lib/concurrent/atomic/ruby_thread_local_var.rb +172 -0
- data/lib/concurrent/atomic/semaphore.rb +84 -178
- data/lib/concurrent/atomic/thread_local_var.rb +65 -294
- data/lib/concurrent/atomic_reference/jruby+truffle.rb +1 -0
- data/lib/concurrent/atomic_reference/jruby.rb +1 -1
- data/lib/concurrent/atomic_reference/mutex_atomic.rb +14 -8
- data/lib/concurrent/atomic_reference/ruby.rb +1 -1
- data/lib/concurrent/atomics.rb +7 -37
- data/lib/concurrent/collection/copy_on_notify_observer_set.rb +7 -15
- data/lib/concurrent/collection/copy_on_write_observer_set.rb +7 -15
- data/lib/concurrent/collection/java_non_concurrent_priority_queue.rb +84 -0
- data/lib/concurrent/collection/map/atomic_reference_map_backend.rb +927 -0
- data/lib/concurrent/collection/map/mri_map_backend.rb +66 -0
- data/lib/concurrent/collection/map/non_concurrent_map_backend.rb +144 -0
- data/lib/concurrent/collection/map/synchronized_map_backend.rb +86 -0
- data/lib/concurrent/collection/non_concurrent_priority_queue.rb +143 -0
- data/lib/concurrent/collection/ruby_non_concurrent_priority_queue.rb +150 -0
- data/lib/concurrent/concern/dereferenceable.rb +9 -24
- data/lib/concurrent/concern/logging.rb +1 -1
- data/lib/concurrent/concern/obligation.rb +11 -20
- data/lib/concurrent/concern/observable.rb +38 -13
- data/lib/concurrent/configuration.rb +23 -152
- data/lib/concurrent/constants.rb +8 -0
- data/lib/concurrent/delay.rb +14 -12
- data/lib/concurrent/exchanger.rb +339 -41
- data/lib/concurrent/executor/abstract_executor_service.rb +134 -0
- data/lib/concurrent/executor/executor_service.rb +23 -359
- data/lib/concurrent/executor/immediate_executor.rb +3 -2
- data/lib/concurrent/executor/java_executor_service.rb +100 -0
- data/lib/concurrent/executor/java_single_thread_executor.rb +3 -3
- data/lib/concurrent/executor/java_thread_pool_executor.rb +3 -4
- data/lib/concurrent/executor/ruby_executor_service.rb +78 -0
- data/lib/concurrent/executor/ruby_single_thread_executor.rb +10 -66
- data/lib/concurrent/executor/ruby_thread_pool_executor.rb +25 -22
- data/lib/concurrent/executor/safe_task_executor.rb +6 -7
- data/lib/concurrent/executor/serial_executor_service.rb +34 -0
- data/lib/concurrent/executor/serialized_execution.rb +10 -33
- data/lib/concurrent/executor/serialized_execution_delegator.rb +28 -0
- data/lib/concurrent/executor/simple_executor_service.rb +1 -10
- data/lib/concurrent/executor/single_thread_executor.rb +20 -10
- data/lib/concurrent/executor/timer_set.rb +8 -10
- data/lib/concurrent/executors.rb +12 -2
- data/lib/concurrent/future.rb +6 -4
- data/lib/concurrent/hash.rb +35 -0
- data/lib/concurrent/immutable_struct.rb +5 -1
- data/lib/concurrent/ivar.rb +12 -16
- data/lib/concurrent/lazy_register.rb +11 -8
- data/lib/concurrent/map.rb +180 -0
- data/lib/concurrent/maybe.rb +6 -3
- data/lib/concurrent/mutable_struct.rb +7 -6
- data/lib/concurrent/mvar.rb +26 -2
- data/lib/concurrent/{executor/executor.rb → options.rb} +5 -29
- data/lib/concurrent/promise.rb +7 -5
- data/lib/concurrent/scheduled_task.rb +13 -71
- data/lib/concurrent/settable_struct.rb +5 -4
- data/lib/concurrent/synchronization.rb +15 -3
- data/lib/concurrent/synchronization/abstract_lockable_object.rb +98 -0
- data/lib/concurrent/synchronization/abstract_object.rb +7 -146
- data/lib/concurrent/synchronization/abstract_struct.rb +2 -3
- data/lib/concurrent/synchronization/condition.rb +6 -4
- data/lib/concurrent/synchronization/jruby_lockable_object.rb +13 -0
- data/lib/concurrent/synchronization/jruby_object.rb +44 -0
- data/lib/concurrent/synchronization/lock.rb +3 -2
- data/lib/concurrent/synchronization/lockable_object.rb +72 -0
- data/lib/concurrent/synchronization/mri_lockable_object.rb +71 -0
- data/lib/concurrent/synchronization/mri_object.rb +43 -0
- data/lib/concurrent/synchronization/object.rb +140 -73
- data/lib/concurrent/synchronization/rbx_lockable_object.rb +65 -0
- data/lib/concurrent/synchronization/rbx_object.rb +30 -73
- data/lib/concurrent/synchronization/volatile.rb +34 -0
- data/lib/concurrent/thread_safe/synchronized_delegator.rb +50 -0
- data/lib/concurrent/thread_safe/util.rb +14 -0
- data/lib/concurrent/thread_safe/util/adder.rb +74 -0
- data/lib/concurrent/thread_safe/util/array_hash_rbx.rb +30 -0
- data/lib/concurrent/thread_safe/util/cheap_lockable.rb +118 -0
- data/lib/concurrent/thread_safe/util/power_of_two_tuple.rb +38 -0
- data/lib/concurrent/thread_safe/util/striped64.rb +241 -0
- data/lib/concurrent/thread_safe/util/volatile.rb +75 -0
- data/lib/concurrent/thread_safe/util/xor_shift_random.rb +50 -0
- data/lib/concurrent/timer_task.rb +3 -4
- data/lib/concurrent/tuple.rb +86 -0
- data/lib/concurrent/tvar.rb +5 -1
- data/lib/concurrent/utility/at_exit.rb +1 -1
- data/lib/concurrent/utility/engine.rb +4 -0
- data/lib/concurrent/utility/monotonic_time.rb +3 -4
- data/lib/concurrent/utility/native_extension_loader.rb +50 -30
- data/lib/concurrent/version.rb +2 -2
- data/lib/concurrent_ruby_ext.jar +0 -0
- metadata +47 -12
- data/lib/concurrent/atomic/condition.rb +0 -78
- data/lib/concurrent/collection/priority_queue.rb +0 -360
- data/lib/concurrent/synchronization/java_object.rb +0 -34
- data/lib/concurrent/synchronization/monitor_object.rb +0 -27
- data/lib/concurrent/synchronization/mutex_object.rb +0 -43
- data/lib/concurrent/utilities.rb +0 -5
- data/lib/concurrent/utility/timeout.rb +0 -39
- data/lib/concurrent/utility/timer.rb +0 -26
- data/lib/concurrent_ruby.rb +0 -2
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'concurrent/utility/native_extension_loader' # load native part first
|
2
|
-
|
3
|
-
module Concurrent
|
4
|
-
module Synchronization
|
5
|
-
|
6
|
-
if Concurrent.on_jruby?
|
7
|
-
|
8
|
-
# @!visibility private
|
9
|
-
# @!macro internal_implementation_note
|
10
|
-
class JavaObject < AbstractObject
|
11
|
-
|
12
|
-
def self.attr_volatile(*names)
|
13
|
-
names.each do |name|
|
14
|
-
|
15
|
-
ivar = :"@volatile_#{name}"
|
16
|
-
|
17
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
18
|
-
def #{name}
|
19
|
-
instance_variable_get_volatile(:#{ivar})
|
20
|
-
end
|
21
|
-
|
22
|
-
def #{name}=(value)
|
23
|
-
instance_variable_set_volatile(:#{ivar}, value)
|
24
|
-
end
|
25
|
-
RUBY
|
26
|
-
|
27
|
-
end
|
28
|
-
names.map { |n| [n, :"#{n}="] }.flatten
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'monitor'
|
2
|
-
require 'concurrent/synchronization/mutex_object'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
module Synchronization
|
6
|
-
|
7
|
-
# @!visibility private
|
8
|
-
# @!macro internal_implementation_note
|
9
|
-
class MonitorObject < MutexObject
|
10
|
-
def initialize
|
11
|
-
@__lock__ = ::Monitor.new
|
12
|
-
@__condition__ = @__lock__.new_cond
|
13
|
-
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
|
17
|
-
def synchronize
|
18
|
-
@__lock__.synchronize { yield }
|
19
|
-
end
|
20
|
-
|
21
|
-
def ns_wait(timeout = nil)
|
22
|
-
@__condition__.wait timeout
|
23
|
-
self
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Concurrent
|
2
|
-
module Synchronization
|
3
|
-
|
4
|
-
# @!visibility private
|
5
|
-
# @!macro internal_implementation_note
|
6
|
-
class MutexObject < AbstractObject
|
7
|
-
def initialize
|
8
|
-
@__lock__ = ::Mutex.new
|
9
|
-
@__condition__ = ::ConditionVariable.new
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def synchronize
|
15
|
-
if @__lock__.owned?
|
16
|
-
yield
|
17
|
-
else
|
18
|
-
@__lock__.synchronize { yield }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def ns_signal
|
23
|
-
@__condition__.signal
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def ns_broadcast
|
28
|
-
@__condition__.broadcast
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def ns_wait(timeout = nil)
|
33
|
-
@__condition__.wait @__lock__, timeout
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def ensure_ivar_visibility!
|
38
|
-
# relying on undocumented behavior of CRuby, GVL acquire has lock which ensures visibility of ivars
|
39
|
-
# https://github.com/ruby/ruby/blob/ruby_2_2/thread_pthread.c#L204-L211
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/concurrent/utilities.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'thread'
|
3
|
-
|
4
|
-
require 'concurrent/errors'
|
5
|
-
require 'concurrent/concern/deprecation'
|
6
|
-
|
7
|
-
module Concurrent
|
8
|
-
extend Concern::Deprecation
|
9
|
-
|
10
|
-
# [DEPRECATED] Wait the given number of seconds for the block operation to complete.
|
11
|
-
# Intended to be a simpler and more reliable replacement to the Ruby
|
12
|
-
# standard library `Timeout::timeout` method. It does not kill the task
|
13
|
-
# so it finishes anyway. Advantage is that it cannot cause any ugly errors by
|
14
|
-
# killing threads.
|
15
|
-
#
|
16
|
-
# @param [Integer] seconds The number of seconds to wait
|
17
|
-
# @return [Object] The result of the block operation
|
18
|
-
#
|
19
|
-
# @raise [Concurrent::TimeoutError] when the block operation does not complete
|
20
|
-
# in the allotted number of seconds.
|
21
|
-
#
|
22
|
-
# @see http://ruby-doc.org/stdlib-2.2.0/libdoc/timeout/rdoc/Timeout.html Ruby Timeout::timeout
|
23
|
-
#
|
24
|
-
# @!macro monotonic_clock_warning
|
25
|
-
#
|
26
|
-
# @deprecated timeout is deprecated and will be removed
|
27
|
-
def timeout(seconds, &block)
|
28
|
-
deprecated 'timeout is deprecated and will be removed'
|
29
|
-
|
30
|
-
future = Future.execute(&block)
|
31
|
-
future.wait(seconds)
|
32
|
-
if future.complete?
|
33
|
-
future.value!
|
34
|
-
else
|
35
|
-
raise TimeoutError
|
36
|
-
end
|
37
|
-
end
|
38
|
-
module_function :timeout
|
39
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'concurrent/configuration'
|
2
|
-
require 'concurrent/concern/deprecation'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
extend Concern::Deprecation
|
6
|
-
|
7
|
-
# [DEPRECATED] Perform the given operation asynchronously after
|
8
|
-
# the given number of seconds.
|
9
|
-
#
|
10
|
-
# @param [Fixnum] seconds the interval in seconds to wait before executing the task
|
11
|
-
#
|
12
|
-
# @yield the task to execute
|
13
|
-
#
|
14
|
-
# @return [Concurrent::ScheduledTask] IVar representing the task
|
15
|
-
#
|
16
|
-
# @see Concurrent::ScheduledTask
|
17
|
-
#
|
18
|
-
# @deprecated use `ScheduledTask` instead
|
19
|
-
def timer(seconds, *args, &block)
|
20
|
-
deprecated_method 'Concurrent.timer', 'ScheduledTask'
|
21
|
-
raise ArgumentError.new('no block given') unless block_given?
|
22
|
-
raise ArgumentError.new('interval must be greater than or equal to zero') if seconds < 0
|
23
|
-
Concurrent.global_timer_set.post(seconds, *args, &block)
|
24
|
-
end
|
25
|
-
module_function :timer
|
26
|
-
end
|
data/lib/concurrent_ruby.rb
DELETED