composer: Bail out early if previous WaitForCommitDoneAsync is stuck

Change-Id: I1ec169f558df0a136b4c0f821679f193fc71972b
diff --git a/composer/hwc_session.cpp b/composer/hwc_session.cpp
index a5b1c1b..330cc49 100644
--- a/composer/hwc_session.cpp
+++ b/composer/hwc_session.cpp
@@ -4193,6 +4193,14 @@
 
 int HWCSession::WaitForCommitDoneAsync(hwc2_display_t display, int client_id) {
   std::chrono::milliseconds span(5000);
+  if (commit_done_future_.valid()) {
+    std::future_status status = commit_done_future_.wait_for(std::chrono::milliseconds(0));
+    if (status != std::future_status::ready) {
+      // Previous task is stuck. Bail out early.
+      return -ETIMEDOUT;
+    }
+  }
+
   commit_done_future_ = std::async([](HWCSession* session, hwc2_display_t display, int client_id) {
                                       return session->WaitForCommitDone(display, client_id);
                                      }, this, display, client_id);