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 |
28 #if defined(_M_X64) | |
29 #pragma intrinsic(_InterlockedCompareExchange) | |
Sigurður Ásgeirsson
2014/06/03 15:03:08
Stupid question, but why do you need to declare th
Sébastien Marchand
2014/06/03 19:58:45
I don't need to, I've looked at 'sandbox/win/src/s
| |
30 #pragma intrinsic(_InterlockedExchange) | |
31 #pragma intrinsic(_InterlockedExchangeAdd) | |
32 | |
33 #elif defined(_M_IX86) | |
34 extern "C" long _InterlockedCompareExchange(long volatile* destination, | |
35 long exchange, long comperand); | |
36 #pragma intrinsic(_InterlockedCompareExchange) | |
37 | |
38 extern "C" long _InterlockedExchange(long volatile* destination, long exchange); | |
39 #pragma intrinsic(_InterlockedExchange) | |
40 | |
41 extern "C" long _InterlockedExchangeAdd(long volatile* destination, | |
42 long increment); | |
43 #pragma intrinsic(_InterlockedExchangeAdd) | |
44 | |
45 #else | |
46 #error Architecture not supported. | |
47 | |
48 #endif | |
49 | |
26 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 50 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
27 Atomic32 old_value, | 51 Atomic32 old_value, |
28 Atomic32 new_value) { | 52 Atomic32 new_value) { |
29 LONG result = InterlockedCompareExchange( | 53 LONG result = _InterlockedCompareExchange( |
Sigurður Ásgeirsson
2014/06/03 15:03:08
maybe a one-line comment that Interlocked* doesn't
Sébastien Marchand
2014/06/03 19:58:45
Done.
| |
30 reinterpret_cast<volatile LONG*>(ptr), | 54 reinterpret_cast<volatile LONG*>(ptr), |
31 static_cast<LONG>(new_value), | 55 static_cast<LONG>(new_value), |
32 static_cast<LONG>(old_value)); | 56 static_cast<LONG>(old_value)); |
33 return static_cast<Atomic32>(result); | 57 return static_cast<Atomic32>(result); |
34 } | 58 } |
35 | 59 |
36 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | 60 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
37 Atomic32 new_value) { | 61 Atomic32 new_value) { |
38 LONG result = InterlockedExchange( | 62 LONG result = _InterlockedExchange( |
39 reinterpret_cast<volatile LONG*>(ptr), | 63 reinterpret_cast<volatile LONG*>(ptr), |
40 static_cast<LONG>(new_value)); | 64 static_cast<LONG>(new_value)); |
41 return static_cast<Atomic32>(result); | 65 return static_cast<Atomic32>(result); |
42 } | 66 } |
43 | 67 |
44 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | 68 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
45 Atomic32 increment) { | 69 Atomic32 increment) { |
46 return InterlockedExchangeAdd( | 70 return _InterlockedExchangeAdd( |
47 reinterpret_cast<volatile LONG*>(ptr), | 71 reinterpret_cast<volatile LONG*>(ptr), |
48 static_cast<LONG>(increment)) + increment; | 72 static_cast<LONG>(increment)) + increment; |
49 } | 73 } |
50 | 74 |
51 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | 75 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
52 Atomic32 increment) { | 76 Atomic32 increment) { |
53 return Barrier_AtomicIncrement(ptr, increment); | 77 return Barrier_AtomicIncrement(ptr, increment); |
54 } | 78 } |
55 | 79 |
56 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) | 80 #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); | 211 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
188 } | 212 } |
189 | 213 |
190 | 214 |
191 #endif // defined(_WIN64) | 215 #endif // defined(_WIN64) |
192 | 216 |
193 } // namespace base::subtle | 217 } // namespace base::subtle |
194 } // namespace base | 218 } // namespace base |
195 | 219 |
196 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 220 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
OLD | NEW |