[llvm-commits] [llvm] r73587 - in /llvm/trunk: autoconf/configure.ac configure include/llvm/System/Atomic.h include/llvm/Type.h lib/System/Atomic.cpp

Owen Anderson resistor at mac.com
Tue Jun 16 17:13:00 PDT 2009


Author: resistor
Date: Tue Jun 16 19:13:00 2009
New Revision: 73587

URL: http://llvm.org/viewvc/llvm-project?rev=73587&view=rev
Log:
Add an atomic increment and decrement implementation, which will be used for
thread-safe reference counting.

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

Modified: llvm/trunk/autoconf/configure.ac
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/autoconf/configure.ac?rev=73587&r1=73586&r2=73587&view=diff

==============================================================================
--- llvm/trunk/autoconf/configure.ac (original)
+++ llvm/trunk/autoconf/configure.ac Tue Jun 16 19:13:00 2009
@@ -935,6 +935,8 @@
         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;
       }
     ]]),

Modified: llvm/trunk/configure
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/configure?rev=73587&r1=73586&r2=73587&view=diff

==============================================================================
--- llvm/trunk/configure (original)
+++ llvm/trunk/configure Tue Jun 16 19:13:00 2009
@@ -33760,6 +33760,8 @@
         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;
       }
 

Modified: llvm/trunk/include/llvm/System/Atomic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Atomic.h?rev=73587&r1=73586&r2=73587&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/Atomic.h (original)
+++ llvm/trunk/include/llvm/System/Atomic.h Tue Jun 16 19:13:00 2009
@@ -24,6 +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);
   }
 }
 

Modified: llvm/trunk/include/llvm/Type.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Type.h?rev=73587&r1=73586&r2=73587&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Type.h (original)
+++ llvm/trunk/include/llvm/Type.h Tue Jun 16 19:13:00 2009
@@ -353,10 +353,7 @@
   /// 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

Modified: llvm/trunk/lib/System/Atomic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Atomic.cpp?rev=73587&r1=73586&r2=73587&view=diff

==============================================================================
--- llvm/trunk/lib/System/Atomic.cpp (original)
+++ llvm/trunk/lib/System/Atomic.cpp Tue Jun 16 19:13:00 2009
@@ -51,3 +51,31 @@
 #  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
+}
+
+





More information about the llvm-commits mailing list