Pass self to lock methods.

This avoids frequent recomputation of
Thread::Current/pthread_getspecific.

Also add a futex based reader/writer mutex that is disabled.

Change-Id: I118fdb99ef1d1c4bfda6446ba3a0d8b6ab31eaee
diff --git a/src/locks.cc b/src/locks.cc
new file mode 100644
index 0000000..20bf81c
--- /dev/null
+++ b/src/locks.cc
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "locks.h"
+
+#include "mutex.h"
+
+namespace art {
+
+ReaderWriterMutex* Locks::mutator_lock_ = NULL;
+Mutex* Locks::thread_list_lock_ = NULL;
+Mutex* Locks::classlinker_classes_lock_ = NULL;
+ReaderWriterMutex* Locks::heap_bitmap_lock_ = NULL;
+Mutex* Locks::abort_lock_ = NULL;
+Mutex* Locks::logging_lock_ = NULL;
+Mutex* Locks::unexpected_signal_lock_ = NULL;
+Mutex* Locks::thread_suspend_count_lock_ = NULL;
+
+void Locks::Init() {
+  if (logging_lock_ != NULL) {
+    // Already initialized.
+    DCHECK(mutator_lock_ != NULL);
+    DCHECK(thread_list_lock_ != NULL);
+    DCHECK(classlinker_classes_lock_ != NULL);
+    DCHECK(heap_bitmap_lock_ != NULL);
+    DCHECK(abort_lock_ != NULL);
+    DCHECK(logging_lock_ != NULL);
+    DCHECK(unexpected_signal_lock_ != NULL);
+    DCHECK(thread_suspend_count_lock_ != NULL);
+  } else {
+    logging_lock_ = new Mutex("logging lock", kLoggingLock, true);
+    abort_lock_ = new Mutex("abort lock", kAbortLock, true);
+    DCHECK(mutator_lock_ == NULL);
+    mutator_lock_ = new ReaderWriterMutex("mutator lock", kMutatorLock);
+    DCHECK(thread_list_lock_ == NULL);
+    thread_list_lock_ = new Mutex("thread list lock", kThreadListLock);
+    DCHECK(classlinker_classes_lock_ == NULL);
+    classlinker_classes_lock_ = new Mutex("ClassLinker classes lock", kClassLinkerClassesLock);
+    DCHECK(heap_bitmap_lock_ == NULL);
+    heap_bitmap_lock_ = new ReaderWriterMutex("heap bitmap lock", kHeapBitmapLock);
+    DCHECK(unexpected_signal_lock_ == NULL);
+    unexpected_signal_lock_ = new Mutex("unexpected signal lock", kUnexpectedSignalLock, true);
+    DCHECK(thread_suspend_count_lock_ == NULL);
+    thread_suspend_count_lock_ = new Mutex("thread suspend count lock", kThreadSuspendCountLock);
+  }
+}
+
+}  // namespace art