mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
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
This commit is contained in:
parent
4b97c55648
commit
3afb024907
@ -106,7 +106,10 @@ Attributes Attribute::typeIncompatible(const Type *Ty) {
|
|||||||
// AttributeListImpl Definition
|
// AttributeListImpl Definition
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
static ManagedStatic<sys::SmartMutex<true> > ALMutex;
|
||||||
|
|
||||||
class AttributeListImpl : public FoldingSetNode {
|
class AttributeListImpl : public FoldingSetNode {
|
||||||
sys::cas_flag RefCount;
|
sys::cas_flag RefCount;
|
||||||
|
|
||||||
@ -122,10 +125,15 @@ public:
|
|||||||
RefCount = 0;
|
RefCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddRef() { sys::AtomicIncrement(&RefCount); }
|
void AddRef() {
|
||||||
|
sys::SmartScopedLock<true> Lock(*ALMutex);
|
||||||
|
++RefCount;
|
||||||
|
}
|
||||||
void DropRef() {
|
void DropRef() {
|
||||||
sys::cas_flag old = sys::AtomicDecrement(&RefCount);
|
sys::SmartScopedLock<true> Lock(*ALMutex);
|
||||||
if (old == 0) delete this;
|
sys::cas_flag old = RefCount++;
|
||||||
|
if (old == 0)
|
||||||
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Profile(FoldingSetNodeID &ID) const {
|
void Profile(FoldingSetNodeID &ID) const {
|
||||||
@ -139,11 +147,10 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ManagedStatic<sys::SmartMutex<true> > ALMutex;
|
|
||||||
static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
|
static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
|
||||||
|
|
||||||
AttributeListImpl::~AttributeListImpl() {
|
AttributeListImpl::~AttributeListImpl() {
|
||||||
sys::SmartScopedLock<true> Lock(*ALMutex);
|
// NOTE: Lock must be acquired by caller.
|
||||||
AttributesLists->RemoveNode(this);
|
AttributesLists->RemoveNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user