Class: Bob::Engine::Threaded::ThreadPool::Incrementor
- Inherits:
-
Object
- Object
- Bob::Engine::Threaded::ThreadPool::Incrementor
- Defined in:
- lib/bob/engine/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/bob/engine/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.
48 49 50 |
# File 'lib/bob/engine/threaded.rb', line 48 def dec(v = 1) sync { @v -= v } end |
#inc(v = 1) ⇒ Object
Add the given value to self, default 1.
43 44 45 |
# File 'lib/bob/engine/threaded.rb', line 43 def inc(v = 1) sync { @v += v } end |
#inspect ⇒ Object
Simply shows the value inspect for convenience.
53 54 55 |
# File 'lib/bob/engine/threaded.rb', line 53 def inspect @v.inspect end |
#to_i ⇒ Object
Extract the value.
58 59 60 |
# File 'lib/bob/engine/threaded.rb', line 58 def to_i @v end |