提交 1bf3cecf 编写于 作者: K Kasper Timm Hansen

Merge pull request #21679 from jdantonio/replace-thread-safe

Replaced `ThreadSafe::Map` with successor `Concurrent::Map`.
...@@ -122,12 +122,11 @@ PATH ...@@ -122,12 +122,11 @@ PATH
activesupport (= 5.0.0.alpha) activesupport (= 5.0.0.alpha)
arel (= 7.0.0.alpha) arel (= 7.0.0.alpha)
activesupport (5.0.0.alpha) activesupport (5.0.0.alpha)
concurrent-ruby (~> 0.9.1) concurrent-ruby (~> 1.0.0.pre2, < 2.0.0)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
method_source method_source
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
rails (5.0.0.alpha) rails (5.0.0.alpha)
actionmailer (= 5.0.0.alpha) actionmailer (= 5.0.0.alpha)
...@@ -172,7 +171,7 @@ GEM ...@@ -172,7 +171,7 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.9.1.1) coffee-script-source (1.9.1.1)
concurrent-ruby (0.9.1) concurrent-ruby (1.0.0.pre2)
connection_pool (2.2.0) connection_pool (2.2.0)
dalli (2.7.4) dalli (2.7.4)
dante (0.2.0) dante (0.2.0)
......
require 'thread_safe' require 'concurrent'
require 'action_view/path_set' require 'action_view/path_set'
module ActionView module ActionView
class DependencyTracker # :nodoc: class DependencyTracker # :nodoc:
@trackers = ThreadSafe::Cache.new @trackers = Concurrent::Map.new
def self.find_dependencies(name, template, view_paths = nil) def self.find_dependencies(name, template, view_paths = nil)
tracker = @trackers[template.handler] tracker = @trackers[template.handler]
......
require 'thread_safe' require 'concurrent'
require 'action_view/dependency_tracker' require 'action_view/dependency_tracker'
require 'monitor' require 'monitor'
module ActionView module ActionView
class Digestor class Digestor
cattr_reader(:cache) cattr_reader(:cache)
@@cache = ThreadSafe::Cache.new @@cache = Concurrent::Map.new
@@digest_monitor = Monitor.new @@digest_monitor = Monitor.new
class PerRequestDigestCacheExpiry < Struct.new(:app) # :nodoc: class PerRequestDigestCacheExpiry < Struct.new(:app) # :nodoc:
...@@ -28,7 +28,7 @@ def digest(options) ...@@ -28,7 +28,7 @@ def digest(options)
cache_key = ([ options[:name], options[:finder].details_key.hash ].compact + Array.wrap(options[:dependencies])).join('.') cache_key = ([ options[:name], options[:finder].details_key.hash ].compact + Array.wrap(options[:dependencies])).join('.')
# this is a correctly done double-checked locking idiom # this is a correctly done double-checked locking idiom
# (ThreadSafe::Cache's lookups have volatile semantics) # (Concurrent::Map's lookups have volatile semantics)
@@cache[cache_key] || @@digest_monitor.synchronize do @@cache[cache_key] || @@digest_monitor.synchronize do
@@cache.fetch(cache_key) do # re-check under lock @@cache.fetch(cache_key) do # re-check under lock
compute_and_store_digest(cache_key, options) compute_and_store_digest(cache_key, options)
......
require 'thread_safe' require 'concurrent'
require 'active_support/core_ext/module/remove_method' require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attribute_accessors'
require 'action_view/template/resolver' require 'action_view/template/resolver'
...@@ -62,7 +62,7 @@ class DetailsKey #:nodoc: ...@@ -62,7 +62,7 @@ class DetailsKey #:nodoc:
alias :object_hash :hash alias :object_hash :hash
attr_reader :hash attr_reader :hash
@details_keys = ThreadSafe::Cache.new @details_keys = Concurrent::Map.new
def self.get(details) def self.get(details)
if details[:formats] if details[:formats]
......
require 'action_view/renderer/partial_renderer/collection_caching' require 'action_view/renderer/partial_renderer/collection_caching'
require 'thread_safe' require 'concurrent'
module ActionView module ActionView
class PartialIteration class PartialIteration
...@@ -283,8 +283,8 @@ def iterate! # :nodoc: ...@@ -283,8 +283,8 @@ def iterate! # :nodoc:
class PartialRenderer < AbstractRenderer class PartialRenderer < AbstractRenderer
include CollectionCaching include CollectionCaching
PREFIXED_PARTIAL_NAMES = ThreadSafe::Cache.new do |h, k| PREFIXED_PARTIAL_NAMES = Concurrent::Map.new do |h, k|
h[k] = ThreadSafe::Cache.new h[k] = Concurrent::Map.new
end end
def initialize(*) def initialize(*)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require "active_support/core_ext/module/attribute_accessors" require "active_support/core_ext/module/attribute_accessors"
require "action_view/template" require "action_view/template"
require "thread" require "thread"
require "thread_safe" require "concurrent"
module ActionView module ActionView
# = Action View Resolver # = Action View Resolver
...@@ -35,7 +35,7 @@ def to_str ...@@ -35,7 +35,7 @@ def to_str
# Threadsafe template cache # Threadsafe template cache
class Cache #:nodoc: class Cache #:nodoc:
class SmallCache < ThreadSafe::Cache class SmallCache < Concurrent::Map
def initialize(options = {}) def initialize(options = {})
super(options.merge(:initial_capacity => 2)) super(options.merge(:initial_capacity => 2))
end end
......
require 'concurrent' require 'concurrent'
require 'thread_safe'
module ActiveJob module ActiveJob
# == Active Job Async Job # == Active Job Async Job
...@@ -31,7 +30,7 @@ class AsyncJob ...@@ -31,7 +30,7 @@ class AsyncJob
fallback_policy: :caller_runs # shouldn't matter -- 0 max queue fallback_policy: :caller_runs # shouldn't matter -- 0 max queue
}.freeze }.freeze
QUEUES = ThreadSafe::Cache.new do |hash, queue_name| #:nodoc: QUEUES = Concurrent::Map.new do |hash, queue_name| #:nodoc:
hash.compute_if_absent(queue_name) { ActiveJob::AsyncJob.create_thread_pool } hash.compute_if_absent(queue_name) { ActiveJob::AsyncJob.create_thread_pool }
end end
......
require 'thread_safe' require 'concurrent'
require 'mutex_m' require 'mutex_m'
module ActiveModel module ActiveModel
...@@ -350,7 +350,7 @@ def instance_method_already_implemented?(method_name) #:nodoc: ...@@ -350,7 +350,7 @@ def instance_method_already_implemented?(method_name) #:nodoc:
# significantly (in our case our test suite finishes 10% faster with # significantly (in our case our test suite finishes 10% faster with
# this cache). # this cache).
def attribute_method_matchers_cache #:nodoc: def attribute_method_matchers_cache #:nodoc:
@attribute_method_matchers_cache ||= ThreadSafe::Cache.new(initial_capacity: 4) @attribute_method_matchers_cache ||= Concurrent::Map.new(initial_capacity: 4)
end end
def attribute_method_matchers_matching(method_name) #:nodoc: def attribute_method_matchers_matching(method_name) #:nodoc:
......
require 'active_support/core_ext/enumerable' require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/string/filters' require 'active_support/core_ext/string/filters'
require 'mutex_m' require 'mutex_m'
require 'thread_safe' require 'concurrent'
module ActiveRecord module ActiveRecord
# = Active Record Attribute Methods # = Active Record Attribute Methods
...@@ -37,7 +37,7 @@ def self.set_name_cache(name, value) ...@@ -37,7 +37,7 @@ def self.set_name_cache(name, value)
class AttributeMethodCache class AttributeMethodCache
def initialize def initialize
@module = Module.new @module = Module.new
@method_cache = ThreadSafe::Cache.new @method_cache = Concurrent::Map.new
end end
def [](name) def [](name)
......
require 'thread' require 'thread'
require 'thread_safe' require 'concurrent'
require 'monitor' require 'monitor'
module ActiveRecord module ActiveRecord
...@@ -337,7 +337,7 @@ def initialize(spec) ...@@ -337,7 +337,7 @@ def initialize(spec)
# that case +conn.owner+ attr should be consulted. # that case +conn.owner+ attr should be consulted.
# Access and modification of +@thread_cached_conns+ does not require # Access and modification of +@thread_cached_conns+ does not require
# synchronization. # synchronization.
@thread_cached_conns = ThreadSafe::Cache.new(:initial_capacity => @size) @thread_cached_conns = Concurrent::Map.new(:initial_capacity => @size)
@connections = [] @connections = []
@automatic_reconnect = true @automatic_reconnect = true
...@@ -824,11 +824,11 @@ def initialize ...@@ -824,11 +824,11 @@ def initialize
# These caches are keyed by klass.name, NOT klass. Keying them by klass # These caches are keyed by klass.name, NOT klass. Keying them by klass
# alone would lead to memory leaks in development mode as all previous # alone would lead to memory leaks in development mode as all previous
# instances of the class would stay in memory. # instances of the class would stay in memory.
@owner_to_pool = ThreadSafe::Cache.new(:initial_capacity => 2) do |h,k| @owner_to_pool = Concurrent::Map.new(:initial_capacity => 2) do |h,k|
h[k] = ThreadSafe::Cache.new(:initial_capacity => 2) h[k] = Concurrent::Map.new(:initial_capacity => 2)
end end
@class_to_pool = ThreadSafe::Cache.new(:initial_capacity => 2) do |h,k| @class_to_pool = Concurrent::Map.new(:initial_capacity => 2) do |h,k|
h[k] = ThreadSafe::Cache.new h[k] = Concurrent::Map.new
end end
end end
......
require 'thread_safe' require 'concurrent'
module ActiveRecord module ActiveRecord
module Type module Type
class TypeMap # :nodoc: class TypeMap # :nodoc:
def initialize def initialize
@mapping = {} @mapping = {}
@cache = ThreadSafe::Cache.new do |h, key| @cache = Concurrent::Map.new do |h, key|
h.fetch_or_store(key, ThreadSafe::Cache.new) h.fetch_or_store(key, Concurrent::Map.new)
end end
end end
......
* Replaced deprecated `ThreadSafe::Cache` with its successor `Concurrent::Map` now that
the thread_safe gem has been merged into concurrent-ruby.
*Jerry D'Antonio*
* Updated Unicode version to 8.0.0 * Updated Unicode version to 8.0.0
*Anshul Sharma* *Anshul Sharma*
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
s.add_dependency 'json', '~> 1.7', '>= 1.7.7' s.add_dependency 'json', '~> 1.7', '>= 1.7.7'
s.add_dependency 'tzinfo', '~> 1.1' s.add_dependency 'tzinfo', '~> 1.1'
s.add_dependency 'minitest', '~> 5.1' s.add_dependency 'minitest', '~> 5.1'
s.add_dependency 'thread_safe','~> 0.3', '>= 0.3.4' s.add_dependency 'concurrent-ruby', '~> 1.0.0.pre2', '< 2.0.0'
s.add_dependency 'concurrent-ruby', '~> 0.9.1'
s.add_dependency 'method_source' s.add_dependency 'method_source'
end end
require 'set' require 'set'
require 'thread' require 'thread'
require 'thread_safe' require 'concurrent'
require 'pathname' require 'pathname'
require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attribute_accessors'
...@@ -585,7 +585,7 @@ def remove_unloadable_constants! ...@@ -585,7 +585,7 @@ def remove_unloadable_constants!
class ClassCache class ClassCache
def initialize def initialize
@store = ThreadSafe::Cache.new @store = Concurrent::Map.new
end end
def empty? def empty?
......
require 'thread_safe' require 'concurrent'
require 'active_support/core_ext/array/prepend_and_append' require 'active_support/core_ext/array/prepend_and_append'
require 'active_support/i18n' require 'active_support/i18n'
...@@ -25,7 +25,7 @@ module Inflector ...@@ -25,7 +25,7 @@ module Inflector
# singularization rules that is runs. This guarantees that your rules run # singularization rules that is runs. This guarantees that your rules run
# before any of the rules that may already have been loaded. # before any of the rules that may already have been loaded.
class Inflections class Inflections
@__instance__ = ThreadSafe::Cache.new @__instance__ = Concurrent::Map.new
class Uncountables < Array class Uncountables < Array
def initialize def initialize
......
require 'thread_safe' require 'concurrent'
require 'openssl' require 'openssl'
module ActiveSupport module ActiveSupport
...@@ -28,7 +28,7 @@ def generate_key(salt, key_size=64) ...@@ -28,7 +28,7 @@ def generate_key(salt, key_size=64)
class CachingKeyGenerator class CachingKeyGenerator
def initialize(key_generator) def initialize(key_generator)
@key_generator = key_generator @key_generator = key_generator
@cache_keys = ThreadSafe::Cache.new @cache_keys = Concurrent::Map.new
end end
# Returns a derived key suitable for use. The default key_size is chosen # Returns a derived key suitable for use. The default key_size is chosen
......
require 'mutex_m' require 'mutex_m'
require 'thread_safe' require 'concurrent'
module ActiveSupport module ActiveSupport
module Notifications module Notifications
...@@ -12,7 +12,7 @@ class Fanout ...@@ -12,7 +12,7 @@ class Fanout
def initialize def initialize
@subscribers = [] @subscribers = []
@listeners_for = ThreadSafe::Cache.new @listeners_for = Concurrent::Map.new
super super
end end
...@@ -51,7 +51,7 @@ def publish(name, *args) ...@@ -51,7 +51,7 @@ def publish(name, *args)
end end
def listeners_for(name) def listeners_for(name)
# this is correctly done double-checked locking (ThreadSafe::Cache's lookups have volatile semantics) # this is correctly done double-checked locking (Concurrent::Map's lookups have volatile semantics)
@listeners_for[name] || synchronize do @listeners_for[name] || synchronize do
# use synchronisation when accessing @subscribers # use synchronisation when accessing @subscribers
@listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) }
......
require 'tzinfo' require 'tzinfo'
require 'thread_safe' require 'concurrent'
require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/try'
...@@ -189,7 +189,7 @@ class TimeZone ...@@ -189,7 +189,7 @@ class TimeZone
UTC_OFFSET_WITH_COLON = '%s%02d:%02d' UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(':', '') UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(':', '')
@lazy_zones_map = ThreadSafe::Cache.new @lazy_zones_map = Concurrent::Map.new
class << self class << self
# Assumes self represents an offset from UTC in seconds (as returned from # Assumes self represents an offset from UTC in seconds (as returned from
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册