diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index 6f5ecd278d8..d854628603b 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -106,7 +106,10 @@ Attributes Attribute::typeIncompatible(const Type *Ty) { // AttributeListImpl Definition //===----------------------------------------------------------------------===// + namespace llvm { +static ManagedStatic > ALMutex; + class AttributeListImpl : public FoldingSetNode { sys::cas_flag RefCount; @@ -122,10 +125,15 @@ public: RefCount = 0; } - void AddRef() { sys::AtomicIncrement(&RefCount); } + void AddRef() { + sys::SmartScopedLock Lock(*ALMutex); + ++RefCount; + } void DropRef() { - sys::cas_flag old = sys::AtomicDecrement(&RefCount); - if (old == 0) delete this; + sys::SmartScopedLock Lock(*ALMutex); + sys::cas_flag old = RefCount++; + if (old == 0) + delete this; } void Profile(FoldingSetNodeID &ID) const { @@ -139,11 +147,10 @@ public: }; } -static ManagedStatic > ALMutex; static ManagedStatic > AttributesLists; AttributeListImpl::~AttributeListImpl() { - sys::SmartScopedLock Lock(*ALMutex); + // NOTE: Lock must be acquired by caller. AttributesLists->RemoveNode(this); }