Sha256: d1880fe4a004f8b667257be40c61452f91e72f41b21cba73768d461dfe67262a

Contents?: true

Size: 444 Bytes

Versions: 36

Compression:

Stored size: 444 Bytes

Contents

require 'thread'

# Maintains a thread-safe counter wrapped in a Mutex.
class Sqewer::AtomicCounter
  def initialize
    @m, @v = Mutex.new, 0
  end

  # Returns the current value of the counter
  #
  # @return [Fixnum] the current value of the counter
  def to_i
    @m.synchronize { @v + 0 }
  end

  # Increments the counter
  #
  # @return [Fixnum] the current value of the counter
  def increment!
    @m.synchronize { @v += 1 }
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
sqewer-10.0.0 lib/sqewer/atomic_counter.rb
sqewer-9.0.0 lib/sqewer/atomic_counter.rb
sqewer-8.1.0 lib/sqewer/atomic_counter.rb
sqewer-8.1.0.pre.1 lib/sqewer/atomic_counter.rb
sqewer-8.0.3 lib/sqewer/atomic_counter.rb
sqewer-8.0.2 lib/sqewer/atomic_counter.rb
sqewer-8.0.1 lib/sqewer/atomic_counter.rb
sqewer-8.0.0 lib/sqewer/atomic_counter.rb
sqewer-7.0.0 lib/sqewer/atomic_counter.rb
sqewer-6.5.1 lib/sqewer/atomic_counter.rb
sqewer-6.5.0 lib/sqewer/atomic_counter.rb
sqewer-6.4.1 lib/sqewer/atomic_counter.rb
sqewer-6.4.0 lib/sqewer/atomic_counter.rb
sqewer-6.3.0 lib/sqewer/atomic_counter.rb
sqewer-6.2.2 lib/sqewer/atomic_counter.rb
sqewer-6.2.1 lib/sqewer/atomic_counter.rb
sqewer-6.2.0 lib/sqewer/atomic_counter.rb
sqewer-6.1.0 lib/sqewer/atomic_counter.rb
sqewer-6.0.6 lib/sqewer/atomic_counter.rb
sqewer-6.0.5 lib/sqewer/atomic_counter.rb