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 25 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 38 def broadcast raise_unless_locked! @cv.broadcast end
signal()
click to toggle source
# File lib/mongo/condition_variable.rb, line 43 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 32 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 52 def raise_unless_locked! unless @lock.owned? raise ArgumentError, "the lock must be owned when calling this method" end end