aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/System/Atomic.h1
-rw-r--r--lib/System/Atomic.cpp13
2 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/System/Atomic.h b/include/llvm/System/Atomic.h
index adbb975298..c4049d40da 100644
--- a/include/llvm/System/Atomic.h
+++ b/include/llvm/System/Atomic.h
@@ -26,6 +26,7 @@ namespace llvm {
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);
}
}
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
+}
+