From 7fa27ce4a07f19b07799a767fc29416f3b625afb Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 26 Jul 2023 21:03:47 +0200 Subject: Vendor import of llvm-project main llvmorg-17-init-19304-gd0b54bb50e51, the last commit before the upstream release/17.x branch was created. --- lldb/source/Symbol/TypeSystem.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lldb/source/Symbol/TypeSystem.cpp') 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 const &callback) { - std::lock_guard 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 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 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; -- cgit v1.3