From 8b6d88d2f87397d19af964a9d8e8be6ceaaeb1e6 Mon Sep 17 00:00:00 2001 From: Oscar Fuentes Date: Mon, 7 Dec 2009 05:29:59 +0000 Subject: [PATCH] Fixes the Atomic implementation if compiled by MSVC compiler. sys::cas_flag should be long on this platform, InterlockedAdd() is defined only for the Itanium architecture (according to MSDN). Patch by Michael Beck! llvm-svn: 90748 --- llvm/include/llvm/System/Atomic.h | 4 ++++ llvm/lib/System/Atomic.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/System/Atomic.h b/llvm/include/llvm/System/Atomic.h index 0c05d696e392..fc19369d11bd 100644 --- a/llvm/include/llvm/System/Atomic.h +++ b/llvm/include/llvm/System/Atomic.h @@ -20,7 +20,11 @@ namespace llvm { namespace sys { void MemoryFence(); +#ifdef _MSC_VER + typedef long cas_flag; +#else typedef uint32_t cas_flag; +#endif cas_flag CompareAndSwap(volatile cas_flag* ptr, cas_flag new_value, cas_flag old_value); diff --git a/llvm/lib/System/Atomic.cpp b/llvm/lib/System/Atomic.cpp index f9b55a186d18..7ba8b774d5e0 100644 --- a/llvm/lib/System/Atomic.cpp +++ b/llvm/lib/System/Atomic.cpp @@ -85,7 +85,7 @@ sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) { #elif defined(__GNUC__) return __sync_add_and_fetch(ptr, val); #elif defined(_MSC_VER) - return InterlockedAdd(ptr, val); + return InterlockedExchangeAdd(ptr, val) + val; #else # error No atomic add implementation for your platform! #endif