Class: Rubcask::Concurrency::FakeAtomicFixnum
- Inherits:
-
Object
- Object
- Rubcask::Concurrency::FakeAtomicFixnum
- Defined in:
- lib/rubcask/concurrency/fake_atomic_fixnum.rb
Overview
A fake class that implements interface of Concurrent::AtomicFixnum without actually doing any synchronization
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #compare_and_set(expected, update) ⇒ Object
- #decrement(delta = 1) ⇒ Object
- #increment(delta = 1) ⇒ Object
-
#initialize(initial = 0) ⇒ FakeAtomicFixnum
constructor
A new instance of FakeAtomicFixnum.
- #update ⇒ Object
Constructor Details
#initialize(initial = 0) ⇒ FakeAtomicFixnum
Returns a new instance of FakeAtomicFixnum.
9 10 11 |
# File 'lib/rubcask/concurrency/fake_atomic_fixnum.rb', line 9 def initialize(initial = 0) @value = initial end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/rubcask/concurrency/fake_atomic_fixnum.rb', line 8 def value @value end |
Instance Method Details
#compare_and_set(expected, update) ⇒ Object
13 14 15 16 |
# File 'lib/rubcask/concurrency/fake_atomic_fixnum.rb', line 13 def compare_and_set(expected, update) @value = update if @value == expected @value end |
#decrement(delta = 1) ⇒ Object
18 19 20 21 |
# File 'lib/rubcask/concurrency/fake_atomic_fixnum.rb', line 18 def decrement(delta = 1) @value -= delta @value end |
#increment(delta = 1) ⇒ Object
23 24 25 26 |
# File 'lib/rubcask/concurrency/fake_atomic_fixnum.rb', line 23 def increment(delta = 1) @value += delta @value end |
#update ⇒ Object
28 29 30 31 |
# File 'lib/rubcask/concurrency/fake_atomic_fixnum.rb', line 28 def update @value = yield(@value) @value end |