Class: Bob::Engine::Threaded::ThreadPool::Incrementor

Inherits:
Object
  • Object
show all
Defined in:
lib/bob/engine/threaded.rb

Overview

A thread safe single value for use as a counter.

Instance Method Summary collapse

Constructor Details

#initialize(v = 0) ⇒ Incrementor

The value passed in will be the initial value.



36
37
38
39
# File 'lib/bob/engine/threaded.rb', line 36

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.



47
48
49
# File 'lib/bob/engine/threaded.rb', line 47

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/bob/engine/threaded.rb', line 42

def inc(v = 1)
  sync { @v += v }
end

#inspectObject

Simply shows the value inspect for convenience.



52
53
54
# File 'lib/bob/engine/threaded.rb', line 52

def inspect
  @v.inspect
end

#to_iObject

Extract the value.



57
58
59
# File 'lib/bob/engine/threaded.rb', line 57

def to_i
  @v
end