Add additional support for Thread::Current() == NULL.
Added checks for Thread::Current() == NULL so that we don't crash in Runtime::~Runtime() when we have to wait for a concurrent GC to complete.
Change-Id: I3164c01f3eb668c7e8fa29c8a0d5a48b8f0e4fb1
diff --git a/src/thread.h b/src/thread.h
index e48f444..6904d4a 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -655,10 +655,20 @@
class ScopedThreadStateChange {
public:
ScopedThreadStateChange(Thread* thread, ThreadState new_state) : thread_(thread) {
+ if (thread_ == NULL) {
+ // Value chosen arbitrarily and won't be used in the destructor since thread_ == NULL.
+ old_thread_state_ = kTerminated;
+ CHECK(Runtime::Current()->IsShuttingDown());
+ return;
+ }
old_thread_state_ = thread_->SetState(new_state);
}
~ScopedThreadStateChange() {
+ if (thread_ == NULL) {
+ CHECK(Runtime::Current()->IsShuttingDown());
+ return;
+ }
thread_->SetState(old_thread_state_);
}