class EventMachine::Synchrony::Thread::ConditionVariable

Public Class Methods

new() click to toggle source

Creates a new ConditionVariable

# File lib/em-synchrony/thread.rb, line 74
def initialize
  @waiters = []
end

Public Instance Methods

_wakeup(mutex, fiber) click to toggle source
# 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
broadcast() click to toggle source

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
signal() click to toggle source

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
wait(mutex, timeout=nil) click to toggle source

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