[Lldb-commits] [lldb] SBDebugger: Add new APIs `AddDestroyCallback` and `RemoveDestroyCallback` (PR #89868)
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 29 13:24:07 PDT 2024
================
@@ -743,9 +743,19 @@ DebuggerSP Debugger::CreateInstance(lldb::LogOutputCallback log_callback,
}
void Debugger::HandleDestroyCallback() {
- if (m_destroy_callback) {
- m_destroy_callback(GetID(), m_destroy_callback_baton);
- m_destroy_callback = nullptr;
+ std::lock_guard<std::recursive_mutex> guard(m_destroy_callback_mutex);
+ const lldb::user_id_t user_id = GetID();
+ // In case one destroy callback adds or removes other destroy callbacks
+ // which aren't taken care of in the same inner loop.
+ while (m_destroy_callback_and_baton.size()) {
+ auto iter = m_destroy_callback_and_baton.begin();
+ while (iter != m_destroy_callback_and_baton.end()) {
+ // Invoke the callback and remove the entry from the map
+ const auto &callback = iter->second.first;
+ const auto &baton = iter->second.second;
+ callback(user_id, baton);
+ iter = m_destroy_callback_and_baton.erase(iter);
+ }
----------------
bulbazord wrote:
Instead of your 2 loop approach, could you not just repeatedly grab and call the first callback in the list? If new ones are added it'll be picked up, if others are removed then the next iteration won't see them.
https://github.com/llvm/llvm-project/pull/89868
More information about the lldb-commits
mailing list