Chromium Code Reviews| 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 #include <intrin.h> | |
| 13 | |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 | 15 |
| 14 #if defined(ARCH_CPU_64_BITS) | 16 #if defined(ARCH_CPU_64_BITS) |
| 15 // windows.h #defines this (only on x64). This causes problems because the | 17 // windows.h #defines this (only on x64). This causes problems because the |
| 16 // public API also uses MemoryBarrier at the public name for this fence. So, on | 18 // public API also uses MemoryBarrier at the public name for this fence. So, on |
| 17 // X64, undef it, and call its documented | 19 // X64, undef it, and call its documented |
| 18 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx) | 20 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx) |
| 19 // implementation directly. | 21 // implementation directly. |
| 20 #undef MemoryBarrier | 22 #undef MemoryBarrier |
| 21 #endif | 23 #endif |
| 22 | 24 |
| 25 #pragma intrinsic(_InterlockedCompareExchange) | |
|
Sigurður Ásgeirsson
2014/06/02 19:43:08
I'm concerned that you're setting this for all cli
Sébastien Marchand
2014/06/03 14:39:48
winbase.h seems to only define these functions to
| |
| 26 #pragma intrinsic(_InterlockedExchange) | |
| 27 #pragma intrinsic(_InterlockedExchangeAdd) | |
| 28 | |
| 23 namespace base { | 29 namespace base { |
| 24 namespace subtle { | 30 namespace subtle { |
| 25 | 31 |
| 26 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 32 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
| 27 Atomic32 old_value, | 33 Atomic32 old_value, |
| 28 Atomic32 new_value) { | 34 Atomic32 new_value) { |
| 29 LONG result = InterlockedCompareExchange( | 35 LONG result = _InterlockedCompareExchange( |
| 30 reinterpret_cast<volatile LONG*>(ptr), | 36 reinterpret_cast<volatile LONG*>(ptr), |
| 31 static_cast<LONG>(new_value), | 37 static_cast<LONG>(new_value), |
| 32 static_cast<LONG>(old_value)); | 38 static_cast<LONG>(old_value)); |
| 33 return static_cast<Atomic32>(result); | 39 return static_cast<Atomic32>(result); |
| 34 } | 40 } |
| 35 | 41 |
| 36 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | 42 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
| 37 Atomic32 new_value) { | 43 Atomic32 new_value) { |
| 38 LONG result = InterlockedExchange( | 44 LONG result = _InterlockedExchange( |
| 39 reinterpret_cast<volatile LONG*>(ptr), | 45 reinterpret_cast<volatile LONG*>(ptr), |
| 40 static_cast<LONG>(new_value)); | 46 static_cast<LONG>(new_value)); |
| 41 return static_cast<Atomic32>(result); | 47 return static_cast<Atomic32>(result); |
| 42 } | 48 } |
| 43 | 49 |
| 44 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | 50 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
| 45 Atomic32 increment) { | 51 Atomic32 increment) { |
| 46 return InterlockedExchangeAdd( | 52 return _InterlockedExchangeAdd( |
| 47 reinterpret_cast<volatile LONG*>(ptr), | 53 reinterpret_cast<volatile LONG*>(ptr), |
| 48 static_cast<LONG>(increment)) + increment; | 54 static_cast<LONG>(increment)) + increment; |
| 49 } | 55 } |
| 50 | 56 |
| 51 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | 57 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
| 52 Atomic32 increment) { | 58 Atomic32 increment) { |
| 53 return Barrier_AtomicIncrement(ptr, increment); | 59 return Barrier_AtomicIncrement(ptr, increment); |
| 54 } | 60 } |
| 55 | 61 |
| 56 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) | 62 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); | 193 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 188 } | 194 } |
| 189 | 195 |
| 190 | 196 |
| 191 #endif // defined(_WIN64) | 197 #endif // defined(_WIN64) |
| 192 | 198 |
| 193 } // namespace base::subtle | 199 } // namespace base::subtle |
| 194 } // namespace base | 200 } // namespace base |
| 195 | 201 |
| 196 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 202 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| OLD | NEW |