Class: TimeScheduler::Counter
- Inherits:
-
Object
- Object
- TimeScheduler::Counter
- Defined in:
- lib/time_scheduler/scheduler.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.
183 184 185 186 |
# File 'lib/time_scheduler/scheduler.rb', line 183 def initialize @count = 0 @mutex = Mutex.new end |
Instance Method Details
#decr ⇒ Object
194 195 196 197 198 199 |
# File 'lib/time_scheduler/scheduler.rb', line 194 def decr @mutex.synchronize do @count -= 1 if @count > 0 @count end end |
#incr ⇒ Object
188 189 190 191 192 |
# File 'lib/time_scheduler/scheduler.rb', line 188 def incr @mutex.synchronize do @count += 1 end end |
#reset ⇒ Object
201 202 203 204 205 |
# File 'lib/time_scheduler/scheduler.rb', line 201 def reset @mutex.synchronize do @count = 0 end end |