Method: Fluent::Counter::MutexHash#synchronize_keys
- Defined in:
- lib/fluent/counter/mutex_hash.rb
#synchronize_keys(*keys) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fluent/counter/mutex_hash.rb', line 74 def synchronize_keys(*keys) return if keys.empty? keys = keys.dup while key = keys.shift @mutex.lock mutex = @mutex_hash[key] unless mutex v = Mutex.new @mutex_hash[key] = v mutex = v end if mutex.try_lock @mutex.unlock yield @data_store, key mutex.unlock else # release global lock @mutex.unlock keys.push(key) # failed lock, retry this key end end end |