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 // The Interlocked* functions doesn't resolve to their intrinsics | |
Sigurður Ásgeirsson
2014/06/05 17:41:09
nit: doesn't ->don't
Also mention this is on ia32
| |
29 // counterpart, we need to explicitly call the _Interlocked* variant. | |
30 #pragma intrinsic(_InterlockedCompareExchange) | |
Sigurður Ásgeirsson
2014/06/04 15:12:54
do you need even this? Doesn't <intrin.h> declare
Sébastien Marchand
2014/06/04 15:21:02
Nop, it seems that I've to explicitly use the intr
Sigurður Ásgeirsson
2014/06/05 17:41:09
Ah, interesting. Turns out <intrin.h> gives you de
| |
31 #pragma intrinsic(_InterlockedExchange) | |
32 #pragma intrinsic(_InterlockedExchangeAdd) | |
33 | |
26 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 34 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
27 Atomic32 old_value, | 35 Atomic32 old_value, |
28 Atomic32 new_value) { | 36 Atomic32 new_value) { |
29 LONG result = InterlockedCompareExchange( | 37 LONG result = _InterlockedCompareExchange( |
30 reinterpret_cast<volatile LONG*>(ptr), | 38 reinterpret_cast<volatile LONG*>(ptr), |
31 static_cast<LONG>(new_value), | 39 static_cast<LONG>(new_value), |
32 static_cast<LONG>(old_value)); | 40 static_cast<LONG>(old_value)); |
33 return static_cast<Atomic32>(result); | 41 return static_cast<Atomic32>(result); |
34 } | 42 } |
35 | 43 |
36 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | 44 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
37 Atomic32 new_value) { | 45 Atomic32 new_value) { |
38 LONG result = InterlockedExchange( | 46 LONG result = _InterlockedExchange( |
39 reinterpret_cast<volatile LONG*>(ptr), | 47 reinterpret_cast<volatile LONG*>(ptr), |
40 static_cast<LONG>(new_value)); | 48 static_cast<LONG>(new_value)); |
41 return static_cast<Atomic32>(result); | 49 return static_cast<Atomic32>(result); |
42 } | 50 } |
43 | 51 |
44 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | 52 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
45 Atomic32 increment) { | 53 Atomic32 increment) { |
46 return InterlockedExchangeAdd( | 54 return _InterlockedExchangeAdd( |
47 reinterpret_cast<volatile LONG*>(ptr), | 55 reinterpret_cast<volatile LONG*>(ptr), |
48 static_cast<LONG>(increment)) + increment; | 56 static_cast<LONG>(increment)) + increment; |
49 } | 57 } |
50 | 58 |
51 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | 59 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
52 Atomic32 increment) { | 60 Atomic32 increment) { |
53 return Barrier_AtomicIncrement(ptr, increment); | 61 return Barrier_AtomicIncrement(ptr, increment); |
54 } | 62 } |
55 | 63 |
56 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) | 64 #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); | 195 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
188 } | 196 } |
189 | 197 |
190 | 198 |
191 #endif // defined(_WIN64) | 199 #endif // defined(_WIN64) |
192 | 200 |
193 } // namespace base::subtle | 201 } // namespace base::subtle |
194 } // namespace base | 202 } // namespace base |
195 | 203 |
196 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 204 #endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
OLD | NEW |