Skip to content

Commit aa44895

Browse files
committed
Merge pull request #409 from ruby-concurrency/circular
Fix interpreter warnings
2 parents 42878ba + b67113f commit aa44895

24 files changed

+106
-75
lines changed

lib/concurrent.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
require 'concurrent/version'
2-
3-
require 'concurrent/synchronization'
4-
52
require 'concurrent/configuration'
63

74
require 'concurrent/atomics'
85
require 'concurrent/errors'
96
require 'concurrent/executors'
7+
require 'concurrent/synchronization'
108

119
require 'concurrent/atomic/atomic_reference'
1210
require 'concurrent/atom'
@@ -33,6 +31,7 @@
3331
require 'concurrent/thread_safe/synchronized_delegator'
3432
require 'concurrent/thread_safe/util'
3533

34+
require 'concurrent/options'
3635

3736
# @!macro [new] internal_implementation_note
3837
#

lib/concurrent/agent.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
require 'concurrent/concern/dereferenceable'
33
require 'concurrent/concern/observable'
44
require 'concurrent/concern/logging'
5-
require 'concurrent/executor/executor'
65
require 'concurrent/synchronization'
76

87
module Concurrent
98

9+
autoload :Options, 'concurrent/options'
10+
1011
# `Agent`s are inspired by [Clojure's](http://clojure.org/) [agent](http://clojure.org/agents) function. An `Agent` is a single atomic value that represents an identity. The current value of the `Agent` can be requested at any time (`deref`). Each `Agent` has a work queue and operates on the global thread pool (see below). Consumers can `post` code blocks to the `Agent`. The code block (function) will receive the current value of the `Agent` as its sole parameter. The return value of the block will become the new value of the `Agent`. `Agent`s support two error handling modes: fail and continue. A good example of an `Agent` is a shared incrementing counter, such as the score in a video game.
1112
#
1213
# An `Agent` must be initialize with an initial value. This value is always accessible via the `value` (or `deref`) methods. Code blocks sent to the `Agent` will be processed in the order received. As each block is processed the current value is updated with the result from the block. This update is an atomic operation so a `deref` will never block and will always return the current value.
@@ -203,8 +204,8 @@ def ns_initialize(initial, opts)
203204
@validator = Proc.new { |result| true }
204205
self.observers = Collection::CopyOnWriteObserverSet.new
205206
@serialized_execution = SerializedExecution.new
206-
@io_executor = Executor.executor_from_options(opts) || Concurrent.global_io_executor
207-
@fast_executor = Executor.executor_from_options(opts) || Concurrent.global_fast_executor
207+
@io_executor = Options.executor_from_options(opts) || Concurrent.global_io_executor
208+
@fast_executor = Options.executor_from_options(opts) || Concurrent.global_fast_executor
208209
set_deref_options(opts)
209210
end
210211

lib/concurrent/array.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Array < ::Array
2727

2828
elsif Concurrent.on_rbx?
2929
require 'monitor'
30+
require 'concurrent/thread_safe/util/array_hash_rbx'
3031

3132
# @!macro concurrent_array
3233
class Array < ::Array

lib/concurrent/collection/map/atomic_reference_map_backend.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
require 'concurrent/thread_safe/util'
2+
require 'concurrent/thread_safe/util/adder'
3+
require 'concurrent/thread_safe/util/cheap_lockable'
4+
require 'concurrent/thread_safe/util/power_of_two_tuple'
5+
require 'concurrent/thread_safe/util/volatile'
6+
require 'concurrent/thread_safe/util/xor_shift_random'
27

38
module Concurrent
49

lib/concurrent/configuration.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
require 'concurrent/errors'
44
require 'concurrent/atomic/atomic_reference'
55
require 'concurrent/concern/logging'
6-
require 'concurrent/executor/timer_set'
76
require 'concurrent/executor/immediate_executor'
8-
require 'concurrent/executor/fixed_thread_pool'
9-
require 'concurrent/executor/thread_pool_executor'
107
require 'concurrent/utility/at_exit'
118
require 'concurrent/utility/processor_counter'
129

1310
module Concurrent
1411
extend Concern::Logging
1512

13+
autoload :Options, 'concurrent/options'
14+
autoload :TimerSet, 'concurrent/executor/timer_set'
15+
autoload :ThreadPoolExecutor, 'concurrent/executor/thread_pool_executor'
16+
1617
# @return [Logger] Logger with provided level and output.
1718
def self.create_stdlib_logger(level = Logger::FATAL, output = $stderr)
1819
logger = Logger.new(output)
@@ -125,7 +126,7 @@ def self.global_timer_set
125126
# - :immediate - {Concurrent.global_immediate_executor}
126127
# @return [Executor]
127128
def self.executor(executor_identifier)
128-
Executor.executor(executor_identifier)
129+
Options.executor(executor_identifier)
129130
end
130131

