[llvm-commits] [llvm] r74004 - in /llvm/trunk: include/llvm/System/Atomic.h lib/System/Atomic.cpp
Owen Anderson
resistor at mac.com
Tue Jun 23 14:19:04 PDT 2009
Author: resistor
Date: Tue Jun 23 16:19:04 2009
New Revision: 74004
URL: http://llvm.org/viewvc/llvm-project?rev=74004&view=rev
Log:
Add atomic multiply and divide operations, built on top of CompareAndSwap.
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=74004&r1=74003&r2=74004&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/Atomic.h (original)
+++ llvm/trunk/include/llvm/System/Atomic.h Tue Jun 23 16:19:04 2009
@@ -27,6 +27,8 @@
cas_flag AtomicIncrement(volatile cas_flag* ptr);
cas_flag AtomicDecrement(volatile cas_flag* ptr);
cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
+ cas_flag AtomicMul(volatile cas_flag* ptr, cas_flag val);
+ cas_flag AtomicDiv(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=74004&r1=74003&r2=74004&view=diff
==============================================================================
--- llvm/trunk/lib/System/Atomic.cpp (original)
+++ llvm/trunk/lib/System/Atomic.cpp Tue Jun 23 16:19:04 2009
@@ -91,4 +91,22 @@
#endif
}
+sys::cas_flag sys::AtomicMul(volatile sys::cas_flag* ptr, sys::cas_flag val) {
+ sys::cas_flag original, result;
+ do {
+ original = *ptr;
+ result = original * val;
+ } while (sys::CompareAndSwap(ptr, result, original) != original);
+ return result;
+}
+
+sys::cas_flag sys::AtomicDiv(volatile sys::cas_flag* ptr, sys::cas_flag val) {
+ sys::cas_flag original, result;
+ do {
+ original = *ptr;
+ result = original / val;
+ } while (sys::CompareAndSwap(ptr, result, original) != original);
+
+ return result;
+}
More information about the llvm-commits
mailing list