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