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


8
9
10
11
12
13
14
15
16
17
# 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

#mutexObject


19
20
21
# File 'lib/vagrant/util/counter.rb', line 19

def mutex
  @__counter_mutex ||= Mutex.new
end