[llvm-commits] [llvm] r73964 - in /llvm/trunk: include/llvm/System/Atomic.h lib/System/Atomic.cpp

Owen Anderson resistor at mac.com
Tue Jun 23 10:39:34 PDT 2009


Author: resistor
Date: Tue Jun 23 12:39:31 2009
New Revision: 73964

URL: http://llvm.org/viewvc/llvm-project?rev=73964&view=rev
Log:
Add an atomic add operation.

Modified:
    llvm/trunk/include/llvm/System/Atomic.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=73964&r1=73963&r2=73964&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/Atomic.h (original)
+++ llvm/trunk/include/llvm/System/Atomic.h Tue Jun 23 12:39:31 2009
@@ -26,6 +26,7 @@
                             cas_flag old_value);
     cas_flag AtomicIncrement(volatile cas_flag* ptr);
     cas_flag AtomicDecrement(volatile cas_flag* ptr);
+    cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
   }
 }
 

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

==============================================================================
--- llvm/trunk/lib/System/Atomic.cpp (original)
+++ llvm/trunk/lib/System/Atomic.cpp Tue Jun 23 12:39:31 2009
@@ -78,4 +78,17 @@
 #endif
 }
 
+sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
+#if LLVM_MULTITHREADED==0
+  *ptr += val;
+  return *ptr;
+#elif defined(__GNUC__)
+  return __sync_add_and_fetch(ptr, val);
+#elif defined(_MSC_VER)
+  return InterlockedAdd(ptr, val);
+#else
+#  error No atomic add implementation for your platform!
+#endif
+}
+
 





More information about the llvm-commits mailing list