================
@@ -65,15 +66,21 @@ class PipeEvent : public MainLoopWindows::IOEvent {
   }
 
   void WillPoll() override {
-    if (!m_monitor_thread.joinable())
-      m_monitor_thread = std::thread(&PipeEvent::Monitor, this);
+    // If the m_event is signaled, wait until it is consumed before telling the
+    // monitor thread to continue.
+    if (WaitForSingleObject(m_event, /*dwMilliseconds=*/0) == WAIT_TIMEOUT &&
+        WaitForSingleObject(m_ready, /*dwMilliseconds=*/0) == WAIT_TIMEOUT)
+      SetEvent(m_ready);
----------------
labath wrote:

This is equivalent. I'm just adding some comments to explain why it is correct.
```suggestion
    if (WaitForSingleObject(m_event, /*dwMilliseconds=*/0) != WAIT_TIMEOUT) {
      // The thread has already signalled that the data is available. No need 
for further polling until we consume that event.
      return;
    }
    if (WaitForSingleObject(m_ready, /*dwMilliseconds=*/0) != WAIT_TIMEOUT) {
      // The thread is already waiting for data to become available.
      return;
    }
    // Start waiting.
    SetEvent(m_ready);
```

https://github.com/llvm/llvm-project/pull/147438
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to