[compiler-rt] r177854 - [Sanitizer] First effort to implement atomic_compare_exchange for 1-byte vars on Windows
Alexey Samsonov
samsonov at google.com
Mon Mar 25 02:23:31 PDT 2013
Author: samsonov
Date: Mon Mar 25 04:23:30 2013
New Revision: 177854
URL: http://llvm.org/viewvc/llvm-project?rev=177854&view=rev
Log:
[Sanitizer] First effort to implement atomic_compare_exchange for 1-byte vars on Windows
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=177854&r1=177853&r2=177854&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_msvc.h Mon Mar 25 04:23:30 2013
@@ -134,6 +134,27 @@ INLINE u16 atomic_exchange(volatile atom
return v;
}
+INLINE bool atomic_compare_exchange_strong(volatile atomic_uint8_t *a,
+ u8 *cmp,
+ u8 xchg,
+ memory_order mo) {
+ (void)mo;
+ DCHECK(!((uptr)a % sizeof(*a)));
+ u8 cmpv = *cmp;
+ u8 prev;
+ __asm {
+ mov al, cmpv
+ mov ecx, a
+ mov dl, xchg
+ lock cmpxchg [ecx], dl
+ mov prev, al
+ }
+ if (prev == cmpv)
+ return true;
+ *cmp = prev;
+ return false;
+}
+
INLINE bool atomic_compare_exchange_strong(volatile atomic_uintptr_t *a,
uptr *cmp,
uptr xchg,
@@ -149,9 +170,9 @@ INLINE bool atomic_compare_exchange_stro
template<typename T>
INLINE bool atomic_compare_exchange_weak(volatile T *a,
- typename T::Type *cmp,
- typename T::Type xchg,
- memory_order mo) {
+ typename T::Type *cmp,
+ typename T::Type xchg,
+ memory_order mo) {
return atomic_compare_exchange_strong(a, cmp, xchg, mo);
}
More information about the llvm-commits
mailing list