class MonitorMixin::ConditionVariable

A condition variable associated with a monitor. Do not instantiate directly. @see MonitorMixin#new_cond

Public Class Methods

new(monitor) click to toggle source
# File lib/monitor.rb, line 69
def initialize(monitor)
  @monitor = monitor
  @cond = monitor.__send__(:mon_class_lookup,:ConditionVariable).new
end

Public Instance Methods

broadcast() click to toggle source

Wakes up all threads waiting for this lock.

# File lib/monitor.rb, line 62
def broadcast
  @monitor.__send__(:mon_check_owner)
  @cond.broadcast
end
signal() click to toggle source

Wakes up the first thread in line waiting for this lock.

# File lib/monitor.rb, line 54
def signal
  @monitor.__send__(:mon_check_owner)
  @cond.signal
end
wait(timeout = nil) click to toggle source

Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup. @param [Numeric] timeout maximum time, in seconds, to wait for a signal @return [true]

# File lib/monitor.rb, line 20
def wait(timeout = nil)
  @monitor.__send__(:mon_check_owner)
  count = @monitor.__send__(:mon_exit_for_cond)
  begin
    @cond.wait(@monitor.instance_variable_get("@mon_mutex"), timeout)
    return true
  ensure
    @monitor.__send__(:mon_enter_for_cond, count)
  end
end
wait_until() click to toggle source

Calls wait repeatedly until the given block yields a truthy value.

@return [true]

# File lib/monitor.rb, line 45
def wait_until
  until yield
    wait
  end
end
wait_while() click to toggle source

Calls wait repeatedly while the given block yields a truthy value.

@return [true]

# File lib/monitor.rb, line 35
def wait_while
  while yield
    wait
  end
end