diff options
author | Mathieu Chartier <mathieuc@google.com> | 2016-01-06 18:28:21 -0800 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2016-03-16 15:57:04 -0700 |
commit | 3c7f69523f5ff5be188b6d95193e5a68d6d28d80 (patch) | |
tree | 0245329facdb8617ece13bcd7ec45e4a0d0dbbef | |
parent | 71b0b6ef9f7cdb1c07c492796607bbe7d5fd1cb6 (diff) | |
download | android_art-3c7f69523f5ff5be188b6d95193e5a68d6d28d80.tar.gz android_art-3c7f69523f5ff5be188b6d95193e5a68d6d28d80.tar.bz2 android_art-3c7f69523f5ff5be188b6d95193e5a68d6d28d80.zip |
Reduce sleep duration in SuspendAllDaemonThreads
Previously we unconditionally slept for 200ms which caused runtime
shutdown to take 200ms longer than required.
Reduces runtime shutdown time for "am" from ~200ms to ~10ms.
Bug: 26351700
Change-Id: I7fd0059cb3b04dba0acc4a1754e76c89ec867f85
-rw-r--r-- | runtime/thread_list.cc | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc index b697b43a77..ba6eb5bb13 100644 --- a/runtime/thread_list.cc +++ b/runtime/thread_list.cc @@ -1060,8 +1060,9 @@ void ThreadList::SuspendAllDaemonThreads() { } // Give the threads a chance to suspend, complaining if they're slow. bool have_complained = false; - for (int i = 0; i < 10; ++i) { - usleep(200 * 1000); + static constexpr size_t kTimeoutMicroseconds = 200 * 1000; + static constexpr size_t kSleepMicroseconds = 1000; + for (size_t i = 0; i < kTimeoutMicroseconds / kSleepMicroseconds; ++i) { bool all_suspended = true; for (const auto& thread : list_) { if (thread != self && thread->GetState() == kRunnable) { @@ -1075,8 +1076,9 @@ void ThreadList::SuspendAllDaemonThreads() { if (all_suspended) { return; } + usleep(kSleepMicroseconds); } - LOG(ERROR) << "suspend all daemons failed"; + LOG(ERROR) << "timed out suspending all daemon threads"; } void ThreadList::Register(Thread* self) { DCHECK_EQ(self, Thread::Current()); |