mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Synchronize access to the Gem::Specification::LOAD_CACHE Hash
* It's accessed concurrently, notably when installing a gem with a C extension. https://github.com/rubygems/rubygems/commit/543294d7dd
This commit is contained in:
parent
89bd1df895
commit
2453d16f5e
1 changed files with 8 additions and 3 deletions
|
@ -109,6 +109,7 @@ class Gem::Specification < Gem::BasicSpecification
|
||||||
# rubocop:disable Style/MutableConstant
|
# rubocop:disable Style/MutableConstant
|
||||||
LOAD_CACHE = {} # :nodoc:
|
LOAD_CACHE = {} # :nodoc:
|
||||||
# rubocop:enable Style/MutableConstant
|
# rubocop:enable Style/MutableConstant
|
||||||
|
LOAD_CACHE_MUTEX = Mutex.new
|
||||||
|
|
||||||
private_constant :LOAD_CACHE if defined? private_constant
|
private_constant :LOAD_CACHE if defined? private_constant
|
||||||
|
|
||||||
|
@ -753,7 +754,9 @@ class Gem::Specification < Gem::BasicSpecification
|
||||||
end
|
end
|
||||||
|
|
||||||
def self._clear_load_cache # :nodoc:
|
def self._clear_load_cache # :nodoc:
|
||||||
LOAD_CACHE.clear
|
LOAD_CACHE_MUTEX.synchronize do
|
||||||
|
LOAD_CACHE.clear
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.each_gemspec(dirs) # :nodoc:
|
def self.each_gemspec(dirs) # :nodoc:
|
||||||
|
@ -1105,7 +1108,7 @@ class Gem::Specification < Gem::BasicSpecification
|
||||||
def self.load(file)
|
def self.load(file)
|
||||||
return unless file
|
return unless file
|
||||||
|
|
||||||
_spec = LOAD_CACHE[file]
|
_spec = LOAD_CACHE_MUTEX.synchronize { LOAD_CACHE[file] }
|
||||||
return _spec if _spec
|
return _spec if _spec
|
||||||
|
|
||||||
file = file.dup.untaint
|
file = file.dup.untaint
|
||||||
|
@ -1120,7 +1123,9 @@ class Gem::Specification < Gem::BasicSpecification
|
||||||
|
|
||||||
if Gem::Specification === _spec
|
if Gem::Specification === _spec
|
||||||
_spec.loaded_from = File.expand_path file.to_s
|
_spec.loaded_from = File.expand_path file.to_s
|
||||||
LOAD_CACHE[file] = _spec
|
LOAD_CACHE_MUTEX.synchronize do
|
||||||
|
LOAD_CACHE[file] = _spec
|
||||||
|
end
|
||||||
return _spec
|
return _spec
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue