| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file is an internal atomic implementation, use base/atomicops.h instead. | 5 // This file is an internal atomic implementation, use base/atomicops.h instead. |
| 6 | 6 |
| 7 #ifndef BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 7 #ifndef BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| 8 #define BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 8 #define BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| 9 | 9 |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 | 11 |
| 12 #if defined(ARCH_CPU_64_BITS) |
| 13 // windows.h #defines this (only on x64). This causes problems because the |
| 14 // public API also uses MemoryBarrier at the public name for this fence. So, on |
| 15 // X64, undef it, and call its documented |
| 16 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx) |
| 17 // implementation directly. |
| 18 #undef MemoryBarrier |
| 19 #endif |
| 20 |
| 12 namespace base { | 21 namespace base { |
| 13 namespace subtle { | 22 namespace subtle { |
| 14 | 23 |
| 15 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 24 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
| 16 Atomic32 old_value, | 25 Atomic32 old_value, |
| 17 Atomic32 new_value) { | 26 Atomic32 new_value) { |
| 18 LONG result = InterlockedCompareExchange( | 27 LONG result = InterlockedCompareExchange( |
| 19 reinterpret_cast<volatile LONG*>(ptr), | 28 reinterpret_cast<volatile LONG*>(ptr), |
| 20 static_cast<LONG>(new_value), | 29 static_cast<LONG>(new_value), |
| 21 static_cast<LONG>(old_value)); | 30 static_cast<LONG>(old_value)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 | 48 |
| 40 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | 49 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
| 41 Atomic32 increment) { | 50 Atomic32 increment) { |
| 42 return Barrier_AtomicIncrement(ptr, increment); | 51 return Barrier_AtomicIncrement(ptr, increment); |
| 43 } | 52 } |
| 44 | 53 |
| 45 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) | 54 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) |
| 46 #error "We require at least vs2005 for MemoryBarrier" | 55 #error "We require at least vs2005 for MemoryBarrier" |
| 47 #endif | 56 #endif |
| 48 inline void MemoryBarrier() { | 57 inline void MemoryBarrier() { |
| 58 #if defined(ARCH_CPU_64_BITS) |
| 59 // See #undef and note at the top of this file. |
| 60 __faststorefence(); |
| 61 #else |
| 49 // We use MemoryBarrier from WinNT.h | 62 // We use MemoryBarrier from WinNT.h |
| 50 ::MemoryBarrier(); | 63 ::MemoryBarrier(); |
| 64 #endif |
| 51 } | 65 } |
| 52 | 66 |
| 53 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, | 67 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, |
| 54 Atomic32 old_value, | 68 Atomic32 old_value, |
| 55 Atomic32 new_value) { | 69 Atomic32 new_value) { |
| 56 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); | 70 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 57 } | 71 } |
| 58 | 72 |
| 59 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, | 73 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, |
| 60 Atomic32 old_value, | 74 Atomic32 old_value, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); | 185 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 172 } | 186 } |
| 173 | 187 |
| 174 | 188 |
| 175 #endif // defined(_WIN64) | 189 #endif // defined(_WIN64) |
| 176 | 190 |
| 177 } // namespace base::subtle | 191 } // namespace base::subtle |
| 178 } // namespace base | 192 } // namespace base |
| 179 | 193 |
| 180 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 194 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| OLD | NEW |