Class: Obfusk::Atom

Inherits:
Object
  • Object
show all
Defined in:
lib/obfusk/atom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Atom

new Atom with value



21
22
23
24
# File 'lib/obfusk/atom.rb', line 21

def initialize(value)
  @mutex = Mutex.new
  @value = value
end

Instance Attribute Details

#valueObject (readonly) Also known as: _, deref

Returns the value of attribute value.



16
17
18
# File 'lib/obfusk/atom.rb', line 16

def value
  @value
end

Instance Method Details

#swap!(&b) ⇒ Object

atomically swaps the value to be b[oldvalue]; uses with_value



33
34
35
# File 'lib/obfusk/atom.rb', line 33

def swap!(&b)
  with_value { |v| @value = b[v] }
end

#with_value(&b) ⇒ Object

calls block with value; uses a mutex to synchronize



27
28
29
# File 'lib/obfusk/atom.rb', line 27

def with_value(&b)
  @mutex.synchronize { b[value] }
end