Browse code

Cherry-pick LLVM upstream commit r90748.

commit 4aafc85f5a94802c121050ec113973249e295577
Author: Oscar Fuentes <ofv@wanadoo.es>
Date: Mon Dec 7 05:29:59 2009 +0000

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!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90748 91177308-0d34-0410-b5e6-96231b3b80d8

Török Edvin authored on 2009/12/12 05:57:23
Showing 2 changed files
... ...
@@ -20,7 +20,11 @@ namespace llvm {
20 20
   namespace sys {
21 21
     void MemoryFence();
22 22
 
23
+#ifdef _MSC_VER
24
+    typedef long cas_flag;
25
+#else
23 26
     typedef uint32_t cas_flag;
27
+#endif
24 28
     cas_flag CompareAndSwap(volatile cas_flag* ptr,
25 29
                             cas_flag new_value,
26 30
                             cas_flag old_value);
... ...
@@ -85,7 +85,7 @@ sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
85 85
 #elif defined(__GNUC__)
86 86
   return __sync_add_and_fetch(ptr, val);
87 87
 #elif defined(_MSC_VER)
88
-  return InterlockedAdd(ptr, val);
88
+  return InterlockedExchangeAdd(ptr, val) + val;
89 89
 #else
90 90
 #  error No atomic add implementation for your platform!
91 91
 #endif