concurrent-ruby 0.9.2-java → 1.0.0-java
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 +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
@@ -9,13 +9,17 @@ module Concurrent
|
|
9
9
|
#
|
10
10
|
# @!macro copy_options
|
11
11
|
module Dereferenceable
|
12
|
+
# NOTE: This module is going away in 2.0. In the mean time we need it to
|
13
|
+
# play nicely with the synchronization layer. This means that the
|
14
|
+
# including class SHOULD be synchronized and it MUST implement a
|
15
|
+
# `#synchronize` method. Not doing so will lead to runtime errors.
|
12
16
|
|
13
17
|
# Return the value this object represents after applying the options specified
|
14
18
|
# by the `#set_deref_options` method.
|
15
19
|
#
|
16
20
|
# @return [Object] the current value of the object
|
17
21
|
def value
|
18
|
-
|
22
|
+
synchronize { apply_deref_options(@value) }
|
19
23
|
end
|
20
24
|
alias_method :deref, :value
|
21
25
|
|
@@ -25,43 +29,24 @@ module Concurrent
|
|
25
29
|
#
|
26
30
|
# @param [Object] value the new value
|
27
31
|
def value=(value)
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
# A mutex lock used for synchronizing thread-safe operations. Methods defined
|
32
|
-
# by `Dereferenceable` are synchronized using the `Mutex` returned from this
|
33
|
-
# method. Operations performed by the including class that operate on the
|
34
|
-
# `@value` instance variable should be locked with this `Mutex`.
|
35
|
-
#
|
36
|
-
# @return [Mutex] the synchronization object
|
37
|
-
def mutex
|
38
|
-
@mutex
|
39
|
-
end
|
40
|
-
|
41
|
-
# Initializes the internal `Mutex`.
|
42
|
-
#
|
43
|
-
# @note This method *must* be called from within the constructor of the including class.
|
44
|
-
#
|
45
|
-
# @see #mutex
|
46
|
-
def init_mutex(mutex = Mutex.new)
|
47
|
-
@mutex = mutex
|
32
|
+
synchronize{ @value = value }
|
48
33
|
end
|
49
34
|
|
50
35
|
# @!macro [attach] dereferenceable_set_deref_options
|
51
36
|
# Set the options which define the operations #value performs before
|
52
37
|
# returning data to the caller (dereferencing).
|
53
|
-
#
|
38
|
+
#
|
54
39
|
# @note Most classes that include this module will call `#set_deref_options`
|
55
40
|
# from within the constructor, thus allowing these options to be set at
|
56
41
|
# object creation.
|
57
|
-
#
|
42
|
+
#
|
58
43
|
# @param [Hash] opts the options defining dereference behavior.
|
59
44
|
# @option opts [String] :dup_on_deref (false) call `#dup` before returning the data
|
60
45
|
# @option opts [String] :freeze_on_deref (false) call `#freeze` before returning the data
|
61
46
|
# @option opts [String] :copy_on_deref (nil) call the given `Proc` passing
|
62
47
|
# the internal value and returning the value returned from the proc
|
63
48
|
def set_deref_options(opts = {})
|
64
|
-
|
49
|
+
synchronize{ ns_set_deref_options(opts) }
|
65
50
|
end
|
66
51
|
|
67
52
|
# @!macro dereferenceable_set_deref_options
|
@@ -9,7 +9,7 @@ module Concurrent
|
|
9
9
|
module Logging
|
10
10
|
include Logger::Severity
|
11
11
|
|
12
|
-
# Logs through {
|
12
|
+
# Logs through {Concurrent.global_logger}, it can be overridden by setting @logger
|
13
13
|
# @param [Integer] level one of Logger::Severity constants
|
14
14
|
# @param [String] progname e.g. a path of an Actor
|
15
15
|
# @param [String, nil] message when nil block is used to generate the message
|
@@ -3,14 +3,16 @@ require 'timeout'
|
|
3
3
|
|
4
4
|
require 'concurrent/atomic/event'
|
5
5
|
require 'concurrent/concern/dereferenceable'
|
6
|
-
require 'concurrent/concern/deprecation'
|
7
6
|
|
8
7
|
module Concurrent
|
9
8
|
module Concern
|
10
9
|
|
11
10
|
module Obligation
|
12
11
|
include Concern::Dereferenceable
|
13
|
-
|
12
|
+
# NOTE: The Dereferenceable module is going away in 2.0. In the mean time
|
13
|
+
# we need it to place nicely with the synchronization layer. This means
|
14
|
+
# that the including class SHOULD be synchronized and it MUST implement a
|
15
|
+
# `#synchronize` method. Not doing so will lead to runtime errors.
|
14
16
|
|
15
17
|
# Has the obligation been fulfilled?
|
16
18
|
#
|
@@ -48,16 +50,6 @@ module Concurrent
|
|
48
50
|
[:fulfilled, :rejected].include? state
|
49
51
|
end
|
50
52
|
|
51
|
-
# Has the obligation completed processing?
|
52
|
-
#
|
53
|
-
# @return [Boolean]
|
54
|
-
#
|
55
|
-
# @deprecated
|
56
|
-
def completed?
|
57
|
-
deprecated_method 'completed?', 'complete?'
|
58
|
-
complete?
|
59
|
-
end
|
60
|
-
|
61
53
|
# Is the obligation still awaiting completion of processing?
|
62
54
|
#
|
63
55
|
# @return [Boolean]
|
@@ -116,7 +108,7 @@ module Concurrent
|
|
116
108
|
#
|
117
109
|
# @return [Symbol] the current state
|
118
110
|
def state
|
119
|
-
|
111
|
+
synchronize { @state }
|
120
112
|
end
|
121
113
|
|
122
114
|
# If an exception was raised during processing this will return the
|
@@ -125,7 +117,7 @@ module Concurrent
|
|
125
117
|
#
|
126
118
|
# @return [Exception] the exception raised during processing or `nil`
|
127
119
|
def reason
|
128
|
-
|
120
|
+
synchronize { @reason }
|
129
121
|
end
|
130
122
|
|
131
123
|
# @example allows Obligation to be risen
|
@@ -144,8 +136,7 @@ module Concurrent
|
|
144
136
|
end
|
145
137
|
|
146
138
|
# @!visibility private
|
147
|
-
def init_obligation
|
148
|
-
init_mutex(*args)
|
139
|
+
def init_obligation
|
149
140
|
@event = Event.new
|
150
141
|
end
|
151
142
|
|
@@ -167,7 +158,7 @@ module Concurrent
|
|
167
158
|
|
168
159
|
# @!visibility private
|
169
160
|
def state=(value)
|
170
|
-
|
161
|
+
synchronize { ns_set_state(value) }
|
171
162
|
end
|
172
163
|
|
173
164
|
# Atomic compare and set operation
|
@@ -175,12 +166,12 @@ module Concurrent
|
|
175
166
|
#
|
176
167
|
# @param [Symbol] next_state
|
177
168
|
# @param [Symbol] expected_current
|
178
|
-
#
|
169
|
+
#
|
179
170
|
# @return [Boolean] true is state is changed, false otherwise
|
180
171
|
#
|
181
172
|
# @!visibility private
|
182
173
|
def compare_and_set_state(next_state, *expected_current)
|
183
|
-
|
174
|
+
synchronize do
|
184
175
|
if expected_current.include? @state
|
185
176
|
@state = next_state
|
186
177
|
true
|
@@ -196,7 +187,7 @@ module Concurrent
|
|
196
187
|
#
|
197
188
|
# @!visibility private
|
198
189
|
def if_state(*expected_states)
|
199
|
-
|
190
|
+
synchronize do
|
200
191
|
raise ArgumentError.new('no block given') unless block_given?
|
201
192
|
|
202
193
|
if expected_states.include? @state
|
@@ -21,8 +21,8 @@ module Concurrent
|
|
21
21
|
#
|
22
22
|
# In a multi threaded environment things are more complex. The `subject` must
|
23
23
|
# synchronize the access to its data structure and to do so currently we're
|
24
|
-
# using two specialized ObserverSet: CopyOnWriteObserverSet
|
25
|
-
# CopyOnNotifyObserverSet.
|
24
|
+
# using two specialized ObserverSet: {Concurrent::Concern::CopyOnWriteObserverSet}
|
25
|
+
# and {Concurrent::Concern::CopyOnNotifyObserverSet}.
|
26
26
|
#
|
27
27
|
# When implementing and `observer` there's a very important rule to remember:
|
28
28
|
# **there are no guarantees about the thread that will execute the callback**
|
@@ -49,30 +49,55 @@ module Concurrent
|
|
49
49
|
# or an AtomicFixum)
|
50
50
|
module Observable
|
51
51
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
52
|
+
# @!macro [attach] observable_add_observer
|
53
|
+
#
|
54
|
+
# Adds an observer to this set. If a block is passed, the observer will be
|
55
|
+
# created by this method and no other params should be passed.
|
56
|
+
#
|
57
|
+
# @param [Object] observer the observer to add
|
58
|
+
# @param [Symbol] func the function to call on the observer during notification.
|
59
|
+
# Default is :update
|
60
|
+
# @return [Object] the added observer
|
61
|
+
def add_observer(observer = nil, func = :update, &block)
|
62
|
+
observers.add_observer(observer, func, &block)
|
55
63
|
end
|
56
64
|
|
57
|
-
#
|
65
|
+
# As `#add_observer` but can be used for chaining.
|
66
|
+
#
|
67
|
+
# @param [Object] observer the observer to add
|
68
|
+
# @param [Symbol] func the function to call on the observer during notification.
|
58
69
|
# @return [Observable] self
|
59
|
-
def with_observer(
|
60
|
-
add_observer(
|
70
|
+
def with_observer(observer = nil, func = :update, &block)
|
71
|
+
add_observer(observer, func, &block)
|
61
72
|
self
|
62
73
|
end
|
63
74
|
|
64
|
-
#
|
65
|
-
|
66
|
-
|
75
|
+
# @!macro [attach] observable_delete_observer
|
76
|
+
#
|
77
|
+
# Remove `observer` as an observer on this object so that it will no
|
78
|
+
# longer receive notifications.
|
79
|
+
#
|
80
|
+
# @param [Object] observer the observer to remove
|
81
|
+
# @return [Object] the deleted observer
|
82
|
+
def delete_observer(observer)
|
83
|
+
observers.delete_observer(observer)
|
67
84
|
end
|
68
85
|
|
69
|
-
#
|
86
|
+
# @!macro [attach] observable_delete_observers
|
87
|
+
#
|
88
|
+
# Remove all observers associated with this object.
|
89
|
+
#
|
90
|
+
# @return [Observable] self
|
70
91
|
def delete_observers
|
71
92
|
observers.delete_observers
|
72
93
|
self
|
73
94
|
end
|
74
95
|
|
75
|
-
#
|
96
|
+
# @!macro [attach] observable_count_observers
|
97
|
+
#
|
98
|
+
# Return the number of observers associated with this object.
|
99
|
+
#
|
100
|
+
# @return [Integer] the observers count
|
76
101
|
def count_observers
|
77
102
|
observers.count_observers
|
78
103
|
end
|
@@ -2,18 +2,17 @@ require 'thread'
|
|
2
2
|
require 'concurrent/delay'
|
3
3
|
require 'concurrent/errors'
|
4
4
|
require 'concurrent/atomic/atomic_reference'
|
5
|
-
require 'concurrent/concern/deprecation'
|
6
5
|
require 'concurrent/concern/logging'
|
7
|
-
require 'concurrent/executor/timer_set'
|
8
6
|
require 'concurrent/executor/immediate_executor'
|
9
|
-
require 'concurrent/executor/fixed_thread_pool'
|
10
|
-
require 'concurrent/executor/thread_pool_executor'
|
11
7
|
require 'concurrent/utility/at_exit'
|
12
8
|
require 'concurrent/utility/processor_counter'
|
13
9
|
|
14
10
|
module Concurrent
|
15
11
|
extend Concern::Logging
|
16
|
-
|
12
|
+
|
13
|
+
autoload :Options, 'concurrent/options'
|
14
|
+
autoload :TimerSet, 'concurrent/executor/timer_set'
|
15
|
+
autoload :ThreadPoolExecutor, 'concurrent/executor/thread_pool_executor'
|
17
16
|
|
18
17
|
# @return [Logger] Logger with provided level and output.
|
19
18
|
def self.create_stdlib_logger(level = Logger::FATAL, output = $stderr)
|
@@ -25,19 +24,19 @@ module Concurrent
|
|
25
24
|
msg
|
26
25
|
when Exception
|
27
26
|
format "%s (%s)\n%s",
|
28
|
-
|
27
|
+
msg.message, msg.class, (msg.backtrace || []).join("\n")
|
29
28
|
else
|
30
29
|
msg.inspect
|
31
30
|
end
|
32
31
|
format "[%s] %5s -- %s: %s\n",
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
datetime.strftime('%Y-%m-%d %H:%M:%S.%L'),
|
33
|
+
severity,
|
34
|
+
progname,
|
35
|
+
formatted_message
|
37
36
|
end
|
38
37
|
|
39
38
|
lambda do |loglevel, progname, message = nil, &block|
|
40
|
-
|
39
|
+
logger.add loglevel, message, progname, &block
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -95,25 +94,6 @@ module Concurrent
|
|
95
94
|
AtExit.enabled = false
|
96
95
|
end
|
97
96
|
|
98
|
-
def self.disable_executor_auto_termination!
|
99
|
-
deprecated_method 'disable_executor_auto_termination!', 'disable_at_exit_handlers!'
|
100
|
-
disable_at_exit_handlers!
|
101
|
-
end
|
102
|
-
|
103
|
-
# @return [true,false]
|
104
|
-
# @see .disable_executor_auto_termination!
|
105
|
-
def self.disable_executor_auto_termination?
|
106
|
-
deprecated_method 'disable_executor_auto_termination?', 'Concurrent::AtExit.enabled?'
|
107
|
-
AtExit.enabled?
|
108
|
-
end
|
109
|
-
|
110
|
-
# terminates all pools and blocks until they are terminated
|
111
|
-
# @see .disable_executor_auto_termination!
|
112
|
-
def self.terminate_pools!
|
113
|
-
deprecated_method 'terminate_pools!', 'Concurrent::AtExit.run'
|
114
|
-
AtExit.run
|
115
|
-
end
|
116
|
-
|
117
97
|
# Global thread pool optimized for short, fast *operations*.
|
118
98
|
#
|
119
99
|
# @return [ThreadPoolExecutor] the thread pool
|
@@ -146,137 +126,28 @@ module Concurrent
|
|
146
126
|
# - :immediate - {Concurrent.global_immediate_executor}
|
147
127
|
# @return [Executor]
|
148
128
|
def self.executor(executor_identifier)
|
149
|
-
|
129
|
+
Options.executor(executor_identifier)
|
150
130
|
end
|
151
131
|
|
152
132
|
def self.new_fast_executor(opts = {})
|
153
133
|
FixedThreadPool.new(
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
134
|
+
[2, Concurrent.processor_count].max,
|
135
|
+
auto_terminate: opts.fetch(:auto_terminate, true),
|
136
|
+
idletime: 60, # 1 minute
|
137
|
+
max_queue: 0, # unlimited
|
138
|
+
fallback_policy: :abort # shouldn't matter -- 0 max queue
|
159
139
|
)
|
160
140
|
end
|
161
141
|
|
162
142
|
def self.new_io_executor(opts = {})
|
163
143
|
ThreadPoolExecutor.new(
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
144
|
+
min_threads: [2, Concurrent.processor_count].max,
|
145
|
+
max_threads: ThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE,
|
146
|
+
# max_threads: 1000,
|
147
|
+
auto_terminate: opts.fetch(:auto_terminate, true),
|
148
|
+
idletime: 60, # 1 minute
|
149
|
+
max_queue: 0, # unlimited
|
150
|
+
fallback_policy: :abort # shouldn't matter -- 0 max queue
|
171
151
|
)
|
172
152
|
end
|
173
|
-
|
174
|
-
# A gem-level configuration object.
|
175
|
-
class Configuration
|
176
|
-
include Concern::Deprecation
|
177
|
-
|
178
|
-
# Create a new configuration object.
|
179
|
-
def initialize
|
180
|
-
end
|
181
|
-
|
182
|
-
# if assigned to {#logger}, it will log nothing.
|
183
|
-
# @deprecated Use Concurrent::NULL_LOGGER instead
|
184
|
-
def no_logger
|
185
|
-
deprecated_method 'Concurrent.configuration.no_logger', 'Concurrent::NULL_LOGGER'
|
186
|
-
NULL_LOGGER
|
187
|
-
end
|
188
|
-
|
189
|
-
# a proc defining how to log messages, its interface has to be:
|
190
|
-
# lambda { |level, progname, message = nil, &block| _ }
|
191
|
-
#
|
192
|
-
# @deprecated Use Concurrent.global_logger instead
|
193
|
-
def logger
|
194
|
-
deprecated_method 'Concurrent.configuration.logger', 'Concurrent.global_logger'
|
195
|
-
Concurrent.global_logger.value
|
196
|
-
end
|
197
|
-
|
198
|
-
# a proc defining how to log messages, its interface has to be:
|
199
|
-
# lambda { |level, progname, message = nil, &block| _ }
|
200
|
-
#
|
201
|
-
# @deprecated Use Concurrent.global_logger instead
|
202
|
-
def logger=(value)
|
203
|
-
deprecated_method 'Concurrent.configuration.logger=', 'Concurrent.global_logger='
|
204
|
-
Concurrent.global_logger = value
|
205
|
-
end
|
206
|
-
|
207
|
-
# @deprecated Use Concurrent.global_io_executor instead
|
208
|
-
def global_task_pool
|
209
|
-
deprecated_method 'Concurrent.configuration.global_task_pool', 'Concurrent.global_io_executor'
|
210
|
-
Concurrent.global_io_executor
|
211
|
-
end
|
212
|
-
|
213
|
-
# @deprecated Use Concurrent.global_fast_executor instead
|
214
|
-
def global_operation_pool
|
215
|
-
deprecated_method 'Concurrent.configuration.global_operation_pool', 'Concurrent.global_fast_executor'
|
216
|
-
Concurrent.global_fast_executor
|
217
|
-
end
|
218
|
-
|
219
|
-
# @deprecated Use Concurrent.global_timer_set instead
|
220
|
-
def global_timer_set
|
221
|
-
deprecated_method 'Concurrent.configuration.global_timer_set', 'Concurrent.global_timer_set'
|
222
|
-
Concurrent.global_timer_set
|
223
|
-
end
|
224
|
-
|
225
|
-
# @deprecated Replacing global thread pools is deprecated.
|
226
|
-
# Use the :executor constructor option instead.
|
227
|
-
def global_task_pool=(executor)
|
228
|
-
deprecated 'Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
|
229
|
-
GLOBAL_IO_EXECUTOR.reconfigure { executor } or
|
230
|
-
raise ConfigurationError.new('global task pool was already set')
|
231
|
-
end
|
232
|
-
|
233
|
-
# @deprecated Replacing global thread pools is deprecated.
|
234
|
-
# Use the :executor constructor option instead.
|
235
|
-
def global_operation_pool=(executor)
|
236
|
-
deprecated 'Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
|
237
|
-
GLOBAL_FAST_EXECUTOR.reconfigure { executor } or
|
238
|
-
raise ConfigurationError.new('global operation pool was already set')
|
239
|
-
end
|
240
|
-
|
241
|
-
# @deprecated Use Concurrent.new_io_executor instead
|
242
|
-
def new_task_pool
|
243
|
-
deprecated_method 'Concurrent.configuration.new_task_pool', 'Concurrent.new_io_executor'
|
244
|
-
Concurrent.new_io_executor
|
245
|
-
end
|
246
|
-
|
247
|
-
# @deprecated Use Concurrent.new_fast_executor instead
|
248
|
-
def new_operation_pool
|
249
|
-
deprecated_method 'Concurrent.configuration.new_operation_pool', 'Concurrent.new_fast_executor'
|
250
|
-
Concurrent.new_fast_executor
|
251
|
-
end
|
252
|
-
|
253
|
-
# @deprecated Use Concurrent.disable_executor_auto_termination! instead
|
254
|
-
def auto_terminate=(value)
|
255
|
-
deprecated_method 'Concurrent.configuration.auto_terminate=', 'Concurrent.disable_executor_auto_termination!'
|
256
|
-
Concurrent.disable_executor_auto_termination! if !value
|
257
|
-
end
|
258
|
-
|
259
|
-
# @deprecated Use Concurrent.auto_terminate_global_executors? instead
|
260
|
-
def auto_terminate
|
261
|
-
deprecated_method 'Concurrent.configuration.auto_terminate', 'Concurrent.auto_terminate_global_executors?'
|
262
|
-
Concurrent.auto_terminate_global_executors?
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
# create the default configuration on load
|
267
|
-
CONFIGURATION = AtomicReference.new(Configuration.new)
|
268
|
-
private_constant :CONFIGURATION
|
269
|
-
|
270
|
-
# @return [Configuration]
|
271
|
-
def self.configuration
|
272
|
-
CONFIGURATION.value
|
273
|
-
end
|
274
|
-
|
275
|
-
# Perform gem-level configuration.
|
276
|
-
#
|
277
|
-
# @yield the configuration commands
|
278
|
-
# @yieldparam [Configuration] the current configuration object
|
279
|
-
def self.configure
|
280
|
-
yield(configuration)
|
281
|
-
end
|
282
153
|
end
|