Class: Lowdown::Threading::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/lowdown/threading.rb

Instance Method Summary collapse

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

#valueObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/lowdown/threading.rb', line 45

def zero?
  value.zero?
end