Module: MutexedAccessors

Includes:
AccessorsGenerator
Defined in:
lib/ruby-threading-toolkit/mutexed_accessors.rb

Instance Method Summary collapse

Instance Method Details

#mutexed_accessors(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruby-threading-toolkit/mutexed_accessors.rb', line 20

def mutexed_accessors(*args)
  generate_accessors(args) do |attr, mutex|
    attr = attr.to_s
    {:line => (__LINE__+1), :file => __FILE__, :code => "        def \#{attr}\n          @\#{mutex}.synchronize { @\#{attr} }\n        end\n        \n        def \#{attr}= value\n          @\#{mutex}.synchronize { @\#{attr} = value}\n        end\n      EOS\n    }\n  end\nend\n"