Use static thread safety analysis when available, and fix the bugs GCC finds.

It's impossible to express the Heap locking and the ThreadList locking with
GCC, but Clang is supposed to be able to do it. This patch does what's possible
for now.

Change-Id: Ib64a890c9d27c6ce255d5003cb755c2ef1beba95
diff --git a/src/signal_catcher.cc b/src/signal_catcher.cc
index 5c7a30f..d3c799c 100644
--- a/src/signal_catcher.cc
+++ b/src/signal_catcher.cc
@@ -155,8 +155,8 @@
   Runtime::Current()->GetHeap()->CollectGarbage(false);
 }
 
-int SignalCatcher::WaitForSignal(SignalSet& signals) {
-  ScopedThreadStateChange tsc(thread_, kVmWait);
+int SignalCatcher::WaitForSignal(Thread* self, SignalSet& signals) {
+  ScopedThreadStateChange tsc(self, kVmWait);
 
   // Signals for sigwait() must be blocked but not ignored.  We
   // block signals like SIGQUIT for all threads, so the condition
@@ -166,7 +166,7 @@
   if (!ShouldHalt()) {
     // Let the user know we got the signal, just in case the system's too screwed for us to
     // actually do what they want us to do...
-    LOG(INFO) << *thread_ << ": reacting to signal " << signal_number;
+    LOG(INFO) << *self << ": reacting to signal " << signal_number;
 
     // If anyone's holding locks (which might prevent us from getting back into state Runnable), say so...
     Runtime::Current()->DumpLockHolders(LOG(INFO));
@@ -181,11 +181,13 @@
 
   Runtime* runtime = Runtime::Current();
   runtime->AttachCurrentThread("Signal Catcher", true, Thread::GetSystemThreadGroup());
-  Thread::Current()->SetState(kRunnable);
+
+  Thread* self = Thread::Current();
+  self->SetState(kRunnable);
 
   {
     MutexLock mu(signal_catcher->lock_);
-    signal_catcher->thread_ = Thread::Current();
+    signal_catcher->thread_ = self;
     signal_catcher->cond_.Broadcast();
   }
 
@@ -195,7 +197,7 @@
   signals.Add(SIGUSR1);
 
   while (true) {
-    int signal_number = signal_catcher->WaitForSignal(signals);
+    int signal_number = signal_catcher->WaitForSignal(self, signals);
     if (signal_catcher->ShouldHalt()) {
       runtime->DetachCurrentThread();
       return NULL;