Skip to content

Commit 1fbf9d5

Browse files
committed
Merge pull request #391 from ruby-concurrency/one-point-zero-pre-1
Initial preparation for 1.0.0.pre1
2 parents 0d449fb + c9bd33a commit 1fbf9d5

36 files changed

+118
-1044
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### Upcoming Release v1.0.0 (TBD)
2+
3+
* Removed all deprecated code (classes, methods, constants, etc.)
4+
* Updated Agent, MutexAtomic, and BufferedChannel to inherit from Synchronization::Object.
5+
16
## Current Release v0.9.1 (09 August 2015)
27

38
* Fixed a Rubiniux bug in synchronization object

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ require 'concurrent/tvar' # Concurrent::TVar
184184
require 'concurrent/actor' # Concurrent::Actor and supporting code
185185
require 'concurrent/edge/future' # new Future Framework
186186
require 'concurrent/agent' # Concurrent::Agent
187-
require 'concurrent/channel ' # Concurrent::Channel and supporting code
187+
require 'concurrent/channel' # Concurrent::Channel and supporting code
188188
```
189189

190190
If the library does not behave as expected, `Concurrent.use_stdlib_logger(Logger::DEBUG)` could help to reveal the problem.

lib/concurrent.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
require 'concurrent/atomics'
88
require 'concurrent/errors'
99
require 'concurrent/executors'
10-
require 'concurrent/utilities'
1110

1211
require 'concurrent/atomic/atomic_reference'
1312
require 'concurrent/atom'

lib/concurrent/agent.rb

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
require 'thread'
21
require 'concurrent/collection/copy_on_write_observer_set'
32
require 'concurrent/concern/dereferenceable'
43
require 'concurrent/concern/observable'
54
require 'concurrent/concern/logging'
65
require 'concurrent/executor/executor'
7-
require 'concurrent/concern/deprecation'
6+
require 'concurrent/synchronization'
87

98
module Concurrent
109

@@ -81,11 +80,10 @@ module Concurrent
8180
# @return [Fixnum] the maximum number of seconds before an update is cancelled
8281
#
8382
# @!macro edge_warning
84-
class Agent
83+
class Agent < Synchronization::Object
8584
include Concern::Dereferenceable
8685
include Concern::Observable
8786
include Concern::Logging
88-
include Concern::Deprecation
8987

9088
attr_reader :timeout, :io_executor, :fast_executor
9189

@@ -95,15 +93,8 @@ class Agent
9593
#
9694
# @!macro executor_and_deref_options
9795
def initialize(initial, opts = {})
98-
@value = initial
99-
@rescuers = []
100-
@validator = Proc.new { |result| true }
101-
self.observers = Collection::CopyOnWriteObserverSet.new
102-
@serialized_execution = SerializedExecution.new
103-
@io_executor = Executor.executor_from_options(opts) || Concurrent.global_io_executor
104-
@fast_executor = Executor.executor_from_options(opts) || Concurrent.global_fast_executor
105-
init_mutex
106-
set_deref_options(opts)
96+
super()
97+
synchronize { ns_initialize(initial, opts) }
10798
end
10899

109100
# Specifies a block fast to be performed when an update fast raises
@@ -129,17 +120,15 @@ def initialize(initial, opts = {})
129120
# #=> puts "Pow!"
130121
def rescue(clazz = StandardError, &block)
131122
unless block.nil?
132-
mutex.synchronize do
133-
@rescuers << Rescuer.new(clazz, block)
134-
end
123+
synchronize { @rescuers << Rescuer.new(clazz, block) }
135124
end
136125
self
137126
end
138127

139128
alias_method :catch, :rescue
140129
alias_method :on_error, :rescue
141130

142-
# A block fast to be performed after every update to validate if the new
131+
# A block task to be performed after every update to validate if the new
143132
# value is valid. If the new value is not valid then the current value is not
144133
# updated. If no validator is provided then all updates are considered valid.
145134
#
@@ -150,12 +139,7 @@ def rescue(clazz = StandardError, &block)
150139
def validate(&block)
151140

152141
unless block.nil?
153-
begin
154-
mutex.lock
155-
@validator = block
156-
ensure
157-
mutex.unlock
158-
end
142+
synchronize { @validator = block }
159143
end
160144
self
161145
end
@@ -179,30 +163,13 @@ def post(&block)
179163
# Update the current value with the result of the given block fast,
180164
# block can do blocking calls
181165
#
182-
# @param [Fixnum, nil] timeout [DEPRECATED] maximum number of seconds before an update is cancelled
183-
#
184166
# @yield the fast to be performed with the current value in order to calculate
185167
# the new value
186168
# @yieldparam [Object] value the current value
187169
# @yieldreturn [Object] the new value
188170
# @return [true, nil] nil when no block is given
189-
def post_off(timeout = nil, &block)
190-
task = if timeout
191-
deprecated 'post_off with option timeout options is deprecated and will be removed'
192-
lambda do |value|
193-
future = Future.execute do
194-
block.call(value)
195-
end
196-
if future.wait(timeout)
197-
future.value!
198-
else
199-
raise Concurrent::TimeoutError
200-
end
201-
end
202-
else
203-
block
204-
end
205-
post_on(@io_executor, &task)
171+
def post_off(&block)
172+
post_on(@io_executor, &block)
206173
end
207174

208175
# Update the current value with the result of the given block fast,
@@ -227,6 +194,20 @@ def await(timeout = nil)
227194
done.wait timeout
228195
end
229196

197+
protected
198+
199+
def ns_initialize(initial, opts)
200+
init_mutex(self)
201+
@value = initial
202+
@rescuers = []
203+
@validator = Proc.new { |result| true }
204+
self.observers = Collection::CopyOnWriteObserverSet.new
205+
@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
208+
set_deref_options(opts)
209+
end
210+
230211
private
231212

232213
def post_on(executor, &block)
@@ -240,7 +221,7 @@ def post_on(executor, &block)
240221

241222
# @!visibility private
242223
def try_rescue(ex) # :nodoc:
243-
rescuer = mutex.synchronize do
224+
rescuer = synchronize do
244225
@rescuers.find { |r| ex.is_a?(r.clazz) }
245226
end
246227
rescuer.block.call(ex) if rescuer
@@ -251,7 +232,7 @@ def try_rescue(ex) # :nodoc:
251232

252233
# @!visibility private
253234
def work(&handler) # :nodoc:
254-
validator, value = mutex.synchronize { [@validator, @value] }
235+
validator, value = synchronize { [@validator, @value] }
255236

256237
begin
257238
result = handler.call(value)
@@ -260,14 +241,11 @@ def work(&handler) # :nodoc:
260241
exception = ex
261242
end
262243

263-
begin
264-
mutex.lock
265-
should_notify = if !exception && valid
266-
@value = result
267-
true
268-
end
269-
ensure
270-
mutex.unlock
244+
should_notify = synchronize do
245+
if !exception && valid
246+
@value = result
247+
true
248+
end
271249
end
272250

273251
if should_notify

lib/concurrent/async.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require 'concurrent/ivar'
66
require 'concurrent/executor/immediate_executor'
77
require 'concurrent/executor/serialized_execution'
8-
require 'concurrent/concern/deprecation'
98

109
module Concurrent
1110

@@ -248,22 +247,6 @@ def executor=(executor)
248247
raise ArgumentError.new('executor has already been set')
249248
end
250249

251-
# Initialize the internal serializer and other stnchronization mechanisms.
252-
#
253-
# @note This method *must* be called immediately upon object construction.
254-
# This is the only way thread-safe initialization can be guaranteed.
255-
#
256-
# @raise [Concurrent::InitializationError] when called more than once
257-
#
258-
# @!visibility private
259-
# @deprecated
260-
def init_mutex
261-
deprecated 'mutex synchronization now happens automatically'
262-
init_synchronization
263-
rescue InitializationError
264-
# suppress
265-
end
266-
267250
private
268251

269252
# Initialize the internal serializer and other stnchronization mechanisms.

lib/concurrent/atomic/atomic_reference.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,3 @@ class Concurrent::AtomicReference < Concurrent::CAtomicReference
4040
class Concurrent::AtomicReference < Concurrent::MutexAtomicReference
4141
end
4242
end
43-
44-
module Concurrent
45-
46-
# @see Concurrent::AtomicReference
47-
# @deprecated Use Concurrent::AtomicReference instead.
48-
Atomic = AtomicReference
49-
end

lib/concurrent/atomic/condition.rb

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'thread'
1+
require 'concurrent/synchronization'
22
require 'concurrent/atomic_reference/direct_update'
33
require 'concurrent/atomic_reference/numeric_cas_wrapper'
44

@@ -8,31 +8,31 @@ module Concurrent
88
#
99
# @!visibility private
1010
# @!macro internal_implementation_note
11-
class MutexAtomicReference
11+
class MutexAtomicReference < Synchronization::Object
1212
include Concurrent::AtomicDirectUpdate
1313
include Concurrent::AtomicNumericCompareAndSetWrapper
1414

1515
# @!macro atomic_reference_method_initialize
1616
def initialize(value = nil)
17-
@mutex = Mutex.new
18-
@value = value
17+
super()
18+
synchronize { ns_initialize(value) }
1919
end
2020

2121
# @!macro atomic_reference_method_get
2222
def get
23-
@mutex.synchronize { @value }
23+
synchronize { @value }
2424
end
2525
alias_method :value, :get
2626

2727
# @!macro atomic_reference_method_set
2828
def set(new_value)
29-
@mutex.synchronize { @value = new_value }
29+
synchronize { @value = new_value }
3030
end
3131
alias_method :value=, :set
3232

3333
# @!macro atomic_reference_method_get_and_set
3434
def get_and_set(new_value)
35-
@mutex.synchronize do
35+
synchronize do
3636
old_value = @value
3737
@value = new_value
3838
old_value
@@ -42,7 +42,7 @@ def get_and_set(new_value)
4242

4343
# @!macro atomic_reference_method_compare_and_set
4444
def _compare_and_set(old_value, new_value)
45-
@mutex.synchronize do
45+
synchronize do
4646
if @value.equal? old_value
4747
@value = new_value
4848
true
@@ -51,5 +51,11 @@ def _compare_and_set(old_value, new_value)
5151
end
5252
end
5353
end
54+
55+
protected
56+
57+
def ns_initialize(value)
58+
@value = value
59+
end
5460
end
5561
end

lib/concurrent/atomics.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
require 'concurrent/atomic/atomic_reference'
7474
require 'concurrent/atomic/atomic_boolean'
7575
require 'concurrent/atomic/atomic_fixnum'
76-
require 'concurrent/atomic/condition'
7776
require 'concurrent/atomic/cyclic_barrier'
7877
require 'concurrent/atomic/count_down_latch'
7978
require 'concurrent/atomic/event'

0 commit comments

Comments
 (0)