From 5429893629154e39e0db33f5c98e237b29c7bbdc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 27 May 2015 21:59:31 +0000 Subject: use monotonic clock if possible on Ruby 2.1+ The monotonic clock is immune to discontinuous time jumps while still taking into account clock imperfections, making it appropriate for calculating time differences and timeouts. --- lib/mogilefs.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/mogilefs.rb') diff --git a/lib/mogilefs.rb b/lib/mogilefs.rb index dd60e91..6059836 100644 --- a/lib/mogilefs.rb +++ b/lib/mogilefs.rb @@ -5,6 +5,16 @@ # Client usage information is available in MogileFS::MogileFS. module MogileFS + if defined?(Process::CLOCK_MONOTONIC) + def self.now + Process.clock_gettime(Process::CLOCK_MONOTONIC) + end + else + def self.now + Time.now.to_f + end + end + # Standard error class for most MogileFS-specific errors class Error < StandardError; end -- cgit v1.2.3-24-ge0c7