Sha256: 7e22f51e06d0d7cdaaecd5d0c173da0fcc435da290d378778c9b1ecab32cee8a

Contents?: true

Size: 474 Bytes

Versions: 5

Compression:

Stored size: 474 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
        mutex.synchronize do
          @__counter ||= 1
          result = @__counter
          @__counter += 1
          result
        end
      end

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

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
vagrantup-0.8.2 lib/vagrant/util/counter.rb
vagrantup-0.8.1 lib/vagrant/util/counter.rb
vagrantup-0.8.0 lib/vagrant/util/counter.rb
vagrant-0.8.2 lib/vagrant/util/counter.rb
vagrant-0.8.1 lib/vagrant/util/counter.rb