aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Attributes.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-11-09 00:27:03 +0000
committerOwen Anderson <resistor@mac.com>2010-11-09 00:27:03 +0000
commit3afb024907729b09bd91ff2358c0b085f472e6ac (patch)
tree7131e321d6bd207586f4d115061715d873d652d3 /lib/VMCore/Attributes.cpp
parent4b97c55648a228305e28b4164dae9dcdebccdc8f (diff)
downloadexternal_llvm-3afb024907729b09bd91ff2358c0b085f472e6ac.tar.gz
external_llvm-3afb024907729b09bd91ff2358c0b085f472e6ac.tar.bz2
external_llvm-3afb024907729b09bd91ff2358c0b085f472e6ac.zip
Fix PR8441, a race condition in the static attributes list. While the reference counting was itself threadsafe,
the implicit removal of each object from the global list was not. Make this operation atomic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Attributes.cpp')
-rw-r--r--lib/VMCore/Attributes.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index 6f5ecd278d..d854628603 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<sys::SmartMutex<true> > 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<true> Lock(*ALMutex);
+ ++RefCount;
+ }
void DropRef() {
- sys::cas_flag old = sys::AtomicDecrement(&RefCount);
- if (old == 0) delete this;
+ sys::SmartScopedLock<true> Lock(*ALMutex);
+ sys::cas_flag old = RefCount++;
+ if (old == 0)
+ delete this;
}
void Profile(FoldingSetNodeID &ID) const {
@@ -139,11 +147,10 @@ public:
};
}
-static ManagedStatic<sys::SmartMutex<true> > ALMutex;
static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
AttributeListImpl::~AttributeListImpl() {
- sys::SmartScopedLock<true> Lock(*ALMutex);
+ // NOTE: Lock must be acquired by caller.
AttributesLists->RemoveNode(this);
}