summaryrefslogtreecommitdiff
path: root/lib/System
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-23 17:39:31 +0000
committerOwen Anderson <resistor@mac.com>2009-06-23 17:39:31 +0000
commit5a9c0eeaf23a498de19c805395cc0e2762dbf3d3 (patch)
treedef143fec6c5f9440ec541ed7058cf551be413b1 /lib/System
parent3b8d135879bd045d63174064c6879eaa6581ec00 (diff)
downloadllvm-5a9c0eeaf23a498de19c805395cc0e2762dbf3d3.tar.gz
llvm-5a9c0eeaf23a498de19c805395cc0e2762dbf3d3.tar.bz2
llvm-5a9c0eeaf23a498de19c805395cc0e2762dbf3d3.tar.xz
Add an atomic add operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73964 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/Atomic.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/System/Atomic.cpp b/lib/System/Atomic.cpp
index 416f981df8..6e751a30d4 100644
--- a/lib/System/Atomic.cpp
+++ b/lib/System/Atomic.cpp
@@ -78,4 +78,17 @@ sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
#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
+}
+