Skip to content

Commit 54a8a2d

Browse files
Merge pull request #6780 from Michael137/bugfix/lldb-typesystem-deadlock-to-5.9
[lldb][TypeSystem] ForEach: Don't hold the TypeSystemMap lock across callback
2 parents 4471e44 + ac6d5b1 commit 54a8a2d

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)