Class: Lowdown::Threading::Counter
- Inherits:
-
Object
- Object
- Lowdown::Threading::Counter
- Defined in:
- lib/lowdown/threading.rb
Instance Method Summary collapse
- #decrement! ⇒ Object
- #increment! ⇒ Object
-
#initialize(value = 0) ⇒ Counter
constructor
A new instance of Counter.
- #value ⇒ Object
- #value=(value) ⇒ Object
- #zero? ⇒ Boolean
Constructor Details
#initialize(value = 0) ⇒ Counter
Returns a new instance of Counter.
34 35 36 37 |
# File 'lib/lowdown/threading.rb', line 34 def initialize(value = 0) @value = value @mutex = Mutex.new end |
Instance Method Details
#decrement! ⇒ Object
58 59 60 |
# File 'lib/lowdown/threading.rb', line 58 def decrement! @mutex.synchronize { @value -= 1 } end |
#increment! ⇒ Object
54 55 56 |
# File 'lib/lowdown/threading.rb', line 54 def increment! @mutex.synchronize { @value += 1 } end |
#value ⇒ Object
39 40 41 42 43 |
# File 'lib/lowdown/threading.rb', line 39 def value value = nil @mutex.synchronize { value = @value } value end |
#value=(value) ⇒ Object
49 50 51 52 |
# File 'lib/lowdown/threading.rb', line 49 def value=(value) @mutex.synchronize { @value = value } value end |
#zero? ⇒ Boolean
45 46 47 |
# File 'lib/lowdown/threading.rb', line 45 def zero? value.zero? end |