Class: Google::Protobuf::Internal::AtomicCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/google/protobuf/descriptor_dsl.rb

Instance Method Summary collapse

Constructor Details

#initializeAtomicCounter

Returns a new instance of AtomicCounter.



18
19
20
21
# File 'lib/google/protobuf/descriptor_dsl.rb', line 18

def initialize
  @n = 0
  @mu = Mutex.new
end

Instance Method Details

#get_and_incrementObject



23
24
25
26
27
28
29
# File 'lib/google/protobuf/descriptor_dsl.rb', line 23

def get_and_increment
  n = @n
  @mu.synchronize {
    @n += 1
  }
  return n
end