Add locking around the attributes list.
authorOwen Anderson <resistor@mac.com>
Mon, 17 Aug 2009 17:10:58 +0000 (17:10 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 17 Aug 2009 17:10:58 +0000 (17:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79255 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Attributes.cpp

index 5d763c34fe587a9c10f4589306d4ada377fd0988..91c7320a708b5b3e880bc2183fe644b2a5c8d538 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/Type.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/Type.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/System/Mutex.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/ManagedStatic.h"
 using namespace llvm;
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/ManagedStatic.h"
 using namespace llvm;
@@ -124,9 +125,11 @@ public:
 };
 }
 
 };
 }
 
+static ManagedStatic<sys::SmartMutex<true> > ALMutex;
 static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
 
 AttributeListImpl::~AttributeListImpl() {
 static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
 
 AttributeListImpl::~AttributeListImpl() {
+  sys::SmartScopedLock<true> Lock(*ALMutex);
   AttributesLists->RemoveNode(this);
 }
 
   AttributesLists->RemoveNode(this);
 }
 
@@ -149,6 +152,9 @@ AttrListPtr AttrListPtr::get(const AttributeWithIndex *Attrs, unsigned NumAttrs)
   FoldingSetNodeID ID;
   AttributeListImpl::Profile(ID, Attrs, NumAttrs);
   void *InsertPos;
   FoldingSetNodeID ID;
   AttributeListImpl::Profile(ID, Attrs, NumAttrs);
   void *InsertPos;
+  
+  sys::SmartScopedLock<true> Lock(*ALMutex);
+  
   AttributeListImpl *PAL =
     AttributesLists->FindNodeOrInsertPos(ID, InsertPos);
   
   AttributeListImpl *PAL =
     AttributesLists->FindNodeOrInsertPos(ID, InsertPos);