diff --git a/lib/concurrent/atomic/condition.rb b/lib/concurrent/atomic/condition.rb index bb85183b3..1eba2e8e2 100644 --- a/lib/concurrent/atomic/condition.rb +++ b/lib/concurrent/atomic/condition.rb @@ -42,13 +42,13 @@ def initialize # @param [Object] timeout nil means no timeout # @return [Result] def wait(mutex, timeout = nil) - start_time = Time.now.to_f + start_time = clock_time @condition.wait(mutex, timeout) if timeout.nil? Result.new(nil) else - Result.new(start_time + timeout - Time.now.to_f) + Result.new(start_time + timeout - clock_time) end end @@ -66,5 +66,17 @@ def broadcast true end + private + + if defined?(Process::CLOCK_MONOTONIC) + def clock_time + Process.clock_gettime Process::CLOCK_MONOTONIC + end + else + def clock_time + Time.now.to_f + end + end + end end