[llvm-commits] [compiler-rt] r162996 - /compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h

Dmitry Vyukov dvyukov at google.com
Fri Aug 31 07:01:33 PDT 2012


Author: dvyukov
Date: Fri Aug 31 09:01:33 2012
New Revision: 162996

URL: http://llvm.org/viewvc/llvm-project?rev=162996&view=rev
Log:
tsan: fix windows build (1)

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h?rev=162996&r1=162995&r2=162996&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h Fri Aug 31 09:01:33 2012
@@ -24,6 +24,10 @@
 extern "C" long _InterlockedExchangeAdd(  // NOLINT
     long volatile * Addend, long Value);  // NOLINT
 #pragma intrinsic(_InterlockedExchangeAdd)
+extern "C" void *_InterlockedCompareExchangePointer(
+    void *volatile *Destination,
+    void *Exchange, void *Comparand);
+#pragma intrinsic(_InterlockedCompareExchangePointer)
 
 namespace __sanitizer {
 
@@ -107,6 +111,27 @@
   return v;
 }
 
+INLINE bool atomic_compare_exchange_strong(volatile uptr *a,
+                                           uptr *cmp,
+                                           uptr xchg,
+                                           memory_order mo) {
+  uptr cmpv = *cmp;
+  uptr prev = (uptr)_InterlockedCompareExchangePointer(
+      (void*volatile*)&a->val_dont_use, (void*)xchg, (void*)cmpv);
+  if (prev == cmpv)
+    return true;
+  *cmp = prev;
+  return false;
+}
+
+template<typename T>
+INLINE bool atomic_compare_exchange_weak(volatile T *a,
+                                           typename T::Type *cmp,
+                                           typename T::Type xchg,
+                                           memory_order mo) {
+  return atomic_compare_exchange_strong(a, cmp, xchg, mo);
+}
+
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_ATOMIC_CLANG_H





More information about the llvm-commits mailing list