File: mutexed_stats.rb

package info (click to toggle)
ruby-hitimes 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 388 kB
  • sloc: ruby: 1,196; ansic: 418; java: 265; makefile: 15
file content (32 lines) | stat: -rw-r--r-- 662 bytes parent folder | download | duplicates (5)
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