[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 1 01:08:50 PDT 2025


================
@@ -31,6 +34,122 @@ static DWORD ToTimeout(std::optional<MainLoopWindows::TimePoint> point) {
   return ceil<milliseconds>(dur).count();
 }
 
+namespace {
+
+class PipeEvent : public MainLoopWindows::IOEvent {
+public:
+  explicit PipeEvent(HANDLE handle)
+      : IOEvent((IOObject::WaitableHandle)CreateEventW(
+            NULL, /*bManualReset=*/FALSE,
+            /*bInitialState=*/FALSE, NULL)),
+        m_handle(handle), m_ready(CreateEventW(NULL, /*bManualReset=*/FALSE,
+                                               /*bInitialState=*/FALSE, NULL)) {
+    assert(event && ready);
+  }
+
+  ~PipeEvent() override {
+    if (m_monitor_thread.joinable()) {
+      m_stopped = true;
+      SetEvent(m_ready);
+      // Keep trying to cancel ReadFile() until the thread exits.
+      do {
+        CancelIoEx((HANDLE)m_handle, /*lpOverlapped=*/NULL);
+      } while (WaitForSingleObject(m_monitor_thread.native_handle(), 1) ==
+               WAIT_TIMEOUT);
+      m_monitor_thread.join();
+    }
+    CloseHandle((HANDLE)m_event);
+    CloseHandle(m_ready);
+  }
+
+  void WillPoll() override {
+    if (!m_monitor_thread.joinable())
----------------
labath wrote:

Okay, I see what you mean. Looks good then.

https://github.com/llvm/llvm-project/pull/145621


More information about the lldb-commits mailing list