diff options
author | Jerry D'Antonio <stumpjumper@gmail.com> | 2015-07-13 14:22:54 -0400 |
---|---|---|
committer | Jerry D'Antonio <stumpjumper@gmail.com> | 2015-07-13 15:44:21 -0400 |
commit | 284a9ba8ecbbaac598179af6fc65aed7bcf5785b (patch) | |
tree | 1f9f0ad6dff487a66235d52dca959693ca5c9a34 /activesupport/lib/active_support | |
parent | 08e41a043218583d34e34316df82d38e4d7f1b55 (diff) | |
download | rails-284a9ba8ecbbaac598179af6fc65aed7bcf5785b.tar.gz rails-284a9ba8ecbbaac598179af6fc65aed7bcf5785b.tar.bz2 rails-284a9ba8ecbbaac598179af6fc65aed7bcf5785b.zip |
Replaced `ActiveSupport::Concurrency::Latch` with concurrent-ruby.
The concurrent-ruby gem is a toolset containing many concurrency
utilities. Many of these utilities include runtime-specific
optimizations when possible. Rather than clutter the Rails codebase with
concurrency utilities separate from the core task, such tools can be
superseded by similar tools in the more specialized gem. This commit
replaces `ActiveSupport::Concurrency::Latch` with
`Concurrent::CountDownLatch`, which is functionally equivalent.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/concurrency/latch.rb | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/activesupport/lib/active_support/concurrency/latch.rb b/activesupport/lib/active_support/concurrency/latch.rb index 1507de433e..7b8df0df04 100644 --- a/activesupport/lib/active_support/concurrency/latch.rb +++ b/activesupport/lib/active_support/concurrency/latch.rb @@ -1,26 +1,18 @@ -require 'thread' -require 'monitor' +require 'concurrent/atomics' module ActiveSupport module Concurrency - class Latch - def initialize(count = 1) - @count = count - @lock = Monitor.new - @cv = @lock.new_cond - end + class Latch < Concurrent::CountDownLatch - def release - @lock.synchronize do - @count -= 1 if @count > 0 - @cv.broadcast if @count.zero? - end + def initialize(count = 1) + ActiveSupport::Deprecation.warn("ActiveSupport::Concurrency::Latch is deprecated. Please use Concurrent::CountDownLatch instead.") + super(count) end + + alias_method :release, :count_down def await - @lock.synchronize do - @cv.wait_while { @count > 0 } - end + wait(nil) end end end |