Class: Thread::Task::Counter
- Inherits:
-
Object
- Object
- Thread::Task::Counter
- Defined in:
- lib/thread/task/base.rb
Instance Method Summary collapse
- #decr ⇒ Object
- #incr ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
89 90 91 92 |
# File 'lib/thread/task/base.rb', line 89 def initialize @count = 0 @mutex = Mutex.new end |
Instance Method Details
#decr ⇒ Object
100 101 102 103 104 105 |
# File 'lib/thread/task/base.rb', line 100 def decr @mutex.synchronize do @count -= 1 if @count > 0 @count end end |
#incr ⇒ Object
94 95 96 97 98 |
# File 'lib/thread/task/base.rb', line 94 def incr @mutex.synchronize do @count += 1 end end |
#reset ⇒ Object
107 108 109 110 111 |
# File 'lib/thread/task/base.rb', line 107 def reset @mutex.synchronize do @count = 0 end end |