File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -230,11 +230,21 @@ void TypeSystemMap::Clear() {
230230
231231void 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 ;
You can’t perform that action at this time.
0 commit comments