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

Unified Diff: runtime/bin/utils_android.cc

Issue 1519563003: Use a monotonic clock in the implementation of Timer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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 | « runtime/bin/utils.h ('k') | runtime/bin/utils_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/utils_android.cc
diff --git a/runtime/bin/utils_android.cc b/runtime/bin/utils_android.cc
index d96eb5d2cb82ecad5b2f6f80d265232728cada19..db9eb75d2ba6c3736d061497749f59afc51e0a2e 100644
--- a/runtime/bin/utils_android.cc
+++ b/runtime/bin/utils_android.cc
@@ -71,17 +71,21 @@ bool ShellUtils::GetUtf8Argv(int argc, char** argv) {
return false;
}
-int64_t TimerUtils::GetCurrentTimeMilliseconds() {
- return GetCurrentTimeMicros() / 1000;
+int64_t TimerUtils::GetCurrentMonotonicMillis() {
+ return GetCurrentMonotonicMicros() / 1000;
}
-int64_t TimerUtils::GetCurrentTimeMicros() {
- struct timeval tv;
- if (gettimeofday(&tv, NULL) < 0) {
+int64_t TimerUtils::GetCurrentMonotonicMicros() {
+ struct timespec ts;
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
UNREACHABLE();
return 0;
}
- return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
+ // Convert to microseconds.
+ int64_t result = ts.tv_sec;
+ result *= kMicrosecondsPerSecond;
+ result += (ts.tv_nsec / kNanosecondsPerMicrosecond);
+ return result;
}
void TimerUtils::Sleep(int64_t millis) {
« no previous file with comments | « runtime/bin/utils.h ('k') | runtime/bin/utils_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698