summaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-08-20 19:03:20 +0000
committerOwen Anderson <resistor@mac.com>2009-08-20 19:03:20 +0000
commit72689b4094570666f3aa8e003186998805a06b45 (patch)
tree0dce83e220b56dc7c824f879ffa306adbd75eb33 /lib/VMCore
parentd9b207122eeb740a3878f8389cb38b81d9388734 (diff)
downloadllvm-72689b4094570666f3aa8e003186998805a06b45.tar.gz
llvm-72689b4094570666f3aa8e003186998805a06b45.tar.bz2
llvm-72689b4094570666f3aa8e003186998805a06b45.tar.xz
Reduce contention on the Attributes lock by using atomic operations for reference counting rather than locking.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79560 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Attributes.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index 73c92ec6c0..fb1a9b8cd5 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -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 @@ Attributes Attribute::typeIncompatible(const Type *Ty) {
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 @@ public:
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::get(const AttributeWithIndex *Attrs, unsigned NumAttrs)
//===----------------------------------------------------------------------===//
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 @@ const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) {
}
AttrListPtr::~AttrListPtr() {
- sys::SmartScopedLock<true> Lock(*ALMutex);
if (AttrList) AttrList->DropRef();
}