Class: Ninja::Threaded::ThreadPool::Incrementor
- Inherits:
-
Object
- Object
- Ninja::Threaded::ThreadPool::Incrementor
- Defined in:
- lib/ninja/threaded.rb
Overview
A thread safe single value for use as a counter.
Instance Method Summary collapse
-
#dec(v = 1) ⇒ Object
Subtract the given value to self, default 1.
-
#inc(v = 1) ⇒ Object
Add the given value to self, default 1.
-
#initialize(v = 0) ⇒ Incrementor
constructor
The value passed in will be the initial value.
-
#inspect ⇒ Object
Simply shows the value inspect for convenience.
-
#to_i ⇒ Object
Extract the value.
Constructor Details
#initialize(v = 0) ⇒ Incrementor
The value passed in will be the initial value.
37 38 39 40 |
# File 'lib/ninja/threaded.rb', line 37 def initialize(v = 0) @m = Mutex.new @v = v end |
Instance Method Details
#dec(v = 1) ⇒ Object
Subtract the given value to self, default 1.
46 47 48 |
# File 'lib/ninja/threaded.rb', line 46 def dec(v = 1) sync { @v -= v } end |
#inc(v = 1) ⇒ Object
Add the given value to self, default 1.
42 43 44 |
# File 'lib/ninja/threaded.rb', line 42 def inc(v = 1) sync { @v += v } end |
#inspect ⇒ Object
Simply shows the value inspect for convenience.
50 51 52 |
# File 'lib/ninja/threaded.rb', line 50 def inspect @v.inspect end |
#to_i ⇒ Object
Extract the value.
54 55 56 |
# File 'lib/ninja/threaded.rb', line 54 def to_i @v end |