From 284a9ba8ecbbaac598179af6fc65aed7bcf5785b Mon Sep 17 00:00:00 2001 From: Jerry D'Antonio Date: Mon, 13 Jul 2015 14:22:54 -0400 Subject: 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. --- activesupport/CHANGELOG.md | 5 +++++ activesupport/activesupport.gemspec | 1 + .../lib/active_support/concurrency/latch.rb | 24 ++++++++-------------- 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 334eebc268..17c2f0eb27 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Removed `ActiveSupport::Concurrency::Latch`, superseded by `Concurrent::CountDownLatch` + from the concurrent-ruby gem. + + *Jerry D'Antonio* + * Fix not calling `#default` on `HashWithIndifferentAccess#to_hash` when only `default_proc` is set, which could raise. diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index 12c6a4d449..c18c1c87c9 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -25,4 +25,5 @@ Gem::Specification.new do |s| s.add_dependency 'tzinfo', '~> 1.1' s.add_dependency 'minitest', '~> 5.1' s.add_dependency 'thread_safe','~> 0.3', '>= 0.3.4' + s.add_dependency 'concurrent-ruby', '~> 0.9.0' end 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 -- cgit v1.2.3