Class: Tochtli::BaseController::Dispatcher::ProcessCounter

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/tochtli/base_controller.rb

Instance Method Summary collapse

Constructor Details

#initializeProcessCounter

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

#decrementObject



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

#incrementObject



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