bulbazord created this revision. bulbazord added reviewers: jingham, teemperor, JDevlieghere, clayborg, aprantl. bulbazord requested review of this revision. Herald added a project: LLDB.
It is easy to accidentally introduce a deadlock by having the callback passed to Language::ForEach also attempt to acquire the same lock. It is easy enough to disallow the callback from calling anything in Language directly, but it may happen through a series of other function/method calls. The solution I am proposing is to tighten the lock in Language::ForEach so that it is only held as we gather the currently loaded language plugins. We store them in a vector and then iterate through them with the callback so that the callback can't introduce a callback. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D109013 Files: lldb/source/Target/Language.cpp Index: lldb/source/Target/Language.cpp =================================================================== --- lldb/source/Target/Language.cpp +++ lldb/source/Target/Language.cpp @@ -108,10 +108,18 @@ } }); - std::lock_guard<std::mutex> guard(GetLanguagesMutex()); - LanguagesMap &map(GetLanguagesMap()); - for (const auto &entry : map) { - if (!callback(entry.second.get())) + std::vector<Language *> loaded_plugins; + { + std::lock_guard<std::mutex> guard(GetLanguagesMutex()); + LanguagesMap &map(GetLanguagesMap()); + for (const auto &entry : map) { + if (entry.second) + loaded_plugins.push_back(entry.second.get()); + } + } + + for (auto *lang : loaded_plugins) { + if (!callback(lang)) break; } }
Index: lldb/source/Target/Language.cpp =================================================================== --- lldb/source/Target/Language.cpp +++ lldb/source/Target/Language.cpp @@ -108,10 +108,18 @@ } }); - std::lock_guard<std::mutex> guard(GetLanguagesMutex()); - LanguagesMap &map(GetLanguagesMap()); - for (const auto &entry : map) { - if (!callback(entry.second.get())) + std::vector<Language *> loaded_plugins; + { + std::lock_guard<std::mutex> guard(GetLanguagesMutex()); + LanguagesMap &map(GetLanguagesMap()); + for (const auto &entry : map) { + if (entry.second) + loaded_plugins.push_back(entry.second.get()); + } + } + + for (auto *lang : loaded_plugins) { + if (!callback(lang)) break; } }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits