ART: Make gAborting an atomic
It's probably overkill for the abort path, but make it safe,
nonetheless.
Test: m test-art-host
Change-Id: I8d333ea5f01ad43bb98e71cd2c89902ced1bd68d
diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc
index 2be9067..4776357 100644
--- a/runtime/base/logging.cc
+++ b/runtime/base/logging.cc
@@ -85,7 +85,7 @@
LogVerbosity gLogVerbosity;
-unsigned int gAborting = 0;
+std::atomic<unsigned int> gAborting(0);
static std::unique_ptr<std::string> gCmdLine;
static std::unique_ptr<std::string> gProgramInvocationName;
diff --git a/runtime/base/logging.h b/runtime/base/logging.h
index d8954e5..15f9353 100644
--- a/runtime/base/logging.h
+++ b/runtime/base/logging.h
@@ -102,7 +102,7 @@
// 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive
// aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown
// makes forward progress.
-extern unsigned int gAborting;
+extern std::atomic<unsigned int> gAborting;
// Configure logging based on ANDROID_LOG_TAGS environment variable.
// We need to parse a string that looks like
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 72dee77..46b4392 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -483,10 +483,15 @@
};
void Runtime::Abort(const char* msg) {
- gAborting++; // set before taking any locks
+ auto old_value = gAborting.fetch_add(1); // set before taking any locks
#ifdef ART_TARGET_ANDROID
- android_set_abort_message(msg);
+ if (old_value == 0) {
+ // Only set the first abort message.
+ android_set_abort_message(msg);
+ }
+#else
+ UNUSED(old_value);
#endif
// Ensure that we don't have multiple threads trying to abort at once,