[WTF] Add clock_gettime based monotonicallyIncreasingTime implementation for Linux...
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Dec 2017 14:17:06 +0000 (14:17 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Dec 2017 14:17:06 +0000 (14:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181175

Reviewed by Michael Catanzaro.

Use platform-provided POSIX APIs to get monotonic time.

* wtf/CurrentTime.cpp:
(WTF::monotonicallyIncreasingTime):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226304 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/CurrentTime.cpp

index 86419ff..4c7eb3b 100644 (file)
@@ -1,3 +1,15 @@
+2017-12-27  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Add clock_gettime based monotonicallyIncreasingTime implementation for Linux and BSDs
+        https://bugs.webkit.org/show_bug.cgi?id=181175
+
+        Reviewed by Michael Catanzaro.
+
+        Use platform-provided POSIX APIs to get monotonic time.
+
+        * wtf/CurrentTime.cpp:
+        (WTF::monotonicallyIncreasingTime):
+
 2017-12-26  Carlos Alberto Lopez Perez  <clopez@igalia.com>
 
         REGRESSION(r225769): Build error with constexpr std::max // std::min in libdstdc++4
index 182475c..f20043a 100644 (file)
@@ -267,6 +267,15 @@ double monotonicallyIncreasingTime()
     return (mach_absolute_time() * timebaseInfo.numer) / (1.0e9 * timebaseInfo.denom);
 }
 
+#elif OS(LINUX) || OS(FREEBSD) || OS(OPENBSD) || OS(NETBSD)
+
+double monotonicallyIncreasingTime()
+{
+    struct timespec ts { };
+    clock_gettime(CLOCK_MONOTONIC, &ts);
+    return static_cast<double>(ts.tv_sec) + ts.tv_nsec / 1.0e9;
+}
+
 #else
 
 double monotonicallyIncreasingTime()