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() {
230
230
231
231
void TypeSystemMap::ForEach (
232
232
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
+
234
244
// Use a std::set so we only call the callback once for each unique
235
245
// TypeSystem instance.
236
246
llvm::DenseSet<TypeSystem *> visited;
237
- for (auto &pair : m_map ) {
247
+ for (auto &pair : map_snapshot ) {
238
248
TypeSystem *type_system = pair.second .get ();
239
249
if (!type_system || visited.count (type_system))
240
250
continue ;
You can’t perform that action at this time.
0 commit comments