[Lldb-commits] [lldb] [lldb] fix dead lock in TypeCategoryMap.cpp (PR #87540)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 5 09:16:46 PDT 2024


================
@@ -25,19 +25,25 @@ TypeCategoryMap::TypeCategoryMap(IFormatChangeListener *lst)
 }
 
 void TypeCategoryMap::Add(KeyType name, const TypeCategoryImplSP &entry) {
-  std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
-  m_map[name] = entry;
+  {
+    std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
+    m_map[name] = entry;
+  }
+  // The lock is now released for the eventual call to Changed.
----------------
JDevlieghere wrote:

This comment explains _what_ you're doing, which the code already tells me, but not _why_.

I'd expect something like this, although it doesn't need to be quite so verbose:

```
// Release the mutex to avoid a potential deadlock between TypeCategoryMap::m_map_mutex and FormatManager::m_language_categories_mutex which can be acquired in reverse order when calling FormatManager::Changed.
``` 

https://github.com/llvm/llvm-project/pull/87540


More information about the lldb-commits mailing list