================
@@ -938,15 +954,30 @@ llvm::Error DAP::Loop() {
     StopEventHandlers();
   });
 
-  while (!disconnecting || !m_queue.empty()) {
+  while (true) {
     std::unique_lock<std::mutex> lock(m_queue_mutex);
-    m_queue_cv.wait(lock, [&] { return disconnecting || !m_queue.empty(); });
+    m_queue_cv.wait(lock, [&] {
+      return disconnecting || !m_queue.empty() ||
+             (!m_launch_sequence_queue.empty() && configuration_done);
+    });
 
-    if (m_queue.empty())
+    if (disconnecting)
       break;
 
-    Message next = m_queue.front();
-    m_queue.pop_front();
+    bool is_launch_seqeuence =
+        !m_launch_sequence_queue.empty() && configuration_done;
+
+    auto &active_queue =
+        is_launch_seqeuence ? m_launch_sequence_queue : m_queue;
+
+    assert(!active_queue.empty() &&
+           "shouldn't have gotten past the wait with an empty queue");
----------------
ashgti wrote:

What if we kept the messages in the `m_launch_sequence_queue` until 
`configurationDone` and in `configurationDone` `PostRun()` we move the items in 
the `m_launch_sequence_queue` into the front of `m_queue`?

Then this loop would only need to check the `m_queue.empty()` and have a few 
less branching paths.

We could add a helper like:

```
void DAP::SetConfigurationDone() {
  std::lock_guard<std::mutex> guard(m_queue_mutex);
  std::copy(m_launch_sequence_queue.front(), m_launch_sequence_queue.end(), 
std::front_inserter(m_queue));
  configuration_done = true;
}
```

and call in `ConfigurationDoneRequestHandler`.

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

Reply via email to