Sha256: 2a125806bc61fc290e2780a52e1331813cb8d4d87a3cfcc6b748fa6552393629
Contents?: true
Size: 448 Bytes
Versions: 11
Compression:
Stored size: 448 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
11 entries across 11 versions & 1 rubygems