[Lldb-commits] [lldb] r260909 - Refinement of r260624. It is possible somebody might try to add to the map

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 15 12:04:16 PST 2016


Author: jingham
Date: Mon Feb 15 14:04:15 2016
New Revision: 260909

URL: http://llvm.org/viewvc/llvm-project?rev=260909&view=rev
Log:
Refinement of r260624.  It is possible somebody might try to add to the map
while we are finalizing its elements.  Prevent that.

<rdar://problem/24554920>

Modified:
    lldb/trunk/include/lldb/Symbol/TypeSystem.h
    lldb/trunk/source/Symbol/TypeSystem.cpp

Modified: lldb/trunk/include/lldb/Symbol/TypeSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeSystem.h?rev=260909&r1=260908&r2=260909&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeSystem.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeSystem.h Mon Feb 15 14:04:15 2016
@@ -607,9 +607,13 @@ protected:
         GetTypeSystemForLanguage (lldb::LanguageType language, Target *target, bool can_create);
 
     protected:
+        void
+        AddToMap (lldb::LanguageType language, lldb::TypeSystemSP const &type_system_sp);
+
         typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> collection;
         mutable Mutex m_mutex; ///< A mutex to keep this object happy in multi-threaded environments.
         collection m_map;
+        bool m_clear_in_progress;
     };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Symbol/TypeSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeSystem.cpp?rev=260909&r1=260908&r2=260909&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeSystem.cpp (original)
+++ lldb/trunk/source/Symbol/TypeSystem.cpp Mon Feb 15 14:04:15 2016
@@ -165,7 +165,8 @@ TypeSystem::DeclContextFindDeclByName (v
 
 TypeSystemMap::TypeSystemMap() :
     m_mutex (),
-    m_map ()
+    m_map (),
+    m_clear_in_progress(false)
 {
 }
 
@@ -180,6 +181,7 @@ TypeSystemMap::Clear ()
     {
         Mutex::Locker locker (m_mutex);
         map = m_map;
+        m_clear_in_progress = true;
     }
     std::set<TypeSystem *> visited;
     for (auto pair : map)
@@ -195,6 +197,7 @@ TypeSystemMap::Clear ()
     {
         Mutex::Locker locker (m_mutex);
         m_map.clear();
+        m_clear_in_progress = false;
     }
 }
 
@@ -232,7 +235,7 @@ TypeSystemMap::GetTypeSystemForLanguage
         {
             // Add a new mapping for "language" to point to an already existing
             // TypeSystem that supports this language
-            m_map[language] = pair.second;
+            AddToMap(language, pair.second);
             return pair.second.get();
         }
     }
@@ -242,7 +245,7 @@ TypeSystemMap::GetTypeSystemForLanguage
 
     // Cache even if we get a shared pointer that contains null type system back
     lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, module);
-    m_map[language] = type_system_sp;
+    AddToMap (language, type_system_sp);
     return type_system_sp.get();
 }
 
@@ -260,7 +263,8 @@ TypeSystemMap::GetTypeSystemForLanguage
         {
             // Add a new mapping for "language" to point to an already existing
             // TypeSystem that supports this language
-            m_map[language] = pair.second;
+
+            AddToMap(language, pair.second);
             return pair.second.get();
         }
     }
@@ -269,7 +273,17 @@ TypeSystemMap::GetTypeSystemForLanguage
         return nullptr;
 
     // Cache even if we get a shared pointer that contains null type system back
-    lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, target);
-    m_map[language] = type_system_sp;
+    lldb::TypeSystemSP type_system_sp;
+    if (!m_clear_in_progress)
+        type_system_sp = TypeSystem::CreateInstance (language, target);
+
+    AddToMap(language, type_system_sp);
     return type_system_sp.get();
 }
+
+void
+TypeSystemMap::AddToMap (lldb::LanguageType language, lldb::TypeSystemSP const &type_system_sp)
+{
+    if (!m_clear_in_progress)
+        m_map[language] = type_system_sp;
+}




More information about the lldb-commits mailing list