QCamera2: HAL3: Use monotonic timestamp for pthread_cond_timedwait

Wall time may jump forward/backward. Especially when it jumps forward,
pthread_cond_timedwait may return early with TIMEOUT.

Switch to MONOTONIC time base instead.

Bug: 33110475
Change-Id: I63efbe24c49c3f539530d6461e89fbfe62a24920
diff --git a/msm8998/QCamera2/HAL3/QCamera3HWI.cpp b/msm8998/QCamera2/HAL3/QCamera3HWI.cpp
index 175726d..33c8859 100644
--- a/msm8998/QCamera2/HAL3/QCamera3HWI.cpp
+++ b/msm8998/QCamera2/HAL3/QCamera3HWI.cpp
@@ -60,6 +60,7 @@
 extern "C" {
 #include "mm_camera_dbg.h"
 }
+#include "cam_cond.h"
 
 using namespace android;
 
@@ -437,9 +438,9 @@
     //TBD - To see if this hardcoding is needed. Check by printing if this is filled by mctl to 3
     gCamCapability[cameraId]->min_num_pp_bufs = 3;
 
-    pthread_cond_init(&mBuffersCond, NULL);
+    PTHREAD_COND_INIT(&mBuffersCond);
 
-    pthread_cond_init(&mRequestCond, NULL);
+    PTHREAD_COND_INIT(&mRequestCond);
     mPendingLiveRequest = 0;
     mCurrentRequestId = -1;
     pthread_mutex_init(&mMutex, NULL);
@@ -5023,7 +5024,7 @@
     // Added a timed condition wait
     struct timespec ts;
     uint8_t isValidTimeout = 1;
-    rc = clock_gettime(CLOCK_REALTIME, &ts);
+    rc = clock_gettime(CLOCK_MONOTONIC, &ts);
     if (rc < 0) {
       isValidTimeout = 0;
       LOGE("Error reading the real time clock!!");
@@ -5275,7 +5276,7 @@
     }
 
     /* wait on a signal that buffers were received */
-    rc = clock_gettime(CLOCK_REALTIME, &timeout);
+    rc = clock_gettime(CLOCK_MONOTONIC, &timeout);
     if (rc < 0) {
         LOGE("Error reading the real time clock, cannot use timed wait");
     } else {