Thread tidying.

Add is_started_ boolean to Thread so that we don't read an uncreated
pthread_key_self_, don't start twice or call shutdown when not started.
Don't use a MutexLock in ThreadList::Unregister, as the MutexLock will
hold a copy of self for the thread that's deleted.
Don't memory leak the resume condition variable.

Change-Id: I767968a9f785e560fc9e356a339e684de5ce2ffc
diff --git a/src/thread.h b/src/thread.h
index 37f2721..f642d56 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -101,11 +101,15 @@
   // Reset internal state of child thread after fork.
   void InitAfterFork();
 
-  static Thread* Current() __attribute__ ((pure)) {
+  static Thread* Current() {
     // We rely on Thread::Current returning NULL for a detached thread, so it's not obvious
     // that we can replace this with a direct %fs access on x86.
-    void* thread = pthread_getspecific(Thread::pthread_key_self_);
-    return reinterpret_cast<Thread*>(thread);
+    if(!is_started_) {
+      return NULL;
+    } else {
+      void* thread = pthread_getspecific(Thread::pthread_key_self_);
+      return reinterpret_cast<Thread*>(thread);
+    }
   }
 
   static Thread* FromManagedThread(const ScopedObjectAccessUnchecked& ts,
@@ -617,6 +621,9 @@
 
   static void ThreadExitCallback(void* arg);
 
+  // Has Thread::Startup been called?
+  static bool is_started_;
+
   // TLS key used to retrieve the Thread*.
   static pthread_key_t pthread_key_self_;