module Vagrant::Util::Counter
Atomic counter implementation. This is useful for incrementing a counter which is guaranteed to only be used once in its class.
Public Instance Methods
get_and_update_counter(name=nil)
click to toggle source
# File lib/vagrant/util/counter.rb, line 8 def get_and_update_counter(name=nil) name ||= :global mutex.synchronize do @__counter ||= Hash.new(1) result = @__counter[name] @__counter[name] += 1 result end end
mutex()
click to toggle source
# File lib/vagrant/util/counter.rb, line 19 def mutex @__counter_mutex ||= Mutex.new end