Module: Vagrant::Util::Counter
- Defined in:
- lib/vagrant/util/counter.rb
Overview
Atomic counter implementation. This is useful for incrementing a counter which is guaranteed to only be used once in its class.
Instance Method Summary collapse
Instance Method Details
#get_and_update_counter(name = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vagrant/util/counter.rb', line 11 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 ⇒ Object
22 23 24 |
# File 'lib/vagrant/util/counter.rb', line 22 def mutex @__counter_mutex ||= Mutex.new end |