Skip to content

Commit 6128ef3

Browse files
author
git apple-llvm automerger
committed
Merge commit '54a8a2d989ca' from swift/release/5.9 into stable/20221013
2 parents ccba7f4 + 54a8a2d commit 6128ef3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lldb/source/Symbol/TypeSystem.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,21 @@ void TypeSystemMap::Clear() {
230230

231231
void TypeSystemMap::ForEach(
232232
std::function<bool(lldb::TypeSystemSP)> const &callback) {
233-
std::lock_guard<std::mutex> guard(m_mutex);
233+
234+
// The callback may call into this function again causing
235+
// us to lock m_mutex twice if we held it across the callback.
236+
// Since we just care about guarding access to 'm_map', make
237+
// a local copy and iterate over that instead.
238+
collection map_snapshot;
239+
{
240+
std::lock_guard<std::mutex> guard(m_mutex);
241+
map_snapshot = m_map;
242+
}
243+
234244
// Use a std::set so we only call the callback once for each unique
235245
// TypeSystem instance.
236246
llvm::DenseSet<TypeSystem *> visited;
237-
for (auto &pair : m_map) {
247+
for (auto &pair : map_snapshot) {
238248
TypeSystem *type_system = pair.second.get();
239249
if (!type_system || visited.count(type_system))
240250
continue;

0 commit comments

Comments
 (0)