class Garcon::Condition
Condition
is a better implementation of standard Ruby ConditionVariable. The biggest difference is the wait return value: Condition#wait
returns Condition::Result
which make possible to know if waiting thread has been woken up by an another thread (using signal
or broadcast
) or due to timeout.
Every wait
must be guarded by a locked Mutex or a ThreadError will be risen. Although it’s not mandatory, it’s recommended to call also signal
and broadcast
within the same mutex
Public Class Methods
new()
click to toggle source
# File lib/garcon/task/condition.rb, line 59 def initialize @condition = ConditionVariable.new end
Public Instance Methods
broadcast()
click to toggle source
Wakes up all waiting threads
@return [true]
# File lib/garcon/task/condition.rb, line 94 def broadcast @condition.broadcast true end
signal()
click to toggle source
Wakes up a waiting thread
@return [true]
# File lib/garcon/task/condition.rb, line 86 def signal @condition.signal true end
wait(mutex, timeout = nil)
click to toggle source
@param [Mutex] mutex
The locked mutex guarding the wait.
@param [Object] timeout
Nil means no timeout.
@return [Result]
@!macro monotonic_clock_warning
# File lib/garcon/task/condition.rb, line 72 def wait(mutex, timeout = nil) start_time = Garcon.monotonic_time @condition.wait(mutex, timeout) if timeout.nil? Result.new(nil) else Result.new(start_time + timeout - Garcon.monotonic_time) end end