diff options
| author | 2012-01-13 16:49:08 -0800 | |
|---|---|---|
| committer | 2012-01-13 16:49:08 -0800 | |
| commit | 6b3557571e798b60df995f978fa01c0ca1980dfd (patch) | |
| tree | ce56e52d67d20bf3204074b48d2be1d15644ef54 /src | |
| parent | f4222065170130a31513dc63e2c2808db80860f1 (diff) | |
Make pthread_mutex_t destruction safer during shutdown.
If we have suspended daemon threads, they might be holding some of the mutexes
we need to destroy, so we can't assert that we successfully destroyed them. We
still want to assert success where possible, though.
Bug: 5869254
Change-Id: Id4f3af3d40b10045958e7d692b3c9eebafec566d
Diffstat (limited to 'src')
| -rw-r--r-- | src/mutex.cc | 8 | ||||
| -rw-r--r-- | src/runtime.cc | 7 | ||||
| -rw-r--r-- | src/runtime.h | 2 |
3 files changed, 16 insertions, 1 deletions
diff --git a/src/mutex.cc b/src/mutex.cc index 0dfab1163d..7507566729 100644 --- a/src/mutex.cc +++ b/src/mutex.cc @@ -21,6 +21,7 @@ #include "heap.h" // for VERIFY_OBJECT_ENABLED #include "logging.h" #include "utils.h" +#include "runtime.h" #define CHECK_MUTEX_CALL(call, args) CHECK_PTHREAD_CALL(call, args, name_) @@ -36,7 +37,12 @@ Mutex::Mutex(const char* name) : name_(name) { } Mutex::~Mutex() { - CHECK_MUTEX_CALL(pthread_mutex_destroy, (&mutex_)); + int rc = pthread_mutex_destroy(&mutex_); + if (rc != 0) { + errno = rc; + bool shutting_down = Runtime::Current()->IsShuttingDown(); + PLOG(shutting_down ? WARNING : FATAL) << "pthread_mutex_destroy failed for " << name_; + } } void Mutex::Lock() { diff --git a/src/runtime.cc b/src/runtime.cc index e9d5677aab..c203ffd1c3 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -43,6 +43,7 @@ Runtime::Runtime() java_vm_(NULL), jni_stub_array_(NULL), abstract_method_error_stub_array_(NULL), + shutting_down_(false), started_(false), vfprintf_(NULL), exit_(NULL), @@ -58,6 +59,8 @@ Runtime::Runtime() } Runtime::~Runtime() { + shutting_down_ = true; + Dbg::StopJdwp(); // Make sure our internal threads are dead before we start tearing down things they're using. @@ -525,6 +528,10 @@ void Runtime::StartDaemonThreads() { VLOG(startup) << "Runtime::StartDaemonThreads exiting"; } +bool Runtime::IsShuttingDown() const { + return shutting_down_; +} + bool Runtime::IsStarted() const { return started_; } diff --git a/src/runtime.h b/src/runtime.h index d30f465926..913779a549 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -85,6 +85,7 @@ class Runtime { // Starts a runtime, which may cause threads to be started and code to run. void Start(); + bool IsShuttingDown() const; bool IsStarted() const; static Runtime* Current() { @@ -268,6 +269,7 @@ class Runtime { // As returned by ClassLoader.getSystemClassLoader() ClassLoader* system_class_loader_; + bool shutting_down_; bool started_; // Hooks supported by JNI_CreateJavaVM |