Creates a new ConditionVariable
# File lib/em-synchrony/thread.rb, line 74 def initialize @waiters = [] end
# File lib/em-synchrony/thread.rb, line 94 def _wakeup(mutex, fiber) if alive = fiber.alive? EM.next_tick { mutex._wakeup(fiber) } end alive end
Wakes up all threads waiting for this lock.
# File lib/em-synchrony/thread.rb, line 116 def broadcast @waiters.each do |mutex, fiber| _wakeup(mutex, fiber) end @waiters.clear self end
Wakes up the first thread in line waiting for this lock.
# File lib/em-synchrony/thread.rb, line 106 def signal while (pair = @waiters.shift) break if _wakeup(*pair) end self end
Releases the lock held in mutex and waits; reacquires the lock on wakeup.
If timeout is given, this method returns after timeout seconds passed, even if no other thread doesn't signal.
# File lib/em-synchrony/thread.rb, line 84 def wait(mutex, timeout=nil) current = Fiber.current pair = [mutex, current] @waiters << pair mutex.sleep timeout do @waiters.delete pair end self end
Generated with the Darkfish Rdoc Generator 2.