Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(869)

Unified Diff: src/ports/SkTime_Unix.cpp

Issue 250243002: Add nanosecond timer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: sigh, just use %u Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkTypes.h ('k') | src/ports/SkTime_win.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkTime_Unix.cpp
diff --git a/src/ports/SkTime_Unix.cpp b/src/ports/SkTime_Unix.cpp
index f519a69d07c2843a60427ea385a5d79b11dd765c..cdf7f3d947c94c8d042a1b553ed8857eaf5acb58 100644
--- a/src/ports/SkTime_Unix.cpp
+++ b/src/ports/SkTime_Unix.cpp
@@ -12,10 +12,8 @@
#include <sys/time.h>
#include <time.h>
-void SkTime::GetDateTime(DateTime* dt)
-{
- if (dt)
- {
+void SkTime::GetDateTime(DateTime* dt) {
+ if (dt) {
time_t m_time;
time(&m_time);
struct tm* tstruct;
@@ -31,9 +29,33 @@ void SkTime::GetDateTime(DateTime* dt)
}
}
-SkMSec SkTime::GetMSecs()
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds
+#ifdef __MACH__
+# include <mach/mach_time.h>
+
+namespace {
+
+struct ConversionFactor {
+ ConversionFactor() {
+ mach_timebase_info_data_t timebase;
+ mach_timebase_info(&timebase);
+ toNanos = (double) timebase.numer / timebase.denom;
+ }
+ double toNanos;
+};
+
+} // namespace
+
+SkNSec SkTime::GetNSecs() {
+ static ConversionFactor convert; // Since already know we're on Mac, this is threadsafe.
+ return mach_absolute_time() * convert.toNanos;
}
+
+#else // Linux, presumably all others too
+
+SkNSec SkTime::GetNSecs() {
+ struct timespec time;
+ clock_gettime(CLOCK_MONOTONIC, &time);
+ return (SkNSec)(time.tv_sec * 1000000000 + time.tv_nsec);
+}
+
+#endif
« no previous file with comments | « include/core/SkTypes.h ('k') | src/ports/SkTime_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698