class Mongo::ConditionVariable

This is an implementation of a condition variable.

@api private

Public Class Methods

new(lock = Mutex.new) click to toggle source
# File lib/mongo/condition_variable.rb, line 24
def initialize(lock = Mutex.new)
  @lock = lock
  @cv = ::ConditionVariable.new
end

Public Instance Methods

broadcast() click to toggle source
# File lib/mongo/condition_variable.rb, line 37
def broadcast
  raise_unless_locked!
  @cv.broadcast
end
signal() click to toggle source
# File lib/mongo/condition_variable.rb, line 42
def signal
  raise_unless_locked!
  @cv.signal
end
wait(timeout = nil) click to toggle source

Waits for the condition variable to be signaled up to timeout seconds. If condition variable is not signaled, returns after timeout seconds.

# File lib/mongo/condition_variable.rb, line 31
def wait(timeout = nil)
  raise_unless_locked!
  return false if timeout && timeout < 0
  @cv.wait(@lock, timeout)
end

Private Instance Methods

raise_unless_locked!() click to toggle source
# File lib/mongo/condition_variable.rb, line 51
def raise_unless_locked!
  unless @lock.owned?
    raise ArgumentError, "the lock must be owned when calling this method"
  end
end