diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-14 11:06:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-14 11:06:20 -0700 |
commit | 468a55b741f2ceacd8a988a9487db6d767ca8616 (patch) | |
tree | cbf935eda9855db7f9d568b599f7c63246a29399 /activesupport | |
parent | 7645a5f85d7fc88b5f05f7fe4b73b743078bb069 (diff) | |
parent | 284a9ba8ecbbaac598179af6fc65aed7bcf5785b (diff) | |
download | rails-468a55b741f2ceacd8a988a9487db6d767ca8616.tar.gz rails-468a55b741f2ceacd8a988a9487db6d767ca8616.tar.bz2 rails-468a55b741f2ceacd8a988a9487db6d767ca8616.zip |
Merge pull request #20866 from jdantonio/countdown-latch
Replace `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch` from concurrent-ruby.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/activesupport.gemspec | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/concurrency/latch.rb | 24 |
3 files changed, 14 insertions, 16 deletions
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 |