Class: Google::Protobuf::Internal::AtomicCounter
- Inherits:
-
Object
- Object
- Google::Protobuf::Internal::AtomicCounter
- Defined in:
- lib/google/protobuf/descriptor_dsl.rb
Instance Method Summary collapse
- #get_and_increment ⇒ Object
-
#initialize ⇒ AtomicCounter
constructor
A new instance of AtomicCounter.
Constructor Details
#initialize ⇒ AtomicCounter
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_increment ⇒ Object
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 |