================ @@ -7,27 +7,43 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/MainLoopBase.h" +#include <chrono> using namespace lldb; using namespace lldb_private; -void MainLoopBase::AddPendingCallback(const Callback &callback) { +void MainLoopBase::AddCallback(const Callback &callback, TimePoint point) { + bool interrupt_needed; { std::lock_guard<std::mutex> lock{m_callback_mutex}; - m_pending_callbacks.push_back(callback); + // We need to interrupt the main thread if this callback is scheduled to + // execute at an earlier time than the earliest callback registered so far. + interrupt_needed = m_callbacks.empty() || point < m_callbacks.top().first; + m_callbacks.emplace(point, callback); } - TriggerPendingCallbacks(); + if (interrupt_needed) ---------------- Jlalond wrote:
> I think you're misunderstanding something here. The emplace is always fast - > it just adds > something to the queue and doesn't cause any callbacks to run. > The callbacks will always > be run on the mainloop thread. The interrupt > needs to happen after the insertion to make > sure the other thread observes > the new callback (via the result of GetNextWakeupTime). My concern was purely if we want nanosecond precision, adding into a priority queue (assuming N log N) seemed like it could be slow. On a second look, I think my concern is moot https://github.com/llvm/llvm-project/pull/112895 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits