aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Symbol/TypeSystem.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-07-26 19:03:47 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-07-26 19:04:23 +0000
commit7fa27ce4a07f19b07799a767fc29416f3b625afb (patch)
tree27825c83636c4de341eb09a74f49f5d38a15d165 /lldb/source/Symbol/TypeSystem.cpp
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'lldb/source/Symbol/TypeSystem.cpp')
-rw-r--r--lldb/source/Symbol/TypeSystem.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp
index 4eae2c98b12e..24f202930565 100644
--- a/lldb/source/Symbol/TypeSystem.cpp
+++ b/lldb/source/Symbol/TypeSystem.cpp
@@ -36,6 +36,7 @@ size_t LanguageSet::Size() const { return bitvector.count(); }
bool LanguageSet::Empty() const { return bitvector.none(); }
bool LanguageSet::operator[](unsigned i) const { return bitvector[i]; }
+TypeSystem::TypeSystem() = default;
TypeSystem::~TypeSystem() = default;
static TypeSystemSP CreateInstanceHelper(lldb::LanguageType language,
@@ -216,11 +217,21 @@ void TypeSystemMap::Clear() {
void TypeSystemMap::ForEach(
std::function<bool(lldb::TypeSystemSP)> const &callback) {
- std::lock_guard<std::mutex> guard(m_mutex);
+
+ // The callback may call into this function again causing
+ // us to lock m_mutex twice if we held it across the callback.
+ // Since we just care about guarding access to 'm_map', make
+ // a local copy and iterate over that instead.
+ collection map_snapshot;
+ {
+ std::lock_guard<std::mutex> guard(m_mutex);
+ map_snapshot = m_map;
+ }
+
// Use a std::set so we only call the callback once for each unique
// TypeSystem instance.
llvm::DenseSet<TypeSystem *> visited;
- for (auto &pair : m_map) {
+ for (auto &pair : map_snapshot) {
TypeSystem *type_system = pair.second.get();
if (!type_system || visited.count(type_system))
continue;