Sha256: 475c708f75403427c02c07f8530bd248f15997e69457303de5bab890a690a96b

Contents?: true

Size: 532 Bytes

Versions: 136

Compression:

Stored size: 532 Bytes

Contents

require 'thread'

module Vagrant
  module Util
    # Atomic counter implementation. This is useful for incrementing
    # a counter which is guaranteed to only be used once in its class.
    module Counter
      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

      def mutex
        @__counter_mutex ||= Mutex.new
      end
    end
  end
end

Version data entries

136 entries across 129 versions & 19 rubygems

Version Path
vagrant-1.0.2 lib/vagrant/util/counter.rb
vagrant-1.0.1 lib/vagrant/util/counter.rb
vagrant-1.0.0 lib/vagrant/util/counter.rb
vagrant-0.9.7 lib/vagrant/util/counter.rb
vagrant-0.9.5 lib/vagrant/util/counter.rb
vagrant-0.9.4 lib/vagrant/util/counter.rb
vagrant-0.9.3 lib/vagrant/util/counter.rb
vagrant-0.9.2 lib/vagrant/util/counter.rb
vagrant-0.9.1 lib/vagrant/util/counter.rb
vagrant-0.9.0 lib/vagrant/util/counter.rb
vagrant-0.8.10 lib/vagrant/util/counter.rb
vagrant-0.8.8 lib/vagrant/util/counter.rb
vagrant-0.8.7 lib/vagrant/util/counter.rb
rvagrant-0.8.7.dev lib/vagrant/util/counter.rb
vagrant-0.8.6 lib/vagrant/util/counter.rb
vagrant-0.8.5 lib/vagrant/util/counter.rb