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-unbundled-2.3.6.0 lib/vagrant/util/counter.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/util/counter.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/util/counter.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.9.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.7.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.6.2 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.6.1 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.6.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.5.0 lib/vagrant/util/counter.rb
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.4.0 lib/vagrant/util/counter.rb
vagrant-unbundled-2.2.3.0 lib/vagrant/util/counter.rb