summaryrefslogtreecommitdiffstats
path: root/include/llvm/System
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-05-19 01:02:27 +0000
committerOwen Anderson <resistor@mac.com>2009-05-19 01:02:27 +0000
commit03462230c763b4c23c9b78416620d90d02fc6786 (patch)
tree6f076876af89bb767a2e8cc5614552ae68ca7499 /include/llvm/System
parentf4786cc07ae6bc463f9d3975be7d42cc8696512c (diff)
downloadexternal_llvm-03462230c763b4c23c9b78416620d90d02fc6786.zip
external_llvm-03462230c763b4c23c9b78416620d90d02fc6786.tar.gz
external_llvm-03462230c763b4c23c9b78416620d90d02fc6786.tar.bz2
Template CompareAndSwap function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72086 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/System')
-rw-r--r--include/llvm/System/Atomic.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/include/llvm/System/Atomic.h b/include/llvm/System/Atomic.h
index 8bae46e..5162f5d 100644
--- a/include/llvm/System/Atomic.h
+++ b/include/llvm/System/Atomic.h
@@ -44,24 +44,27 @@ namespace llvm {
#if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0
typedef unsigned long cas_flag;
- inline cas_flag CompareAndSwap(cas_flag* dest, cas_flag exc, cas_flag c) {
- cas_flag result = *dest;
+ template<typename T>
+ inline T CompareAndSwap(volatile T* dest,
+ T exc, T c) {
+ T result = *dest;
if (result == c)
*dest = exc;
return result;
}
#elif defined(__GNUC__)
typedef unsigned long cas_flag;
- inline cas_flag CompareAndSwap(cas_flag* ptr,
- cas_flag new_value,
- cas_flag old_value) {
+ template<typename T>
+ inline T CompareAndSwap(volatile T* ptr,
+ T new_value,
+ T old_value) {
return __sync_val_compare_and_swap(ptr, old_value, new_value);
}
-#elif defined(_MSC_VER) && _M_IX86 > 400
+#elif defined(_MSC_VER)
typedef LONG cas_flag;
- inline cas_flag CompareAndSwap(cas_flag* ptr,
- cas_flag new_value,
- cas_flag old_value) {
+ inline T CompareAndSwap(volatile T* ptr,
+ T new_value,
+ T old_value) {
return InterlockedCompareExchange(addr, new_value, old_value);
}
#else