diff options
author | Owen Anderson <resistor@mac.com> | 2009-06-17 00:28:49 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-06-17 00:28:49 +0000 |
commit | 82b58a843b9e7d61f8fcb91ddac41929a7f65b65 (patch) | |
tree | bba86311c2b45b1146ffbb899ffec57c9e433561 /llvm | |
parent | 8d0fe6f0d72174bce80ec995352766d26fee6736 (diff) | |
download | bcm5719-llvm-82b58a843b9e7d61f8fcb91ddac41929a7f65b65.tar.gz bcm5719-llvm-82b58a843b9e7d61f8fcb91ddac41929a7f65b65.zip |
Use atomic increment/decrement for reference counting of Type's.
llvm-svn: 73588
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/System/Atomic.h | 4 | ||||
-rw-r--r-- | llvm/include/llvm/Type.h | 8 | ||||
-rw-r--r-- | llvm/lib/System/Atomic.cpp | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/llvm/include/llvm/System/Atomic.h b/llvm/include/llvm/System/Atomic.h index f90a8f62e1c..adbb975298e 100644 --- a/llvm/include/llvm/System/Atomic.h +++ b/llvm/include/llvm/System/Atomic.h @@ -24,8 +24,8 @@ namespace llvm { cas_flag CompareAndSwap(volatile cas_flag* ptr, cas_flag new_value, cas_flag old_value); - cas_flag AtomicPostIncrement(volatile cas_flag* ptr); - cas_flag AtomicPostDecrement(volatile cas_flag* ptr); + cas_flag AtomicIncrement(volatile cas_flag* ptr); + cas_flag AtomicDecrement(volatile cas_flag* ptr); } } diff --git a/llvm/include/llvm/Type.h b/llvm/include/llvm/Type.h index 256944f6004..d439233d8c0 100644 --- a/llvm/include/llvm/Type.h +++ b/llvm/include/llvm/Type.h @@ -14,6 +14,7 @@ #include "llvm/AbstractTypeUser.h" #include "llvm/Support/Casting.h" #include "llvm/Support/DataTypes.h" +#include "llvm/System/Atomic.h" #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/iterator.h" #include <string> @@ -102,7 +103,7 @@ private: /// has no AbstractTypeUsers, the type is deleted. This is only sensical for /// derived types. /// - mutable unsigned RefCount; + mutable sys::cas_flag RefCount; const Type *getForwardedTypeInternal() const; @@ -337,7 +338,7 @@ public: void addRef() const { assert(isAbstract() && "Cannot add a reference to a non-abstract type!"); - ++RefCount; + sys::AtomicIncrement(&RefCount); } void dropRef() const { @@ -346,7 +347,8 @@ public: // If this is the last PATypeHolder using this object, and there are no // PATypeHandles using it, the type is dead, delete it now. - if (--RefCount == 0 && AbstractTypeUsers.empty()) + sys::cas_flag OldCount = sys::AtomicDecrement(&RefCount); + if (OldCount == 0 && AbstractTypeUsers.empty()) this->destroy(); } diff --git a/llvm/lib/System/Atomic.cpp b/llvm/lib/System/Atomic.cpp index 9d8ac925b89..5676ca9d62c 100644 --- a/llvm/lib/System/Atomic.cpp +++ b/llvm/lib/System/Atomic.cpp @@ -52,7 +52,7 @@ sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr, #endif } -sys::cas_flag sys::AtomicPostIncrement(volatile sys::cas_flag* ptr) { +sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) { #if LLVM_MULTITHREADED==0 ++(*ptr); return *ptr; @@ -65,7 +65,7 @@ sys::cas_flag sys::AtomicPostIncrement(volatile sys::cas_flag* ptr) { #endif } -sys::cas_flag sys::AtomicPostDecrement(volatile sys::cas_flag* ptr) { +sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) { #if LLVM_MULTITHREADED==0 --(*ptr); return *ptr; |