[llvm-commits] [llvm] r73588 - in /llvm/trunk: include/llvm/System/Atomic.h include/llvm/Type.h lib/System/Atomic.cpp
Owen Anderson
resistor at mac.com
Tue Jun 16 17:28:56 PDT 2009
Author: resistor
Date: Tue Jun 16 19:28:49 2009
New Revision: 73588
URL: http://llvm.org/viewvc/llvm-project?rev=73588&view=rev
Log:
Use atomic increment/decrement for reference counting of Type's.
Modified:
llvm/trunk/include/llvm/System/Atomic.h
llvm/trunk/include/llvm/Type.h
llvm/trunk/lib/System/Atomic.cpp
Modified: llvm/trunk/include/llvm/System/Atomic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Atomic.h?rev=73588&r1=73587&r2=73588&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/Atomic.h (original)
+++ llvm/trunk/include/llvm/System/Atomic.h Tue Jun 16 19:28:49 2009
@@ -24,8 +24,8 @@
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);
}
}
Modified: llvm/trunk/include/llvm/Type.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Type.h?rev=73588&r1=73587&r2=73588&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Type.h (original)
+++ llvm/trunk/include/llvm/Type.h Tue Jun 16 19:28:49 2009
@@ -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 @@
/// 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 @@
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 @@
// 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();
}
Modified: llvm/trunk/lib/System/Atomic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Atomic.cpp?rev=73588&r1=73587&r2=73588&view=diff
==============================================================================
--- llvm/trunk/lib/System/Atomic.cpp (original)
+++ llvm/trunk/lib/System/Atomic.cpp Tue Jun 16 19:28:49 2009
@@ -52,7 +52,7 @@
#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 @@
#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;
More information about the llvm-commits
mailing list