Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

make metrics access threadsafe

  • Loading branch information...
commit 711e5e2dd86c08a2397aaa04be17a84ed5e8a29f 1 parent ec45d8a
Jordan Sissel authored

Showing 1 changed file with 7 additions and 2 deletions. Show diff stats Hide diff stats

  1. +7 2 lib/cabin/metrics.rb
9 lib/cabin/metrics.rb
@@ -51,6 +51,7 @@ class Cabin::Metrics
51 51 # Get us a new metrics container.
52 52 public
53 53 def initialize
  54 + @metrics_lock = Mutex.new
54 55 @metrics = {}
55 56 end # def initialize
56 57
@@ -76,7 +77,9 @@ def create(instance, name, metric_object)
76 77 if @channel
77 78 @channel.debug("Created metric", :instance => instance, :type => metric_object.class)
78 79 end
79   - return @metrics[metric_name] = metric_object
  80 + return @metrics_lock.synchronize do
  81 + @metrics[metric_name] = metric_object
  82 + end
80 83 end # def create
81 84
82 85 # Create a new Counter metric
@@ -114,6 +117,8 @@ def timer(instance, name=nil)
114 117 # iterate over each metric. yields identifer, metric
115 118 def each(&block)
116 119 # delegate to the @metrics hash until we need something fancier
117   - @metrics.each(&block)
  120 + @metrics_lock.synchronize do
  121 + @metrics.each(&block)
  122 + end
118 123 end # def each
119 124 end # class Cabin::Metrics

0 comments on commit 711e5e2

Please sign in to comment.
Something went wrong with that request. Please try again.