summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2021-09-04 13:36:25 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-09-04 13:36:25 +0000
commit9edb9b9b9d2321725e215eae901e50c3595bf442 (patch)
tree1413702420fb5ee287b77706f79baecfb9185c02
parent9382d321536ea96ba4ed20d79d85e8dae3e0998d (diff)
parentd4da905ba12bfcd9b967a47583f875bbcafeeda2 (diff)
Do not acquire runtime_shutdown_lock_ in Abort() am: d4da905ba1
Original change: https://googleplex-android-review.googlesource.com/c/platform/art/+/15754305 Change-Id: I54b78ea75590a453dcbe47ea599c849e878dd48b
-rw-r--r--runtime/runtime.cc4
-rw-r--r--runtime/runtime.h14
2 files changed, 13 insertions, 5 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 433f564b2d..6c99c1fa8d 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -410,7 +410,7 @@ Runtime::~Runtime() {
while (threads_being_born_ > 0) {
shutdown_cond_->Wait(self);
}
- shutting_down_ = true;
+ SetShuttingDown();
}
// Shutdown and wait for the daemons.
CHECK(self != nullptr);
@@ -641,7 +641,7 @@ void Runtime::Abort(const char* msg) {
// May be coming from an unattached thread.
if (Thread::Current() == nullptr) {
Runtime* current = Runtime::Current();
- if (current != nullptr && current->IsStarted() && !current->IsShuttingDown(nullptr)) {
+ if (current != nullptr && current->IsStarted() && !current->IsShuttingDownUnsafe()) {
// We do not flag this to the unexpected-signal handler so that that may dump the stack.
abort();
UNREACHABLE();
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 68456cd37b..b2093a303c 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -222,7 +222,13 @@ class Runtime {
bool IsShuttingDown(Thread* self);
bool IsShuttingDownLocked() const REQUIRES(Locks::runtime_shutdown_lock_) {
- return shutting_down_;
+ return shutting_down_.load(std::memory_order_relaxed);
+ }
+ bool IsShuttingDownUnsafe() const {
+ return shutting_down_.load(std::memory_order_relaxed);
+ }
+ void SetShuttingDown() REQUIRES(Locks::runtime_shutdown_lock_) {
+ shutting_down_.store(true, std::memory_order_relaxed);
}
size_t NumberOfThreadsBeingBorn() const REQUIRES(Locks::runtime_shutdown_lock_) {
@@ -1190,8 +1196,10 @@ class Runtime {
// Waited upon until no threads are being born.
std::unique_ptr<ConditionVariable> shutdown_cond_ GUARDED_BY(Locks::runtime_shutdown_lock_);
- // Set when runtime shutdown is past the point that new threads may attach.
- bool shutting_down_ GUARDED_BY(Locks::runtime_shutdown_lock_);
+ // Set when runtime shutdown is past the point that new threads may attach. Usually
+ // GUARDED_BY(Locks::runtime_shutdown_lock_). But we need to check it in Abort without the
+ // lock, because we may already own it.
+ std::atomic<bool> shutting_down_;
// The runtime is starting to shutdown but is blocked waiting on shutdown_cond_.
bool shutting_down_started_ GUARDED_BY(Locks::runtime_shutdown_lock_);