[compiler-rt] r256128 - [PGO] Implement BOOL_CMPXCHG for Windows

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 20 11:11:44 PST 2015


Author: davidxl
Date: Sun Dec 20 13:11:44 2015
New Revision: 256128

URL: http://llvm.org/viewvc/llvm-project?rev=256128&view=rev
Log:
[PGO] Implement BOOL_CMPXCHG for Windows

Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingPort.h

Modified: compiler-rt/trunk/lib/profile/InstrProfilingPort.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingPort.h?rev=256128&r1=256127&r2=256128&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingPort.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingPort.h Sun Dec 20 13:11:44 2015
@@ -23,8 +23,21 @@
 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
 
 #if COMPILER_RT_HAS_ATOMICS == 1
+#ifdef _MSC_VER
+#include <windows.h>
+#if defined(_WIN32)
+#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
+  (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
+   (LONG)OldV)
+#else
+#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
+  (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV,      \
+                                (LONGLONG)OldV) == (LONGLONG)OldV)
+#endif
+#else
 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
   __sync_bool_compare_and_swap(Ptr, OldV, NewV)
+#endif
 #else
 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
   BoolCmpXchg((void **)Ptr, OldV, NewV)




More information about the llvm-commits mailing list