concurrent-ruby 1.0.5 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +65 -0
- data/Gemfile +39 -0
- data/{LICENSE.txt → LICENSE.md} +2 -0
- data/README.md +207 -105
- data/Rakefile +314 -0
- data/ext/concurrent-ruby/ConcurrentRubyService.java +17 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/AtomicReferenceLibrary.java +175 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JRubyMapBackendLibrary.java +248 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java +93 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java +113 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaSemaphoreLibrary.java +159 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/SynchronizationLibrary.java +306 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/ConcurrentHashMap.java +31 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/ConcurrentHashMapV8.java +3863 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/LongAdder.java +203 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/Striped64.java +342 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/ConcurrentHashMapV8.java +3800 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/LongAdder.java +204 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/Striped64.java +291 -0
- data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166y/ThreadLocalRandom.java +199 -0
- data/lib/concurrent/agent.rb +7 -7
- data/lib/concurrent/array.rb +59 -32
- data/lib/concurrent/async.rb +4 -4
- data/lib/concurrent/atom.rb +9 -9
- data/lib/concurrent/atomic/atomic_boolean.rb +24 -20
- data/lib/concurrent/atomic/atomic_fixnum.rb +27 -23
- data/lib/concurrent/atomic/atomic_markable_reference.rb +164 -0
- data/lib/concurrent/atomic/atomic_reference.rb +185 -32
- data/lib/concurrent/atomic/count_down_latch.rb +6 -6
- data/lib/concurrent/atomic/cyclic_barrier.rb +1 -1
- data/lib/concurrent/atomic/event.rb +1 -1
- data/lib/concurrent/atomic/java_count_down_latch.rb +9 -6
- data/lib/concurrent/atomic/mutex_atomic_boolean.rb +2 -0
- data/lib/concurrent/atomic/mutex_count_down_latch.rb +1 -0
- data/lib/concurrent/atomic/read_write_lock.rb +2 -1
- data/lib/concurrent/atomic/reentrant_read_write_lock.rb +3 -1
- data/lib/concurrent/atomic/semaphore.rb +8 -8
- data/lib/concurrent/atomic/thread_local_var.rb +7 -7
- data/lib/concurrent/atomic_reference/mutex_atomic.rb +3 -8
- data/lib/concurrent/atomic_reference/numeric_cas_wrapper.rb +1 -1
- data/lib/concurrent/atomics.rb +0 -43
- data/lib/concurrent/collection/lock_free_stack.rb +158 -0
- data/lib/concurrent/collection/map/atomic_reference_map_backend.rb +3 -3
- data/lib/concurrent/collection/map/non_concurrent_map_backend.rb +1 -2
- data/lib/concurrent/collection/non_concurrent_priority_queue.rb +29 -29
- data/lib/concurrent/concern/dereferenceable.rb +1 -1
- data/lib/concurrent/concern/logging.rb +6 -1
- data/lib/concurrent/concern/observable.rb +7 -7
- data/lib/concurrent/concurrent_ruby.jar +0 -0
- data/lib/concurrent/configuration.rb +1 -6
- data/lib/concurrent/constants.rb +1 -1
- data/lib/concurrent/dataflow.rb +2 -1
- data/lib/concurrent/delay.rb +9 -7
- data/lib/concurrent/exchanger.rb +21 -25
- data/lib/concurrent/executor/abstract_executor_service.rb +2 -2
- data/lib/concurrent/executor/cached_thread_pool.rb +1 -1
- data/lib/concurrent/executor/executor_service.rb +15 -15
- data/lib/concurrent/executor/fixed_thread_pool.rb +18 -18
- data/lib/concurrent/executor/java_thread_pool_executor.rb +10 -7
- data/lib/concurrent/executor/single_thread_executor.rb +2 -2
- data/lib/concurrent/executor/thread_pool_executor.rb +6 -6
- data/lib/concurrent/executor/timer_set.rb +1 -1
- data/lib/concurrent/future.rb +4 -1
- data/lib/concurrent/hash.rb +53 -30
- data/lib/concurrent/ivar.rb +5 -6
- data/lib/concurrent/map.rb +178 -81
- data/lib/concurrent/maybe.rb +1 -1
- data/lib/concurrent/mutable_struct.rb +15 -14
- data/lib/concurrent/mvar.rb +2 -2
- data/lib/concurrent/promise.rb +53 -21
- data/lib/concurrent/promises.rb +1936 -0
- data/lib/concurrent/re_include.rb +58 -0
- data/lib/concurrent/set.rb +66 -0
- data/lib/concurrent/settable_struct.rb +1 -0
- data/lib/concurrent/synchronization/abstract_lockable_object.rb +5 -5
- data/lib/concurrent/synchronization/abstract_struct.rb +6 -4
- data/lib/concurrent/synchronization/lockable_object.rb +6 -6
- data/lib/concurrent/synchronization/{mri_lockable_object.rb → mutex_lockable_object.rb} +19 -14
- data/lib/concurrent/synchronization/object.rb +8 -4
- data/lib/concurrent/synchronization/truffleruby_object.rb +46 -0
- data/lib/concurrent/synchronization/volatile.rb +11 -9
- data/lib/concurrent/synchronization.rb +4 -5
- data/lib/concurrent/thread_safe/util/data_structures.rb +63 -0
- data/lib/concurrent/thread_safe/util/striped64.rb +9 -4
- data/lib/concurrent/timer_task.rb +5 -2
- data/lib/concurrent/tuple.rb +1 -1
- data/lib/concurrent/tvar.rb +2 -2
- data/lib/concurrent/utility/193.rb +17 -0
- data/lib/concurrent/utility/at_exit.rb +1 -1
- data/lib/concurrent/utility/engine.rb +4 -4
- data/lib/concurrent/utility/monotonic_time.rb +3 -3
- data/lib/concurrent/utility/native_extension_loader.rb +31 -33
- data/lib/concurrent/utility/processor_counter.rb +0 -2
- data/lib/concurrent/version.rb +2 -2
- data/lib/concurrent-ruby.rb +1 -0
- data/lib/concurrent.rb +26 -20
- metadata +33 -18
- data/lib/concurrent/atomic_reference/concurrent_update_error.rb +0 -8
- data/lib/concurrent/atomic_reference/direct_update.rb +0 -81
- data/lib/concurrent/atomic_reference/jruby+truffle.rb +0 -2
- data/lib/concurrent/atomic_reference/jruby.rb +0 -16
- data/lib/concurrent/atomic_reference/rbx.rb +0 -22
- data/lib/concurrent/atomic_reference/ruby.rb +0 -32
- data/lib/concurrent/edge.rb +0 -26
- data/lib/concurrent/lazy_register.rb +0 -81
- data/lib/concurrent/synchronization/truffle_lockable_object.rb +0 -9
- data/lib/concurrent/synchronization/truffle_object.rb +0 -31
- data/lib/concurrent/thread_safe/util/array_hash_rbx.rb +0 -30
@@ -4,7 +4,7 @@ module Concurrent
|
|
4
4
|
|
5
5
|
###################################################################
|
6
6
|
|
7
|
-
# @!macro
|
7
|
+
# @!macro executor_service_method_post
|
8
8
|
#
|
9
9
|
# Submit a task to the executor for asynchronous processing.
|
10
10
|
#
|
@@ -17,7 +17,7 @@ module Concurrent
|
|
17
17
|
#
|
18
18
|
# @raise [ArgumentError] if no task is given
|
19
19
|
|
20
|
-
# @!macro
|
20
|
+
# @!macro executor_service_method_left_shift
|
21
21
|
#
|
22
22
|
# Submit a task to the executor for asynchronous processing.
|
23
23
|
#
|
@@ -25,13 +25,13 @@ module Concurrent
|
|
25
25
|
#
|
26
26
|
# @return [self] returns itself
|
27
27
|
|
28
|
-
# @!macro
|
28
|
+
# @!macro executor_service_method_can_overflow_question
|
29
29
|
#
|
30
30
|
# Does the task queue have a maximum size?
|
31
31
|
#
|
32
32
|
# @return [Boolean] True if the task queue has a maximum size else false.
|
33
33
|
|
34
|
-
# @!macro
|
34
|
+
# @!macro executor_service_method_serialized_question
|
35
35
|
#
|
36
36
|
# Does this executor guarantee serialization of its operations?
|
37
37
|
#
|
@@ -41,7 +41,7 @@ module Concurrent
|
|
41
41
|
|
42
42
|
###################################################################
|
43
43
|
|
44
|
-
# @!macro
|
44
|
+
# @!macro executor_service_public_api
|
45
45
|
#
|
46
46
|
# @!method post(*args, &task)
|
47
47
|
# @!macro executor_service_method_post
|
@@ -57,23 +57,23 @@ module Concurrent
|
|
57
57
|
|
58
58
|
###################################################################
|
59
59
|
|
60
|
-
# @!macro
|
60
|
+
# @!macro executor_service_attr_reader_fallback_policy
|
61
61
|
# @return [Symbol] The fallback policy in effect. Either `:abort`, `:discard`, or `:caller_runs`.
|
62
62
|
|
63
|
-
# @!macro
|
63
|
+
# @!macro executor_service_method_shutdown
|
64
64
|
#
|
65
65
|
# Begin an orderly shutdown. Tasks already in the queue will be executed,
|
66
66
|
# but no new tasks will be accepted. Has no additional effect if the
|
67
67
|
# thread pool is not running.
|
68
68
|
|
69
|
-
# @!macro
|
69
|
+
# @!macro executor_service_method_kill
|
70
70
|
#
|
71
71
|
# Begin an immediate shutdown. In-progress tasks will be allowed to
|
72
72
|
# complete but enqueued tasks will be dismissed and no new tasks
|
73
73
|
# will be accepted. Has no additional effect if the thread pool is
|
74
74
|
# not running.
|
75
75
|
|
76
|
-
# @!macro
|
76
|
+
# @!macro executor_service_method_wait_for_termination
|
77
77
|
#
|
78
78
|
# Block until executor shutdown is complete or until `timeout` seconds have
|
79
79
|
# passed.
|
@@ -85,31 +85,31 @@ module Concurrent
|
|
85
85
|
#
|
86
86
|
# @return [Boolean] `true` if shutdown complete or false on `timeout`
|
87
87
|
|
88
|
-
# @!macro
|
88
|
+
# @!macro executor_service_method_running_question
|
89
89
|
#
|
90
90
|
# Is the executor running?
|
91
91
|
#
|
92
92
|
# @return [Boolean] `true` when running, `false` when shutting down or shutdown
|
93
93
|
|
94
|
-
# @!macro
|
94
|
+
# @!macro executor_service_method_shuttingdown_question
|
95
95
|
#
|
96
96
|
# Is the executor shuttingdown?
|
97
97
|
#
|
98
98
|
# @return [Boolean] `true` when not running and not shutdown, else `false`
|
99
99
|
|
100
|
-
# @!macro
|
100
|
+
# @!macro executor_service_method_shutdown_question
|
101
101
|
#
|
102
102
|
# Is the executor shutdown?
|
103
103
|
#
|
104
104
|
# @return [Boolean] `true` when shutdown, `false` when shutting down or running
|
105
105
|
|
106
|
-
# @!macro
|
106
|
+
# @!macro executor_service_method_auto_terminate_question
|
107
107
|
#
|
108
108
|
# Is the executor auto-terminate when the application exits?
|
109
109
|
#
|
110
110
|
# @return [Boolean] `true` when auto-termination is enabled else `false`.
|
111
111
|
|
112
|
-
# @!macro
|
112
|
+
# @!macro executor_service_method_auto_terminate_setter
|
113
113
|
#
|
114
114
|
# Set the auto-terminate behavior for this executor.
|
115
115
|
#
|
@@ -119,7 +119,7 @@ module Concurrent
|
|
119
119
|
|
120
120
|
###################################################################
|
121
121
|
|
122
|
-
# @!macro
|
122
|
+
# @!macro abstract_executor_service_public_api
|
123
123
|
#
|
124
124
|
# @!macro executor_service_public_api
|
125
125
|
#
|
@@ -3,44 +3,44 @@ require 'concurrent/executor/thread_pool_executor'
|
|
3
3
|
|
4
4
|
module Concurrent
|
5
5
|
|
6
|
-
# @!macro
|
6
|
+
# @!macro thread_pool_executor_constant_default_max_pool_size
|
7
7
|
# Default maximum number of threads that will be created in the pool.
|
8
8
|
|
9
|
-
# @!macro
|
9
|
+
# @!macro thread_pool_executor_constant_default_min_pool_size
|
10
10
|
# Default minimum number of threads that will be retained in the pool.
|
11
11
|
|
12
|
-
# @!macro
|
12
|
+
# @!macro thread_pool_executor_constant_default_max_queue_size
|
13
13
|
# Default maximum number of tasks that may be added to the task queue.
|
14
14
|
|
15
|
-
# @!macro
|
15
|
+
# @!macro thread_pool_executor_constant_default_thread_timeout
|
16
16
|
# Default maximum number of seconds a thread in the pool may remain idle
|
17
17
|
# before being reclaimed.
|
18
18
|
|
19
|
-
# @!macro
|
19
|
+
# @!macro thread_pool_executor_attr_reader_max_length
|
20
20
|
# The maximum number of threads that may be created in the pool.
|
21
21
|
# @return [Integer] The maximum number of threads that may be created in the pool.
|
22
22
|
|
23
|
-
# @!macro
|
23
|
+
# @!macro thread_pool_executor_attr_reader_min_length
|
24
24
|
# The minimum number of threads that may be retained in the pool.
|
25
25
|
# @return [Integer] The minimum number of threads that may be retained in the pool.
|
26
26
|
|
27
|
-
# @!macro
|
27
|
+
# @!macro thread_pool_executor_attr_reader_largest_length
|
28
28
|
# The largest number of threads that have been created in the pool since construction.
|
29
29
|
# @return [Integer] The largest number of threads that have been created in the pool since construction.
|
30
30
|
|
31
|
-
# @!macro
|
31
|
+
# @!macro thread_pool_executor_attr_reader_scheduled_task_count
|
32
32
|
# The number of tasks that have been scheduled for execution on the pool since construction.
|
33
33
|
# @return [Integer] The number of tasks that have been scheduled for execution on the pool since construction.
|
34
34
|
|
35
|
-
# @!macro
|
35
|
+
# @!macro thread_pool_executor_attr_reader_completed_task_count
|
36
36
|
# The number of tasks that have been completed by the pool since construction.
|
37
37
|
# @return [Integer] The number of tasks that have been completed by the pool since construction.
|
38
38
|
|
39
|
-
# @!macro
|
39
|
+
# @!macro thread_pool_executor_attr_reader_idletime
|
40
40
|
# The number of seconds that a thread may be idle before being reclaimed.
|
41
41
|
# @return [Integer] The number of seconds that a thread may be idle before being reclaimed.
|
42
42
|
|
43
|
-
# @!macro
|
43
|
+
# @!macro thread_pool_executor_attr_reader_max_queue
|
44
44
|
# The maximum number of tasks that may be waiting in the work queue at any one time.
|
45
45
|
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
|
46
46
|
# accordance with the configured `fallback_policy`.
|
@@ -49,15 +49,15 @@ module Concurrent
|
|
49
49
|
# When the queue size reaches `max_queue` subsequent tasks will be rejected in
|
50
50
|
# accordance with the configured `fallback_policy`.
|
51
51
|
|
52
|
-
# @!macro
|
52
|
+
# @!macro thread_pool_executor_attr_reader_length
|
53
53
|
# The number of threads currently in the pool.
|
54
54
|
# @return [Integer] The number of threads currently in the pool.
|
55
55
|
|
56
|
-
# @!macro
|
56
|
+
# @!macro thread_pool_executor_attr_reader_queue_length
|
57
57
|
# The number of tasks in the queue awaiting execution.
|
58
58
|
# @return [Integer] The number of tasks in the queue awaiting execution.
|
59
59
|
|
60
|
-
# @!macro
|
60
|
+
# @!macro thread_pool_executor_attr_reader_remaining_capacity
|
61
61
|
# Number of tasks that may be enqueued before reaching `max_queue` and rejecting
|
62
62
|
# new tasks. A value of -1 indicates that the queue may grow without bound.
|
63
63
|
#
|
@@ -68,7 +68,7 @@ module Concurrent
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
# @!macro
|
71
|
+
# @!macro thread_pool_executor_public_api
|
72
72
|
#
|
73
73
|
# @!macro abstract_executor_service_public_api
|
74
74
|
#
|
@@ -108,7 +108,7 @@ module Concurrent
|
|
108
108
|
|
109
109
|
|
110
110
|
|
111
|
-
# @!macro
|
111
|
+
# @!macro thread_pool_options
|
112
112
|
#
|
113
113
|
# **Thread Pool Options**
|
114
114
|
#
|
@@ -169,7 +169,7 @@ module Concurrent
|
|
169
169
|
|
170
170
|
|
171
171
|
|
172
|
-
# @!macro
|
172
|
+
# @!macro fixed_thread_pool
|
173
173
|
#
|
174
174
|
# A thread pool that reuses a fixed number of threads operating off an unbounded queue.
|
175
175
|
# At any point, at most `num_threads` will be active processing tasks. When all threads are busy new
|
@@ -182,7 +182,7 @@ module Concurrent
|
|
182
182
|
# @!macro thread_pool_options
|
183
183
|
class FixedThreadPool < ThreadPoolExecutor
|
184
184
|
|
185
|
-
# @!macro
|
185
|
+
# @!macro fixed_thread_pool_method_initialize
|
186
186
|
#
|
187
187
|
# Create a new thread pool.
|
188
188
|
#
|
@@ -90,10 +90,10 @@ if Concurrent.on_jruby?
|
|
90
90
|
private
|
91
91
|
|
92
92
|
def ns_initialize(opts)
|
93
|
-
min_length
|
94
|
-
max_length
|
95
|
-
idletime
|
96
|
-
@max_queue
|
93
|
+
min_length = opts.fetch(:min_threads, DEFAULT_MIN_POOL_SIZE).to_i
|
94
|
+
max_length = opts.fetch(:max_threads, DEFAULT_MAX_POOL_SIZE).to_i
|
95
|
+
idletime = opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT).to_i
|
96
|
+
@max_queue = opts.fetch(:max_queue, DEFAULT_MAX_QUEUE_SIZE).to_i
|
97
97
|
@fallback_policy = opts.fetch(:fallback_policy, :abort)
|
98
98
|
|
99
99
|
raise ArgumentError.new("`max_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}") if max_length < DEFAULT_MIN_POOL_SIZE
|
@@ -109,9 +109,12 @@ if Concurrent.on_jruby?
|
|
109
109
|
end
|
110
110
|
|
111
111
|
@executor = java.util.concurrent.ThreadPoolExecutor.new(
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
min_length,
|
113
|
+
max_length,
|
114
|
+
idletime,
|
115
|
+
java.util.concurrent.TimeUnit::SECONDS,
|
116
|
+
queue,
|
117
|
+
FALLBACK_POLICY_CLASSES[@fallback_policy].new)
|
115
118
|
|
116
119
|
self.auto_terminate = opts.fetch(:auto_terminate, true)
|
117
120
|
end
|
@@ -14,7 +14,7 @@ module Concurrent
|
|
14
14
|
end
|
15
15
|
private_constant :SingleThreadExecutorImplementation
|
16
16
|
|
17
|
-
# @!macro
|
17
|
+
# @!macro single_thread_executor
|
18
18
|
#
|
19
19
|
# A thread pool with a single thread an unlimited queue. Should the thread
|
20
20
|
# die for any reason it will be removed and replaced, thus ensuring that
|
@@ -35,7 +35,7 @@ module Concurrent
|
|
35
35
|
# @!macro abstract_executor_service_public_api
|
36
36
|
class SingleThreadExecutor < SingleThreadExecutorImplementation
|
37
37
|
|
38
|
-
# @!macro
|
38
|
+
# @!macro single_thread_executor_method_initialize
|
39
39
|
#
|
40
40
|
# Create a new thread pool.
|
41
41
|
#
|
@@ -15,7 +15,7 @@ module Concurrent
|
|
15
15
|
end
|
16
16
|
private_constant :ThreadPoolExecutorImplementation
|
17
17
|
|
18
|
-
# @!macro
|
18
|
+
# @!macro thread_pool_executor
|
19
19
|
#
|
20
20
|
# An abstraction composed of one or more threads and a task queue. Tasks
|
21
21
|
# (blocks or `proc` objects) are submitted to the pool and added to the queue.
|
@@ -55,12 +55,12 @@ module Concurrent
|
|
55
55
|
# @!macro thread_pool_executor_public_api
|
56
56
|
class ThreadPoolExecutor < ThreadPoolExecutorImplementation
|
57
57
|
|
58
|
-
# @!macro
|
58
|
+
# @!macro thread_pool_executor_method_initialize
|
59
59
|
#
|
60
60
|
# Create a new thread pool.
|
61
|
-
#
|
61
|
+
#
|
62
62
|
# @param [Hash] opts the options which configure the thread pool.
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# @option opts [Integer] :max_threads (DEFAULT_MAX_POOL_SIZE) the maximum
|
65
65
|
# number of threads to be created
|
66
66
|
# @option opts [Integer] :min_threads (DEFAULT_MIN_POOL_SIZE) When a new task is submitted
|
@@ -73,12 +73,12 @@ module Concurrent
|
|
73
73
|
# @option opts [Symbol] :fallback_policy (:abort) the policy for handling new
|
74
74
|
# tasks that are received when the queue size has reached
|
75
75
|
# `max_queue` or the executor has shut down
|
76
|
-
#
|
76
|
+
#
|
77
77
|
# @raise [ArgumentError] if `:max_threads` is less than one
|
78
78
|
# @raise [ArgumentError] if `:min_threads` is less than zero
|
79
79
|
# @raise [ArgumentError] if `:fallback_policy` is not one of the values specified
|
80
80
|
# in `FALLBACK_POLICIES`
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html
|
83
83
|
|
84
84
|
# @!method initialize(opts = {})
|
@@ -20,7 +20,7 @@ module Concurrent
|
|
20
20
|
|
21
21
|
# Create a new set of timed tasks.
|
22
22
|
#
|
23
|
-
# @!macro
|
23
|
+
# @!macro executor_options
|
24
24
|
#
|
25
25
|
# @param [Hash] opts the options used to specify the executor on which to perform actions
|
26
26
|
# @option opts [Executor] :executor when set use the given `Executor` instance.
|
data/lib/concurrent/future.rb
CHANGED
@@ -6,9 +6,12 @@ require 'concurrent/executor/safe_task_executor'
|
|
6
6
|
|
7
7
|
require 'concurrent/options'
|
8
8
|
|
9
|
+
# TODO (pitr-ch 14-Mar-2017): deprecate, Future, Promise, etc.
|
10
|
+
|
11
|
+
|
9
12
|
module Concurrent
|
10
13
|
|
11
|
-
# {include:file:
|
14
|
+
# {include:file:docs-source/future.md}
|
12
15
|
#
|
13
16
|
# @!macro copy_options
|
14
17
|
#
|
data/lib/concurrent/hash.rb
CHANGED
@@ -2,35 +2,58 @@ require 'concurrent/utility/engine'
|
|
2
2
|
require 'concurrent/thread_safe/util'
|
3
3
|
|
4
4
|
module Concurrent
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
5
|
+
|
6
|
+
# @!macro concurrent_hash
|
7
|
+
#
|
8
|
+
# A thread-safe subclass of Hash. This version locks against the object
|
9
|
+
# itself for every method call, ensuring only one thread can be reading
|
10
|
+
# or writing at a time. This includes iteration methods like `#each`,
|
11
|
+
# which takes the lock repeatedly when reading an item.
|
12
|
+
#
|
13
|
+
# @see http://ruby-doc.org/core-2.2.0/Hash.html Ruby standard library `Hash`
|
14
|
+
|
15
|
+
# @!macro internal_implementation_note
|
16
|
+
HashImplementation = case
|
17
|
+
when Concurrent.on_cruby?
|
18
|
+
# Because MRI never runs code in parallel, the existing
|
19
|
+
# non-thread-safe structures should usually work fine.
|
20
|
+
::Hash
|
21
|
+
|
22
|
+
when Concurrent.on_jruby?
|
23
|
+
require 'jruby/synchronized'
|
24
|
+
|
25
|
+
class JRubyHash < ::Hash
|
26
|
+
include JRuby::Synchronized
|
27
|
+
end
|
28
|
+
JRubyHash
|
29
|
+
|
30
|
+
when Concurrent.on_rbx?
|
31
|
+
require 'monitor'
|
32
|
+
require 'concurrent/thread_safe/util/data_structures'
|
33
|
+
|
34
|
+
class RbxHash < ::Hash
|
35
|
+
end
|
36
|
+
ThreadSafe::Util.make_synchronized_on_rbx RbxHash
|
37
|
+
RbxHash
|
38
|
+
|
39
|
+
when Concurrent.on_truffleruby?
|
40
|
+
require 'concurrent/thread_safe/util/data_structures'
|
41
|
+
|
42
|
+
class TruffleRubyHash < ::Hash
|
43
|
+
end
|
44
|
+
|
45
|
+
ThreadSafe::Util.make_synchronized_on_truffleruby TruffleRubyHash
|
46
|
+
TruffleRubyHash
|
47
|
+
|
48
|
+
else
|
49
|
+
warn 'Possibly unsupported Ruby implementation'
|
50
|
+
::Hash
|
51
|
+
end
|
52
|
+
private_constant :HashImplementation
|
53
|
+
|
54
|
+
# @!macro concurrent_hash
|
55
|
+
class Hash < HashImplementation
|
35
56
|
end
|
57
|
+
|
36
58
|
end
|
59
|
+
|
data/lib/concurrent/ivar.rb
CHANGED
@@ -98,10 +98,10 @@ module Concurrent
|
|
98
98
|
observer
|
99
99
|
end
|
100
100
|
|
101
|
-
# @!macro
|
101
|
+
# @!macro ivar_set_method
|
102
102
|
# Set the `IVar` to a value and wake or notify all threads waiting on it.
|
103
103
|
#
|
104
|
-
# @!macro
|
104
|
+
# @!macro ivar_set_parameters_and_exceptions
|
105
105
|
# @param [Object] value the value to store in the `IVar`
|
106
106
|
# @yield A block operation to use for setting the value
|
107
107
|
# @raise [ArgumentError] if both a value and a block are given
|
@@ -124,7 +124,7 @@ module Concurrent
|
|
124
124
|
self
|
125
125
|
end
|
126
126
|
|
127
|
-
# @!macro
|
127
|
+
# @!macro ivar_fail_method
|
128
128
|
# Set the `IVar` to failed due to some error and wake or notify all threads waiting on it.
|
129
129
|
#
|
130
130
|
# @param [Object] reason for the failure
|
@@ -157,9 +157,8 @@ module Concurrent
|
|
157
157
|
self.observers = Collection::CopyOnWriteObserverSet.new
|
158
158
|
set_deref_options(opts)
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
else
|
160
|
+
@state = :pending
|
161
|
+
if value != NULL
|
163
162
|
ns_complete_without_notification(true, value, nil)
|
164
163
|
end
|
165
164
|
end
|