1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#--
# Copyright (c) 2008, 2009 Jeremy Hinegardner
# All rights reserved. See LICENSE and/or COPYING for details.
#++
require 'thread'
module Hitimes
#
# MutexedStats is the start of a threadsafe Stats class. Currently, on MRI
# Ruby the Stats object is already threadsafe, so there is no need to use
# MutexedStats.
#
class MutexedStats < Stats
def initialize
@mutex = Mutex.new
end
# call-seq:
# mutex_stat.update( val ) -> nil
#
# Update the running stats with the new value in a threadsafe manner.
#
def update( value )
@mutex.synchronize do
super( value )
end
end
end
end
|