summaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-09 10:17:15 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-09 10:17:15 +0000
commite1b11ddf323607d98a72b97cb4c67e2e02ad05e8 (patch)
treede7b0bb99331f154218e67e14c2585d7ff994a19 /thread.c
parent53eaeb68d99af659b48f45a0b4b7226e3427786a (diff)
downloadruby-e1b11ddf323607d98a72b97cb4c67e2e02ad05e8.tar.gz
ruby-e1b11ddf323607d98a72b97cb4c67e2e02ad05e8.tar.xz
ruby-e1b11ddf323607d98a72b97cb4c67e2e02ad05e8.zip
* thread.c (timeofday): use monotonic clock. based on a patch
from zimbatm <zimbatm@oree.ch> in [ruby-core:16627]. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/thread.c b/thread.c
index f7a4b8ba7..21d43edc2 100644
--- a/thread.c
+++ b/thread.c
@@ -674,9 +674,18 @@ rb_thread_sleep_forever()
static double
timeofday(void)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+ struct timespec tp;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
+ return (double)tp.tv_sec + (double)tp.tv_nsec * 1e-9;
+ } else
+#endif
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
+ }
}
static void