Implement mutex requeueing for cv broadcasts.

Make the mutex guarding a condition variable part of its state. On a
broadcast requeue waiters on the mutex so they are awoken as the mutex
is unlocked (thereby avoiding thundering herds). Explicit futex use
still guarded behind ART_USE_FUTEXES which remains disabled as I'm
unhappy with some of the warts of mutex usage. Uploading so that the API
changes can stabilize.

Change-Id: Iedb601856ccd8bbc3a64da4ba0cee82246e7bcbf
diff --git a/src/jdwp/jdwp_event.cc b/src/jdwp/jdwp_event.cc
index 2865f3a..de6a235 100644
--- a/src/jdwp/jdwp_event.cc
+++ b/src/jdwp/jdwp_event.cc
@@ -537,8 +537,9 @@
     pReq->invoke_needed_ = false;
 
     VLOG(jdwp) << "invoke complete, signaling and self-suspending";
-    MutexLock mu(Thread::Current(), pReq->lock_);
-    pReq->cond_.Signal();
+    Thread* self = Thread::Current();
+    MutexLock mu(self, pReq->lock_);
+    pReq->cond_.Signal(self);
   }
 }
 
@@ -595,7 +596,7 @@
   while (event_thread_id_ != 0) {
     VLOG(jdwp) << StringPrintf("event in progress (%#llx), %#llx sleeping", event_thread_id_, threadId);
     waited = true;
-    event_thread_cond_.Wait(self, event_thread_lock_);
+    event_thread_cond_.Wait(self);
   }
 
   if (waited || threadId != 0) {
@@ -615,14 +616,15 @@
    * function is called by dvmSuspendSelf(), and the transition back
    * to RUNNING would confuse it.
    */
-  MutexLock mu(Thread::Current(), event_thread_lock_);
+  Thread* self = Thread::Current();
+  MutexLock mu(self, event_thread_lock_);
 
   CHECK_NE(event_thread_id_, 0U);
   VLOG(jdwp) << StringPrintf("cleared event token (%#llx)", event_thread_id_);
 
   event_thread_id_ = 0;
 
-  event_thread_cond_.Signal();
+  event_thread_cond_.Signal(self);
 }