Implement monitors.

Change-Id: Ifc7a801f9cbcdfbc1e1af5c905261dfadaa60f45
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index b9b1ab0..5b4bf21 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -464,9 +464,9 @@
         handle_(handle),
         class_loader_(class_loader),
         jni_on_load_lock_("JNI_OnLoad lock"),
+        jni_on_load_cond_("JNI_OnLoad"),
         jni_on_load_thread_id_(Thread::Current()->GetThinLockId()),
         jni_on_load_result_(kPending) {
-    CHECK_PTHREAD_CALL(pthread_cond_init, (&jni_on_load_cond_, NULL), "jni_on_load_cond_");
   }
 
   Object* GetClassLoader() {
@@ -498,7 +498,7 @@
                   << "JNI_OnLoad...]";
       }
       ScopedThreadStateChange tsc(self, Thread::kVmWait);
-      CHECK_PTHREAD_CALL(pthread_cond_wait, (&jni_on_load_cond_, jni_on_load_lock_.GetImpl()), "JNI_OnLoad");
+      jni_on_load_cond_.Wait(jni_on_load_lock_);
     }
 
     bool okay = (jni_on_load_result_ == kOkay);
@@ -515,7 +515,7 @@
 
     // Broadcast a wakeup to anybody sleeping on the condition variable.
     MutexLock mu(jni_on_load_lock_);
-    CHECK_PTHREAD_CALL(pthread_cond_broadcast, (&jni_on_load_cond_), "JNI_OnLoad");
+    jni_on_load_cond_.Broadcast();
   }
 
   void* FindSymbol(const std::string& symbol_name) {
@@ -541,7 +541,7 @@
   // Guards remaining items.
   Mutex jni_on_load_lock_;
   // Wait for JNI_OnLoad in other thread.
-  pthread_cond_t jni_on_load_cond_;
+  ConditionVariable jni_on_load_cond_;
   // Recursive invocation guard.
   uint32_t jni_on_load_thread_id_;
   // Result of earlier JNI_OnLoad call.
@@ -2186,13 +2186,13 @@
 
   static jint MonitorEnter(JNIEnv* env, jobject java_object) {
     ScopedJniThreadState ts(env);
-    Decode<Object*>(ts, java_object)->MonitorEnter();
+    Decode<Object*>(ts, java_object)->MonitorEnter(ts.Self());
     return ts.Self()->IsExceptionPending() ? JNI_ERR : JNI_OK;
   }
 
   static jint MonitorExit(JNIEnv* env, jobject java_object) {
     ScopedJniThreadState ts(env);
-    Decode<Object*>(ts, java_object)->MonitorExit();
+    Decode<Object*>(ts, java_object)->MonitorExit(ts.Self());
     return ts.Self()->IsExceptionPending() ? JNI_ERR : JNI_OK;
   }