about summary refs log tree commit homepage
path: root/lib/mogilefs.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-05-27 21:59:31 +0000
committerEric Wong <e@80x24.org>2015-05-27 21:59:31 +0000
commit5429893629154e39e0db33f5c98e237b29c7bbdc (patch)
tree9d6bc5f45869e3b433e0425e3f56656c8813e647 /lib/mogilefs.rb
parent44dd54e3c3ae6a771baa17935ebe09ece1616026 (diff)
downloadmogilefs-client-5429893629154e39e0db33f5c98e237b29c7bbdc.tar.gz
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.
Diffstat (limited to 'lib/mogilefs.rb')
-rw-r--r--lib/mogilefs.rb10
1 files changed, 10 insertions, 0 deletions
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