Resolve wait timeout in ResultDispatcher::NotifyCallbackThreadLoop

ResultDispatcher::NotifyCallbackThreadLoop wait event after event
is notified and then cause wait timeout. Patch code to check notified flag before wait.

Bug: 192460320
Bug: 192536631

Test: 1. Test basic photo shot and front/rear camera switch function
correctly. And check there is not long idle time in CLOSE stage
      2. P21 Camera Test Checklist & CTS test pass

Change-Id: Ib503bfec73a85df35368fd997a5cc835cd99c583
diff --git a/common/hal/utils/result_dispatcher.cc b/common/hal/utils/result_dispatcher.cc
index bf34ede..6443e8f 100644
--- a/common/hal/utils/result_dispatcher.cc
+++ b/common/hal/utils/result_dispatcher.cc
@@ -228,8 +228,11 @@
       failed = true;
     }
   }
-
-  notify_callback_condition_.notify_one();
+  {
+    std::unique_lock<std::mutex> lock(notify_callback_lock);
+    is_result_shutter_updated_ = true;
+    notify_callback_condition_.notify_one();
+  }
   return failed ? UNKNOWN_ERROR : OK;
 }
 
@@ -256,8 +259,11 @@
 
   shutter_it->second.timestamp_ns = timestamp_ns;
   shutter_it->second.ready = true;
-
-  notify_callback_condition_.notify_one();
+  {
+    std::unique_lock<std::mutex> lock(notify_callback_lock);
+    is_result_shutter_updated_ = true;
+    notify_callback_condition_.notify_one();
+  }
   return OK;
 }
 
@@ -393,12 +399,14 @@
       ALOGV("%s: NotifyCallbackThreadLoop exits.", __FUNCTION__);
       return;
     }
-
-    if (notify_callback_condition_.wait_for(
-            lock, std::chrono::milliseconds(kCallbackThreadTimeoutMs)) ==
-        std::cv_status::timeout) {
-      PrintTimeoutMessages();
+    if (!is_result_shutter_updated_) {
+      if (notify_callback_condition_.wait_for(
+              lock, std::chrono::milliseconds(kCallbackThreadTimeoutMs)) ==
+          std::cv_status::timeout) {
+        PrintTimeoutMessages();
+      }
     }
+    is_result_shutter_updated_ = false;
   }
 }
 
diff --git a/common/hal/utils/result_dispatcher.h b/common/hal/utils/result_dispatcher.h
index ba97086..74f4b4a 100644
--- a/common/hal/utils/result_dispatcher.h
+++ b/common/hal/utils/result_dispatcher.h
@@ -187,6 +187,9 @@
 
   // Protected by notify_callback_lock.
   bool notify_callback_thread_exiting = false;
+
+  // State of callback thread is notified or not.
+  volatile bool is_result_shutter_updated_ = false;
 };
 
 }  // namespace google_camera_hal