use class variable for Mutex instead of Const

This commit is contained in:
Pawel Chojnacki 2018-01-19 15:04:37 +01:00
parent 83ae172145
commit 27359dbf22

View file

@ -1,8 +1,13 @@
# rubocop:disable Style/ClassVars
module Gitlab module Gitlab
module Metrics module Metrics
module Concern module Concern
extend ActiveSupport::Concern extend ActiveSupport::Concern
MUTEX = Mutex.new
included do
@@_metric_provider_mutex = Mutex.new
end
class_methods do class_methods do
def reload_metric!(name) def reload_metric!(name)
@ -37,7 +42,7 @@ module Gitlab
end end
def synchronized_cache_fill(key) def synchronized_cache_fill(key)
MUTEX.synchronize do @@_metric_provider_mutex.synchronize do
@_metrics_provider_cache ||= {} @_metrics_provider_cache ||= {}
@_metrics_provider_cache[key] ||= yield @_metrics_provider_cache[key] ||= yield
end end