Clean up the use of condition variables in the HeapWorker.

Except for the timed wait case, use the error checking function
wrappers for all condition variable uses.  Also, do not accept an
EINTR return value for the timed wait.  These functions are never
supposed to return EINTR.

Change-Id: I867522b9ecea34dbe29ecc6bef1b3e3586c48414
diff --git a/vm/alloc/HeapWorker.c b/vm/alloc/HeapWorker.c
index edd4b98..a671118 100644
--- a/vm/alloc/HeapWorker.c
+++ b/vm/alloc/HeapWorker.c
@@ -76,9 +76,7 @@
      * so this should not get stuck.
      */
     while (!gDvm.heapWorkerReady) {
-        int cc __attribute__ ((__unused__));
-        cc = pthread_cond_wait(&gDvm.heapWorkerCond, &gDvm.heapWorkerLock);
-        assert(cc == 0);
+        dvmWaitCond(&gDvm.heapWorkerCond, &gDvm.heapWorkerLock);
     }
 
     dvmUnlockMutex(&gDvm.heapWorkerLock);
@@ -303,7 +301,6 @@
 static void* heapWorkerThreadStart(void* arg)
 {
     Thread *self = dvmThreadSelf();
-    int cc;
 
     UNUSED_PARAMETER(arg);
 
@@ -312,8 +309,7 @@
     /* tell the main thread that we're ready */
     dvmLockMutex(&gDvm.heapWorkerLock);
     gDvm.heapWorkerReady = true;
-    cc = pthread_cond_signal(&gDvm.heapWorkerCond);
-    assert(cc == 0);
+    dvmSignalCond(&gDvm.heapWorkerCond);
     dvmUnlockMutex(&gDvm.heapWorkerLock);
 
     dvmLockMutex(&gDvm.heapWorkerLock);
@@ -325,8 +321,7 @@
         dvmChangeStatus(NULL, THREAD_VMWAIT);
 
         /* Signal anyone who wants to know when we're done. */
-        cc = pthread_cond_broadcast(&gDvm.heapWorkerIdleCond);
-        assert(cc == 0);
+        dvmBroadcastCond(&gDvm.heapWorkerIdleCond);
 
         /* Trim the heap if we were asked to. */
         trimtime = gDvm.gcHeap->heapWorkerNextTrim;
@@ -374,6 +369,7 @@
 
         /* sleep until signaled */
         if (timedwait) {
+            int cc __attribute__ ((__unused__));
 #ifdef HAVE_TIMEDWAIT_MONOTONIC
             cc = pthread_cond_timedwait_monotonic(&gDvm.heapWorkerCond,
                     &gDvm.heapWorkerLock, &trimtime);
@@ -381,10 +377,9 @@
             cc = pthread_cond_timedwait(&gDvm.heapWorkerCond,
                     &gDvm.heapWorkerLock, &trimtime);
 #endif
-            assert(cc == 0 || cc == ETIMEDOUT || cc == EINTR);
+            assert(cc == 0 || cc == ETIMEDOUT);
         } else {
-            cc = pthread_cond_wait(&gDvm.heapWorkerCond, &gDvm.heapWorkerLock);
-            assert(cc == 0);
+            dvmWaitCond(&gDvm.heapWorkerCond, &gDvm.heapWorkerLock);
         }
 
         /* dvmChangeStatus() may block;  don't hold heapWorkerLock.
@@ -410,14 +405,11 @@
  */
 void dvmSignalHeapWorker(bool shouldLock)
 {
-    int cc;
-
     if (shouldLock) {
         dvmLockMutex(&gDvm.heapWorkerLock);
     }
 
-    cc = pthread_cond_signal(&gDvm.heapWorkerCond);
-    assert(cc == 0);
+    dvmSignalCond(&gDvm.heapWorkerCond);
 
     if (shouldLock) {
         dvmUnlockMutex(&gDvm.heapWorkerLock);
@@ -429,8 +421,6 @@
  */
 void dvmWaitForHeapWorkerIdle()
 {
-    int cc;
-
     assert(gDvm.heapWorkerReady);
 
     dvmChangeStatus(NULL, THREAD_VMWAIT);
@@ -443,8 +433,7 @@
     //     need to detect when this is called from the HeapWorker
     //     context and just give up.
     dvmSignalHeapWorker(false);
-    cc = pthread_cond_wait(&gDvm.heapWorkerIdleCond, &gDvm.heapWorkerLock);
-    assert(cc == 0);
+    dvmWaitCond(&gDvm.heapWorkerIdleCond, &gDvm.heapWorkerLock);
 
     dvmUnlockMutex(&gDvm.heapWorkerLock);