[Lldb-commits] [lldb] [lldb] Improving synchronization of MainLoopWindows. (PR #147438)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 8 00:40:59 PDT 2025
================
@@ -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
More information about the lldb-commits
mailing list