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 |
23 namespace base { | 25 namespace base { |
24 namespace subtle { | 26 namespace subtle { |
25 | 27 |
26 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 28 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
27 Atomic32 old_value, | 29 Atomic32 old_value, |
28 Atomic32 new_value) { | 30 Atomic32 new_value) { |
29 LONG result = InterlockedCompareExchange( | 31 LONG result = _InterlockedCompareExchange( |
30 reinterpret_cast<volatile LONG*>(ptr), | 32 reinterpret_cast<volatile LONG*>(ptr), |
31 static_cast<LONG>(new_value), | 33 static_cast<LONG>(new_value), |
32 static_cast<LONG>(old_value)); | 34 static_cast<LONG>(old_value)); |
33 return static_cast<Atomic32>(result); | 35 return static_cast<Atomic32>(result); |
34 } | 36 } |
35 | 37 |
36 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | 38 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
37 Atomic32 new_value) { | 39 Atomic32 new_value) { |
38 LONG result = InterlockedExchange( | 40 LONG result = _InterlockedExchange( |
39 reinterpret_cast<volatile LONG*>(ptr), | 41 reinterpret_cast<volatile LONG*>(ptr), |
40 static_cast<LONG>(new_value)); | 42 static_cast<LONG>(new_value)); |
41 return static_cast<Atomic32>(result); | 43 return static_cast<Atomic32>(result); |
42 } | 44 } |
43 | 45 |
44 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | 46 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
45 Atomic32 increment) { | 47 Atomic32 increment) { |
46 return InterlockedExchangeAdd( | 48 return _InterlockedExchangeAdd( |
47 reinterpret_cast<volatile LONG*>(ptr), | 49 reinterpret_cast<volatile LONG*>(ptr), |
48 static_cast<LONG>(increment)) + increment; | 50 static_cast<LONG>(increment)) + increment; |
49 } | 51 } |
50 | 52 |
51 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | 53 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
52 Atomic32 increment) { | 54 Atomic32 increment) { |
53 return Barrier_AtomicIncrement(ptr, increment); | 55 return Barrier_AtomicIncrement(ptr, increment); |
54 } | 56 } |
55 | 57 |
56 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) | 58 #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); | 189 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
188 } | 190 } |
189 | 191 |
190 | 192 |
191 #endif // defined(_WIN64) | 193 #endif // defined(_WIN64) |
192 | 194 |
193 } // namespace base::subtle | 195 } // namespace base::subtle |
194 } // namespace base | 196 } // namespace base |
195 | 197 |
196 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 198 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
OLD | NEW |