Add an atomic increment and decrement implementation, which will be used for
authorOwen Anderson <resistor@mac.com>
Wed, 17 Jun 2009 00:13:00 +0000 (00:13 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 17 Jun 2009 00:13:00 +0000 (00:13 +0000)
thread-safe reference counting.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73587 91177308-0d34-0410-b5e6-96231b3b80d8

autoconf/configure.ac
configure
include/llvm/System/Atomic.h
include/llvm/Type.h
lib/System/Atomic.cpp

index 828e5585f6c1465bbfddc4eb3aaf86b07a21c1a8..4ba6b2b481e44695997854b06dc7395ed2300bb8 100644 (file)
@@ -935,6 +935,8 @@ AC_LINK_IFELSE(
         volatile unsigned long val = 1;
         __sync_synchronize();
         __sync_val_compare_and_swap(&val, 1, 0);
+        __sync_add_and_fetch(&val, 1);
+        __sync_sub_and_fetch(&val, 1);
         return 0;
       }
     ]]),
index 7fdb067bf2fafb1ec521989e8e5ed8db8e5078ee..6920d6d90f6e1e63e1329b783171cf3cfc4b470a 100755 (executable)
--- a/configure
+++ b/configure
@@ -33760,6 +33760,8 @@ int main() {
         volatile unsigned long val = 1;
         __sync_synchronize();
         __sync_val_compare_and_swap(&val, 1, 0);
+        __sync_add_and_fetch(&val, 1);
+        __sync_sub_and_fetch(&val, 1);
         return 0;
       }
 
index cb9277cc35ec80fa0d5352100fba9d604dc0155d..f90a8f62e1c76dd8ce07b1002f1b16e3df9ec251 100644 (file)
@@ -24,6 +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);
   }
 }
 
index 9a48731ede9b8254b31e94ec3f3bdc97df4f6072..256944f600498327567799eb58e7d703ae59e6f4 100644 (file)
@@ -353,10 +353,7 @@ public:
   /// addAbstractTypeUser - Notify an abstract type that there is a new user of
   /// it.  This function is called primarily by the PATypeHandle class.
   ///
-  void addAbstractTypeUser(AbstractTypeUser *U) const {
-    assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!");
-    AbstractTypeUsers.push_back(U);
-  }
+  void addAbstractTypeUser(AbstractTypeUser *U) const;
   
   /// removeAbstractTypeUser - Notify an abstract type that a user of the class
   /// no longer has a handle to the type.  This function is called primarily by
index 2827d8896594544b09ec4176bfd4f3846087aff4..9d8ac925b8900fd5e015d5416fd56eb8867f72a4 100644 (file)
@@ -51,3 +51,31 @@ sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
 #  error No compare-and-swap implementation for your platform!
 #endif
 }
+
+sys::cas_flag sys::AtomicPostIncrement(volatile sys::cas_flag* ptr) {
+#if LLVM_MULTITHREADED==0
+  ++(*ptr);
+  return *ptr;
+#elif defined(__GNUC__)
+  return __sync_add_and_fetch(ptr, 1);
+#elif defined(_MSC_VER)
+  return InterlockedCompareExchange(ptr, new_value, old_value);
+#else
+#  error No atomic increment implementation for your platform!
+#endif
+}
+
+sys::cas_flag sys::AtomicPostDecrement(volatile sys::cas_flag* ptr) {
+#if LLVM_MULTITHREADED==0
+  --(*ptr);
+  return *ptr;
+#elif defined(__GNUC__)
+  return __sync_sub_and_fetch(ptr, 1);
+#elif defined(_MSC_VER)
+  return InterlockedIncrement(ptr);
+#else
+#  error No atomic decrement implementation for your platform!
+#endif
+}
+
+