Class: Tochtli::BaseController::Dispatcher::ProcessCounter
- Inherits:
-
Object
- Object
- Tochtli::BaseController::Dispatcher::ProcessCounter
- Includes:
- MonitorMixin
- Defined in:
- lib/tochtli/base_controller.rb
Instance Method Summary collapse
- #decrement ⇒ Object
- #increment ⇒ Object
-
#initialize ⇒ ProcessCounter
constructor
A new instance of ProcessCounter.
- #wait(timeout) ⇒ Object
Constructor Details
#initialize ⇒ ProcessCounter
Returns a new instance of ProcessCounter.
301 302 303 304 305 |
# File 'lib/tochtli/base_controller.rb', line 301 def initialize super @count = 0 @cv = new_cond end |
Instance Method Details
#decrement ⇒ Object
313 314 315 316 317 318 |
# File 'lib/tochtli/base_controller.rb', line 313 def decrement synchronize do @count -= 1 if @count > 0 @cv.signal if @count == 0 end end |
#increment ⇒ Object
307 308 309 310 311 |
# File 'lib/tochtli/base_controller.rb', line 307 def increment synchronize do @count += 1 end end |
#wait(timeout) ⇒ Object
320 321 322 323 324 |
# File 'lib/tochtli/base_controller.rb', line 320 def wait(timeout) synchronize do @cv.wait(timeout) unless @count == 0 end end |