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

Unified Diff: runtime/bin/utils_android.cc

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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/socket_macos.cc ('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 e88d248eacb9839179e4d10d29126384011d5cb8..615dae966a2bdc151852484e8cdd330f9f33b4e9 100644
--- a/runtime/bin/utils_android.cc
+++ b/runtime/bin/utils_android.cc
@@ -8,6 +8,7 @@
#include <errno.h> // NOLINT
#include <netdb.h> // NOLINT
#include <sys/time.h> // NOLINT
+#include <time.h> // NOLINT
#include "bin/utils.h"
#include "platform/assert.h"
@@ -98,7 +99,24 @@ int64_t TimerUtils::GetCurrentTimeMicros() {
}
void TimerUtils::Sleep(int64_t millis) {
- usleep(millis * 1000);
+ struct timespec req; // requested.
+ struct timespec rem; // remainder.
+ int64_t micros = millis * kMicrosecondsPerMillisecond;
+ int64_t seconds = micros / kMicrosecondsPerSecond;
+ micros = micros - seconds * kMicrosecondsPerSecond;
+ int64_t nanos = micros * kNanosecondsPerMicrosecond;
+ req.tv_sec = seconds;
+ req.tv_nsec = nanos;
+ while (true) {
+ int r = nanosleep(&req, &rem);
+ if (r == 0) {
+ break;
+ }
+ // We should only ever see an interrupt error.
+ ASSERT(errno == EINTR);
+ // Copy remainder into requested and repeat.
+ req = rem;
+ }
}
} // namespace bin
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/utils_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698