Add atomic multiply and divide operations, built on top of CompareAndSwap.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74004 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-06-23 21:19:04 +00:00
parent 343beeb386
commit e0fa0b42b2
2 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,8 @@ namespace llvm {
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);
}
}

View File

@ -91,4 +91,22 @@ sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
#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;
}