Module: Threadlock
- Defined in:
- lib/threadlock.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(mod) ⇒ Object
6 7 8 |
# File 'lib/threadlock.rb', line 6 def self.included(mod) mod.extend Threadlock end |
Instance Method Details
#threadlock(*meths, lock: :@___threadlock___) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/threadlock.rb', line 10 def threadlock(*meths, lock: :@___threadlock___) meths.flatten.each do |meth| m = instance_method(meth) define_method(meth) do |*args, &block| (instance_variable_get(lock) or \ instance_variable_set(lock, Monitor.new)) .synchronize do m.bind(self).call(*args, &block) end end end end |