summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-05-04 09:53:43 -0700
committerMathieu Chartier <mathieuc@google.com>2015-05-04 10:03:41 -0700
commit46578a4a3bf235fde35ed80c6e6cbe8fb5f06b48 (patch)
treef7ac3fcc1c55b52527fce0cc4d17c60e8547f09c
parent414369a2e3f23e1408fc1cbf4f623014bd95cb8f (diff)
downloadandroid_art-46578a4a3bf235fde35ed80c6e6cbe8fb5f06b48.tar.gz
android_art-46578a4a3bf235fde35ed80c6e6cbe8fb5f06b48.tar.bz2
android_art-46578a4a3bf235fde35ed80c6e6cbe8fb5f06b48.zip
Fix NanoSleep and add test
Fixed a bug where tv_nsec was't between 0 and 999,999,999. (cherry picked from commit 0b063d9ba7a11779667c0888e9f3495de0118b74) Bug: 14450052 Change-Id: I30b29a716bfa63c6b57d589dd1102d2ca934c061
-rw-r--r--runtime/utils.cc4
-rw-r--r--runtime/utils_test.cc6
2 files changed, 8 insertions, 2 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc
index e18af00694..650214f67b 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -262,8 +262,8 @@ uint64_t ThreadCpuNanoTime() {
void NanoSleep(uint64_t ns) {
timespec tm;
- tm.tv_sec = 0;
- tm.tv_nsec = ns;
+ tm.tv_sec = ns / MsToNs(1000);
+ tm.tv_nsec = ns - static_cast<uint64_t>(tm.tv_sec) * MsToNs(1000);
nanosleep(&tm, nullptr);
}
diff --git a/runtime/utils_test.cc b/runtime/utils_test.cc
index 259fe3372e..195de0c121 100644
--- a/runtime/utils_test.cc
+++ b/runtime/utils_test.cc
@@ -515,4 +515,10 @@ TEST_F(UtilsTest, IsAbsoluteUint) {
EXPECT_FALSE(IsAbsoluteUint<32>(UINT_MAX_plus1));
}
+TEST_F(UtilsTest, TestSleep) {
+ auto start = NanoTime();
+ NanoSleep(MsToNs(1500));
+ EXPECT_GT(NanoTime() - start, MsToNs(1000));
+}
+
} // namespace art