diff options
author | Owen Anderson <resistor@mac.com> | 2009-06-23 17:39:31 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-06-23 17:39:31 +0000 |
commit | 5a9c0eeaf23a498de19c805395cc0e2762dbf3d3 (patch) | |
tree | def143fec6c5f9440ec541ed7058cf551be413b1 | |
parent | 3b8d135879bd045d63174064c6879eaa6581ec00 (diff) | |
download | external_llvm-5a9c0eeaf23a498de19c805395cc0e2762dbf3d3.tar.gz external_llvm-5a9c0eeaf23a498de19c805395cc0e2762dbf3d3.tar.bz2 external_llvm-5a9c0eeaf23a498de19c805395cc0e2762dbf3d3.zip |
Add an atomic add operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73964 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/System/Atomic.h | 1 | ||||
-rw-r--r-- | lib/System/Atomic.cpp | 13 |
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 +} + |