drm_hwcomposer: avoid potential race condition between worker init and exit
am: ba494c8efc

Change-Id: Ie97c1ca0ed08d48b6bf15c9cf37d9ff58cc40fee
diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp
index a1baed1..b0d1f1e 100644
--- a/drmdisplaycompositor.cpp
+++ b/drmdisplaycompositor.cpp
@@ -191,6 +191,16 @@
 void DrmDisplayCompositor::FrameWorker::QueueFrame(
     std::unique_ptr<DrmDisplayComposition> composition, int status) {
   Lock();
+
+  // Block queue if it gets too large. Otherwise composition will
+  // start stacking up and eat limited resources (file descriptors)
+  // allocated for these.
+  while (frame_queue_.size() >= DRM_DISPLAY_COMPOSITOR_MAX_QUEUE_DEPTH) {
+    Unlock();
+    sched_yield();
+    Lock();
+  }
+
   FrameState frame;
   frame.composition = std::move(composition);
   frame.status = status;
diff --git a/drmeventlistener.cpp b/drmeventlistener.cpp
index 0514aa6..2607eef 100644
--- a/drmeventlistener.cpp
+++ b/drmeventlistener.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <assert.h>
+
 #define LOG_TAG "hwc-drm-event-listener"
 
 #include "drmeventlistener.h"