131132
def self.new_fast_executor(opts = {})

lib/concurrent/delay.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'thread'
2-
require 'concurrent/configuration'
32
require 'concurrent/concern/obligation'
4-
require 'concurrent/executor/executor'
53
require 'concurrent/executor/immediate_executor'
64
require 'concurrent/synchronization'
75

86
module Concurrent
97

8+
autoload :Options, 'concurrent/options'
9+
1010
# Lazy evaluation of a block yielding an immutable result. Useful for
1111
# expensive operations that may never be needed. It may be non-blocking,
1212
# supports the `Concern::Obligation` interface, and accepts the injection of
@@ -74,7 +74,7 @@ def initialize(opts = {}, &block)
7474
#
7575
# @!macro delay_note_regarding_blocking
7676
def value(timeout = nil)
77-
if @task_executor
77+
if @executor
7878
super
7979
else
8080
# this function has been optimized for performance and
@@ -108,7 +108,7 @@ def value(timeout = nil)
108108
#
109109
# @!macro delay_note_regarding_blocking
110110
def value!(timeout = nil)
111-
if @task_executor
111+
if @executor
112112
super
113113
else
114114
result = value
@@ -127,7 +127,7 @@ def value!(timeout = nil)
127127
#
128128
# @!macro delay_note_regarding_blocking
129129
def wait(timeout = nil)
130-
if @task_executor
130+
if @executor
131131
execute_task_once
132132
super(timeout)
133133
else
@@ -157,7 +157,7 @@ def reconfigure(&block)
157157
def ns_initialize(opts, &block)
158158
init_obligation(self)
159159
set_deref_options(opts)
160-
@task_executor = Executor.executor_from_options(opts)
160+
@executor = opts[:executor]
161161

162162
@task = block
163163
@state = :pending
@@ -177,7 +177,8 @@ def execute_task_once # :nodoc:
177177
end
178178

179179
if execute
180-
@task_executor.post do
180+
executor = Options.executor_from_options(executor: @executor)
181+
executor.post do
181182
begin
182183
result = task.call
183184
success = true

lib/concurrent/executor/ruby_executor_service.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ def wait_for_termination(timeout = nil)
5151

5252
private
5353

54-
attr_reader :stop_event, :stopped_event
54+
def stop_event
55+
@stop_event
56+
end
57+
58+
def stopped_event
59+
@stopped_event
60+
end
5561

5662
def ns_shutdown_execution
5763
stopped_event.set

lib/concurrent/executor/timer_set.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
module Concurrent
88

9+
autoload :Options, 'concurrent/options'
10+
911
# Executes a collection of tasks, each after a given delay. A master task
1012
# monitors the set and schedules each task for execution at the appropriate
1113
# time. Tasks are run on the global thread pool or on the supplied executor.
@@ -73,7 +75,7 @@ def kill
7375
# @!visibility private
7476
def ns_initialize(opts)
7577
@queue = Collection::NonConcurrentPriorityQueue.new(order: :min)
76-
@task_executor = Executor.executor_from_options(opts) || Concurrent.global_io_executor
78+
@task_executor = Options.executor_from_options(opts) || Concurrent.global_io_executor
7779
@timer_executor = SingleThreadExecutor.new
7880
@condition = Event.new
7981
self.auto_terminate = opts.fetch(:auto_terminate, true)
@@ -115,7 +117,7 @@ def remove_task(task)
115117
synchronize{ @queue.delete(task) }
116118
end
117119

118-
# `ExecutorServic` callback called during shutdown.
120+
# `ExecutorService` callback called during shutdown.
119121
#
120122
# @!visibility private
121123
def ns_shutdown_execution

lib/concurrent/executors.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'concurrent/executor/abstract_executor_service'
22
require 'concurrent/executor/cached_thread_pool'
3-
require 'concurrent/executor/executor'
43
require 'concurrent/executor/executor_service'
54
require 'concurrent/executor/fixed_thread_pool'
65
require 'concurrent/executor/immediate_executor'

lib/concurrent/future.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
require 'thread'
22
require 'concurrent/errors'
33
require 'concurrent/ivar'
4-
require 'concurrent/executor/executor'
54
require 'concurrent/executor/safe_task_executor'
65

76
module Concurrent
87

8+
autoload :Options, 'concurrent/options'
9+
910
# {include:file:doc/future.md}
1011
#
1112
# @!macro copy_options
@@ -129,7 +130,7 @@ def ns_initialize(value, opts)
129130
super
130131
@state = :unscheduled
131132
@task = opts[:__task_from_block__]
132-
@executor = Executor.executor_from_options(opts) || Concurrent.global_io_executor
133+
@executor = Options.executor_from_options(opts) || Concurrent.global_io_executor
133134
@args = get_arguments_from(opts)
134135
end
135136
end

0 commit comments

Comments
 (0)