[llvm-commits] [llvm] r79560 - /llvm/trunk/lib/VMCore/Attributes.cpp
Owen Anderson
resistor at mac.com
Thu Aug 20 12:03:20 PDT 2009
Author: resistor
Date: Thu Aug 20 14:03:20 2009
New Revision: 79560
URL: http://llvm.org/viewvc/llvm-project?rev=79560&view=rev
Log:
Reduce contention on the Attributes lock by using atomic operations for reference counting rather than locking.
Modified:
llvm/trunk/lib/VMCore/Attributes.cpp
Modified: llvm/trunk/lib/VMCore/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Attributes.cpp?rev=79560&r1=79559&r2=79560&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Attributes.cpp (original)
+++ llvm/trunk/lib/VMCore/Attributes.cpp Thu Aug 20 14:03:20 2009
@@ -15,6 +15,7 @@
#include "llvm/Type.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/FoldingSet.h"
+#include "llvm/System/Atomic.h"
#include "llvm/System/Mutex.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/ManagedStatic.h"
@@ -97,7 +98,7 @@
namespace llvm {
class AttributeListImpl : public FoldingSetNode {
- unsigned RefCount;
+ sys::cas_flag RefCount;
// AttributesList is uniqued, these should not be publicly available.
void operator=(const AttributeListImpl &); // Do not implement
@@ -111,8 +112,11 @@
RefCount = 0;
}
- void AddRef() { ++RefCount; }
- void DropRef() { if (--RefCount == 0) delete this; }
+ void AddRef() { sys::AtomicIncrement(&RefCount); }
+ void DropRef() {
+ sys::cas_flag old = sys::AtomicDecrement(&RefCount);
+ if (old == 0) delete this;
+ }
void Profile(FoldingSetNodeID &ID) const {
Profile(ID, Attrs.data(), Attrs.size());
@@ -175,17 +179,14 @@
//===----------------------------------------------------------------------===//
AttrListPtr::AttrListPtr(AttributeListImpl *LI) : AttrList(LI) {
- sys::SmartScopedLock<true> Lock(*ALMutex);
if (LI) LI->AddRef();
}
AttrListPtr::AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) {
- sys::SmartScopedLock<true> Lock(*ALMutex);
if (AttrList) AttrList->AddRef();
}
const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) {
- sys::SmartScopedLock<true> Lock(*ALMutex);
if (AttrList == RHS.AttrList) return *this;
if (AttrList) AttrList->DropRef();
AttrList = RHS.AttrList;
@@ -194,7 +195,6 @@
}
AttrListPtr::~AttrListPtr() {
- sys::SmartScopedLock<true> Lock(*ALMutex);
if (AttrList) AttrList->DropRef();
}
More information about the llvm-commits
mailing list